# thdawnwind/food-delivery-api architecture

> Architecture diagram of the GitHub repository thdawnwind/food-delivery-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thdawnwind/food-delivery-api
- Repository: https://github.com/thdawnwind/food-delivery-api

## Overview

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: [`cmd/api/main.go`](https://github.com/thdawnwind/food-delivery-api/blob/main/cmd/api/main.go) (API router), [`internal/order/service.go`](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/order/service.go) (Order service), [`internal/auth/service.go`](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/service.go) (Auth service), [`internal/auth/middleware.go`](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/middleware.go) (Auth middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["HTTP application"]
  node_server["API router<br/>[main.go]"]
end

subgraph group_identity["Identity and users"]
  node_authh["Auth endpoints<br/>[handler.go]"]
  node_authsvc["Auth service<br/>[service.go]"]
  node_tokens["JWT tokens<br/>[token.go]"]
  node_authmw["Auth middleware<br/>[middleware.go]"]
  node_usersvc["User service<br/>[service.go]"]
  node_userrepo["User repository<br/>[repository.go]"]
end

subgraph group_catalog["Delivery catalog"]
  node_categories["Category API<br/>[handler.go]"]
  node_categorysvc["Category service<br/>[service.go]"]
  node_categoryrepo["Category repository<br/>[repository.go]"]
  node_products["Product API<br/>[handler.go]"]
  node_productsvc["Product service<br/>[service.go]"]
  node_productrepo["Product repository<br/>[repository.go]"]
end

subgraph group_fulfillment["Orders and addresses"]
  node_addressapi["Address API<br/>[handler.go]"]
  node_addresssvc["Address service<br/>[service.go]"]
  node_addressrepo["Address repository<br/>[repository.go]"]
  node_orderapi["Order API<br/>[handler.go]"]
  node_ordersvc["Order service<br/>[service.go]"]
  node_orderrepo["Order repository<br/>[repository.go]"]
end

subgraph group_platform["Persistence and operations"]
  node_db[("PostgreSQL")]
  node_config["Runtime config<br/>[config.go]"]
  node_dbpool["Database pool<br/>[database.go]"]
  node_httpx["HTTP middleware"]
  node_openapi["API docs<br/>[embed.go]"]
  node_migrations["Schema migrations"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_server
node_server -->|"routes auth"| node_authh
node_server -->|"routes categories"| node_categories
node_server -->|"routes products"| node_products
node_server -->|"mounts addresses"| node_addressapi
node_server -->|"mounts orders"| node_orderapi
node_server -->|"loads settings"| node_config
node_server -->|"opens pool"| node_dbpool
node_server -.->|"configures middleware"| node_httpx
node_server -->|"serves docs"| node_openapi
node_authh -->|"calls"| node_authsvc
node_authsvc -->|"authenticates users"| node_usersvc
node_authsvc -.->|"generates tokens"| node_tokens
node_authmw -->|"parses tokens"| node_tokens
node_authmw -->|"checks roles"| node_usersvc
node_server -->|"registers protection"| node_authmw
node_usersvc -.->|"uses repository"| node_userrepo
node_categories -->|"calls"| node_categorysvc
node_categorysvc -.->|"uses repository"| node_categoryrepo
node_products -->|"calls"| node_productsvc
node_productsvc -.->|"uses repository"| node_productrepo
node_addressapi -->|"calls"| node_addresssvc
node_addresssvc -.->|"uses repository"| node_addressrepo
node_orderapi -->|"calls"| node_ordersvc
node_ordersvc -->|"persists orders"| node_orderrepo
node_ordersvc -->|"reads products"| node_productsvc
node_ordersvc -->|"reads address"| node_addresssvc
node_categoryrepo -.->|"reads and writes"| node_db
node_productrepo -.->|"reads and writes"| node_db
node_addressrepo -.->|"reads and writes"| node_db
node_orderrepo -->|"transactional storage"| node_db
node_userrepo -.->|"reads and writes"| node_db
node_dbpool -.->|"connects"| node_db
node_migrations -->|"defines schema"| node_db
node_server -->|"readiness check"| node_db

click node_server "https://github.com/thdawnwind/food-delivery-api/blob/main/cmd/api/main.go"
click node_authh "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/handler.go"
click node_authsvc "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/service.go"
click node_tokens "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/token.go"
click node_authmw "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/middleware.go"
click node_usersvc "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/user/service.go"
click node_userrepo "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/user/repository.go"
click node_categories "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/category/handler.go"
click node_categorysvc "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/category/service.go"
click node_categoryrepo "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/category/repository.go"
click node_products "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/product/handler.go"
click node_productsvc "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/product/service.go"
click node_productrepo "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/product/repository.go"
click node_addressapi "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/address/handler.go"
click node_addresssvc "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/address/service.go"
click node_addressrepo "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/address/repository.go"
click node_orderapi "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/order/handler.go"
click node_ordersvc "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/order/service.go"
click node_orderrepo "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/order/repository.go"
click node_config "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/config/config.go"
click node_dbpool "https://github.com/thdawnwind/food-delivery-api/blob/main/internal/database/database.go"
click node_httpx "https://github.com/thdawnwind/food-delivery-api/tree/main/internal/httpx"
click node_openapi "https://github.com/thdawnwind/food-delivery-api/blob/main/openapi/embed.go"
click node_migrations "https://github.com/thdawnwind/food-delivery-api/tree/main/migrations"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_client toneBlue
class node_authh,node_authsvc,node_tokens,node_authmw,node_usersvc,node_userrepo toneAmber
class node_categories,node_categorysvc,node_categoryrepo,node_products,node_productsvc,node_productrepo toneMint
class node_addressapi,node_addresssvc,node_addressrepo,node_orderapi,node_ordersvc,node_orderrepo toneRose
class node_db,node_config,node_dbpool,node_httpx,node_openapi,node_migrations toneIndigo
```

## Components

### HTTP application

- [API router](https://github.com/thdawnwind/food-delivery-api/blob/main/cmd/api/main.go): `cmd/api/main.go`

### Identity and users

- [Auth endpoints](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/handler.go): `internal/auth/handler.go`
- [Auth service](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/service.go): `internal/auth/service.go`
- [JWT tokens](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/token.go): `internal/auth/token.go`
- [Auth middleware](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/auth/middleware.go): `internal/auth/middleware.go`
- [User service](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/user/service.go): `internal/user/service.go`
- [User repository](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/user/repository.go): `internal/user/repository.go`

### Delivery catalog

- [Category API](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/category/handler.go): `internal/category/handler.go`
- [Category service](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/category/service.go): `internal/category/service.go`
- [Category repository](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/category/repository.go): `internal/category/repository.go`
- [Product API](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/product/handler.go): `internal/product/handler.go`
- [Product service](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/product/service.go): `internal/product/service.go`
- [Product repository](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/product/repository.go): `internal/product/repository.go`

### Orders and addresses

- [Address API](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/address/handler.go): `internal/address/handler.go`
- [Address service](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/address/service.go): `internal/address/service.go`
- [Address repository](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/address/repository.go): `internal/address/repository.go`
- [Order API](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/order/handler.go): `internal/order/handler.go`
- [Order service](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/order/service.go): `internal/order/service.go`
- [Order repository](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/order/repository.go): `internal/order/repository.go`

### Persistence and operations

- **PostgreSQL**
- [Runtime config](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/config/config.go): `internal/config/config.go`
- [Database pool](https://github.com/thdawnwind/food-delivery-api/blob/main/internal/database/database.go): `internal/database/database.go`
- [HTTP middleware](https://github.com/thdawnwind/food-delivery-api/tree/main/internal/httpx): `internal/httpx`
- [API docs](https://github.com/thdawnwind/food-delivery-api/blob/main/openapi/embed.go): `openapi/embed.go`
- [Schema migrations](https://github.com/thdawnwind/food-delivery-api/tree/main/migrations): `migrations`

### Other components

- **API client**

## Connections

- API client → API router: sends requests (evidence: `README.md`)
- API router → Auth endpoints: routes auth (evidence: `cmd/api/main.go`)
- API router → Category API: routes categories (evidence: `cmd/api/main.go`)
- API router → Product API: routes products (evidence: `cmd/api/main.go`)
- API router → Address API: mounts addresses (evidence: `cmd/api/main.go`)
- API router → Order API: mounts orders (evidence: `cmd/api/main.go`)
- API router → Runtime config: loads settings (evidence: `cmd/api/main.go`)
- API router → Database pool: opens pool (evidence: `cmd/api/main.go`)
- API router → HTTP middleware: configures middleware (evidence: `cmd/api/main.go`)
- API router → API docs: serves docs (evidence: `cmd/api/main.go`)
- Auth endpoints → Auth service: calls (evidence: `internal/auth/handler.go`)
- Auth service → User service: authenticates users (evidence: `internal/auth/service.go`)
- Auth service → JWT tokens: generates tokens
- Auth middleware → JWT tokens: parses tokens (evidence: `internal/auth/middleware.go`)
- Auth middleware → User service: checks roles (evidence: `internal/auth/middleware.go`)
- API router → Auth middleware: registers protection (evidence: `cmd/api/main.go`)
- User service → User repository: uses repository
- Category API → Category service: calls (evidence: `internal/category/handler.go`)
- Category service → Category repository: uses repository
- Product API → Product service: calls (evidence: `internal/product/handler.go`)
- Product service → Product repository: uses repository
- Address API → Address service: calls (evidence: `internal/address/handler.go`)
- Address service → Address repository: uses repository
- Order API → Order service: calls (evidence: `internal/order/handler.go`)
- Order service → Order repository: persists orders (evidence: `internal/order/service.go`)
- Order service → Product service: reads products (evidence: `internal/order/service.go`)
- Order service → Address service: reads address (evidence: `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 (evidence: `internal/order/repository.go`)
- User repository → PostgreSQL: reads and writes
- Database pool → PostgreSQL: connects
- Schema migrations → PostgreSQL: defines schema (evidence: `README.md`)
- API router → PostgreSQL: readiness check (evidence: `README.md`)
