How thdawnwind/food-delivery-api works
Food Delivery API is a Go/PostgreSQL backend whose main flow is HTTP requests through routed handlers and domain services to repositories and persistent storage. Orders combine saved-address and catalog data into transactional orders, with snapshot history and controlled status changes. Authentication and role middleware protect user and admin operations. README-documented health/readiness, metrics, and OpenAPI/Scalar endpoints are represented; unsampled subsystem links are included only where the main entrypoint or README supports them.
Main entry points: main.go API router · order/service.go Order service · auth/service.go Auth service · middleware.go Auth middleware
Components 26
HTTP application
- API router
cmd/api/main.go
Identity and users
- Auth endpoints
internal/auth/handler.go - Auth service
internal/auth/service.go - JWT tokens
internal/auth/token.go - Auth middleware
internal/auth/middleware.go - User service
internal/user/service.go - User repository
internal/user/repository.go
Delivery catalog
- Category API
internal/category/handler.go - Category service
internal/category/service.go - Category repository
internal/category/repository.go - Product API
internal/product/handler.go - Product service
internal/product/service.go - Product repository
internal/product/repository.go
Orders and addresses
- Address API
internal/address/handler.go - Address service
internal/address/service.go - Address repository
internal/address/repository.go - Order API
internal/order/handler.go - Order service
internal/order/service.go - Order repository
internal/order/repository.go
Persistence and operations
- PostgreSQL
- Runtime config
internal/config/config.go - Database pool
internal/database/database.go - HTTP middleware
internal/httpx - API docs
openapi/embed.go - Schema migrations
migrations
Other components
- API client
Connections 35
- API client → API router: sends requests
README.md - API router → Auth endpoints: routes auth
cmd/api/main.go - API router → Category API: routes categories
cmd/api/main.go - API router → Product API: routes products
cmd/api/main.go - API router → Address API: mounts addresses
cmd/api/main.go - API router → Order API: mounts orders
cmd/api/main.go - API router → Runtime config: loads settings
cmd/api/main.go - API router → Database pool: opens pool
cmd/api/main.go - API router → HTTP middleware: configures middleware
cmd/api/main.go - API router → API docs: serves docs
cmd/api/main.go - Auth endpoints → Auth service: calls
internal/auth/handler.go - Auth service → User service: authenticates users
internal/auth/service.go - Auth service → JWT tokens: generates tokens
- Auth middleware → JWT tokens: parses tokens
internal/auth/middleware.go - Auth middleware → User service: checks roles
internal/auth/middleware.go - API router → Auth middleware: registers protection
cmd/api/main.go - User service → User repository: uses repository
- Category API → Category service: calls
internal/category/handler.go - Category service → Category repository: uses repository
- Product API → Product service: calls
internal/product/handler.go - Product service → Product repository: uses repository
- Address API → Address service: calls
internal/address/handler.go - Address service → Address repository: uses repository
- Order API → Order service: calls
internal/order/handler.go - Order service → Order repository: persists orders
internal/order/service.go - Order service → Product service: reads products
internal/order/service.go - Order service → Address service: reads address
internal/order/service.go - Category repository → PostgreSQL: reads and writes
- Product repository → PostgreSQL: reads and writes
- Address repository → PostgreSQL: reads and writes
- Order repository → PostgreSQL: transactional storage
internal/order/repository.go - User repository → PostgreSQL: reads and writes
- Database pool → PostgreSQL: connects
- Schema migrations → PostgreSQL: defines schema
README.md - API router → PostgreSQL: readiness check
README.md