orders-api

module
v0.0.0-...-3b7b480 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT

README

online ordering system for restaurants

project structure

online-orders/ ├── cmd/ │ └── api/ │ └── main.go │ ├── internal/ │ ├── app/ │ │ ├── bootstrap.go │ │ ├── server.go │ │ └── shutdown.go │ │ │ ├── config/ │ │ ├── config.go │ │ └── env.go │ │ │ ├── domain/ │ │ ├── user/ │ │ │ ├── entity.go │ │ │ ├── repository.go │ │ │ ├── service.go │ │ │ └── errors.go │ │ └── order/ │ │ ├── entity.go │ │ ├── repository.go │ │ └── service.go │ │ │ ├── infrastructure/ │ │ ├── postgres/ │ │ │ ├── client.go │ │ │ ├── migrations/ │ │ │ └── user_repository.go │ │ │ │ │ ├── redis/ │ │ │ ├── client.go │ │ │ ├── cache.go │ │ │ └── rate_limiter.go │ │ │ │ │ └── logger/ │ │ └── zap.go │ │ │ ├── interfaces/ │ │ ├── http/ │ │ │ ├── handlers/ │ │ │ │ ├── user_handler.go │ │ │ │ └── order_handler.go │ │ │ │ │ │ │ ├── middleware/ │ │ │ │ ├── auth.go │ │ │ │ ├── cors.go │ │ │ │ └── logging.go │ │ │ │ │ │ │ └── router.go │ │ │ │ │ └── grpc/ │ │ └── user_service.go │ │ │ ├── usecase/ │ │ ├── user/ │ │ │ ├── create_user.go │ │ │ ├── login_user.go │ │ │ └── get_user.go │ │ │ │ │ └── order/ │ │ └── create_order.go │ │ │ ├── pkg/ │ │ ├── auth/ │ │ │ └── jwt.go │ │ ├── crypto/ │ │ │ └── password.go │ │ ├── validator/ │ │ │ └── validator.go │ │ └── utils/ │ │ └── uuid.go │ │ │ └── tests/ │ ├── integration/ │ └── unit/ │ ├── migrations/ │ └── 0001_init.sql │ ├── scripts/ │ ├── migrate.sh │ └── seed.sh │ ├── deployments/ │ ├── docker/ │ │ ├── Dockerfile │ │ └── docker-compose.yml │ └── k8s/ │ └── deployment.yaml │ ├── go.mod ├── go.sum └── README.md

cmd/ - entry points

cmd/api/main.go
  • Parses env vars

  • Starts HTTP/GRPC server

  • Calls internal/app/bootstrap.go

internal/app/ - application lifecycle

bootstrap.go   // wiring dependencies
server.go     // HTTP/GRPC server
shutdown.go   // graceful shutdown

internal/config/ - configuration management

type Config struct {
    Postgres PostgresConfig
    Redis    RedisConfig
}
  • Loads .env

  • Handles defaults

  • Centralized config logic

internal/domain/ - business rules

type User struct {
    ID    uuid.UUID
    Email string
}

NO database, NO Redis, NO HTTP here. core business logic

  • Entities

  • Interfaces (repositories)

  • Domain errors

internal/usecase/ - application actions

CreateUser
LoginUser
GetUser

Each file:

  • Executes ONE business action

  • Coordinates domain + infrastructure

  • Think: verbs, not nouns

internal/infrastructure/ - External systems

postgres/client.go
postgres/user_repository.go
  • SQL, GORM, pgx

  • Implements domain repository interfaces

Redis
redis/cache.go
redis/rate_limiter.go
  • Cache

  • Locks

  • Rate limits

  • Session store

Only infra knows Redis/Postgres exist.

internal/interfaces/ - Adapters

HTTP

handlers/
middleware/
router.go
  • Converts HTTP → usecase

  • Converts usecase → HTTP response

gRPC (optional)

  • Same business logic, different transport

internal/pkg/ - shared libraries

  • JWT

  • Password hashing

  • Validators

  • Utilities

Reusable across services.

migrations/ - Database versioning

0001_init.sql
0002_add_users.sql
  • golang-migrate

  • atlas

  • goose

deployments/ - Infrastructure-as-code

  • Docker

  • Docker Compose

  • Kubernetes

work flow

HTTP Request ↓ Handler ↓ Usecase ↓ Domain logic ↓ Postgres / Redis ↓ Usecase ↓ Handler ↓ HTTP Response

Directories

Path Synopsis
cmd
api command
Package main is the entry point for the orders API application.
Package main is the entry point for the orders API application.
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
app
Package app initializes the application components such as database and cache clients.
Package app initializes the application components such as database and cache clients.
config
Package config provides functionality to load application configuration
Package config provides functionality to load application configuration
domain/restaurant
Package restaurant defines the Restaurant entity and related value objects.
Package restaurant defines the Restaurant entity and related value objects.
domain/user
Package user defines the User entity and related types.
Package user defines the User entity and related types.
domain/user_session
Package usersession defines the UserSessions entity for database interactions
Package usersession defines the UserSessions entity for database interactions
infrastructure/logger
Package logger provides a flexible logging solution using zerolog and lumberjack for log rotation.
Package logger provides a flexible logging solution using zerolog and lumberjack for log rotation.
infrastructure/postgres
Package postgres provides a Postgres client for database operations.
Package postgres provides a Postgres client for database operations.
infrastructure/postgres/persistence
Package persistence implements the restaurant repository using GORM for PostgreSQL It implements the restaurant.Repository interface defined in the restaurant domain, providing methods for creating, retrieving, updating, and deleting restaurant records in a PostgreSQL database using GORM as the ORM.
Package persistence implements the restaurant repository using GORM for PostgreSQL It implements the restaurant.Repository interface defined in the restaurant domain, providing methods for creating, retrieving, updating, and deleting restaurant records in a PostgreSQL database using GORM as the ORM.
infrastructure/redis
Package redis provides a Redis client for caching and other operations.
Package redis provides a Redis client for caching and other operations.
infrastructure/redis/cache
Package cache implements the user repository using Redis as the underlying storage mechanism.
Package cache implements the user repository using Redis as the underlying storage mechanism.
infrastructure/repository
Package repository is cache decorator, it implements read-through caching
Package repository is cache decorator, it implements read-through caching
infrastructure/security
Package security provides password hashing and verification using bcrypt.
Package security provides password hashing and verification using bcrypt.
interfaces/http
Package http defines the HTTP router interface and implementation
Package http defines the HTTP router interface and implementation
interfaces/http/dto
Package dto defines the Data Transfer Objects for the User entity.
Package dto defines the Data Transfer Objects for the User entity.
interfaces/http/handlers
Package handlers contains HTTP handlers for restaurant-related endpoints.
Package handlers contains HTTP handlers for restaurant-related endpoints.
interfaces/http/middleware
Package middleware provides middleware functions for handling HTTP requests in the application.
Package middleware provides middleware functions for handling HTTP requests in the application.
pkg/utils
Package utils provides functions to extract device and location information from HTTP requests.
Package utils provides functions to extract device and location information from HTTP requests.
usecase/restaurant
Package restaurant contains the use case for creating a restaurant.
Package restaurant contains the use case for creating a restaurant.
usecase/user
Package user contains the use case for creating a new user in the system.
Package user contains the use case for creating a new user in the system.
usecase/user_session
Package usersession contains use cases related to user session management, such as creating, validating, and deleting sessions.
Package usersession contains use cases related to user session management, such as creating, validating, and deleting sessions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL