# du380202/restaurant-api architecture

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

- Interactive diagram: https://gitdiagram.com/du380202/restaurant-api
- Repository: https://github.com/du380202/restaurant-api

## Overview

This Go service exposes a restaurant API: users register or log in, authenticate requests, then browse and manage restaurants or like and unlike them. Admin and moderator users also have a profile route. The tree shows separate transport, business, and storage layers for users, restaurants, and likes, but their internal calls were not sampled, so those links are omitted. The sampled runtime confirms router dispatch, authentication’s token and user lookup, and PostgreSQL startup; no README was provided.

Main entry points: [`cmd/main.go`](https://github.com/du380202/restaurant-api/blob/main/cmd/main.go) (HTTP server), [`cmd/user_router.go`](https://github.com/du380202/restaurant-api/blob/main/cmd/user_router.go) (User routes), [`middleware/authenticate.go`](https://github.com/du380202/restaurant-api/blob/main/middleware/authenticate.go) (Authentication), [`cmd/admin_router.go`](https://github.com/du380202/restaurant-api/blob/main/cmd/admin_router.go) (Admin routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["API runtime"]
  node_server["HTTP server<br/>[main.go]"]
  node_user_routes["User routes<br/>[user_router.go]"]
  node_admin_routes["Admin routes<br/>[admin_router.go]"]
  node_app_context["App context<br/>[app_context.go]"]
  node_postgres_config["Postgres setup<br/>[db.go]"]
end

subgraph group_accounts["Accounts and security"]
  node_auth_middleware["Authentication<br/>[authenticate.go]"]
  node_role_middleware["Role checks<br/>[role_require.go]"]
  node_jwt_provider["JWT provider<br/>[jwt.go]"]
  node_user_storage["User storage<br/>[find.go]"]
  node_user_transport["User endpoints<br/>[login.go]"]
  node_user_business["User logic<br/>[login.go]"]
end

subgraph group_restaurants["Restaurant management"]
  node_restaurant_transport["Restaurant endpoints<br/>[list_restaurant.go]"]
  node_restaurant_business["Restaurant logic<br/>[list_restaurant.go]"]
  node_restaurant_storage["Restaurant storage<br/>[list.go]"]
end

subgraph group_engagement["Restaurant likes"]
  node_like_transport["Like endpoints"]
  node_like_business["Like logic"]
  node_like_storage["Like storage<br/>[list.go]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_server
node_server -->|"connects"| node_postgres_config
node_postgres_config -->|"opens database"| node_postgres
node_server -->|"registers routes"| node_user_routes
node_server -->|"registers routes"| node_admin_routes
node_server -->|"creates context"| node_app_context
node_user_routes -->|"dispatches"| node_user_transport
node_user_routes -->|"dispatches"| node_restaurant_transport
node_user_routes -->|"dispatches"| node_like_transport
node_user_routes -->|"protects routes"| node_auth_middleware
node_admin_routes -->|"dispatches profile"| node_user_transport
node_admin_routes -->|"requires authentication"| node_auth_middleware
node_admin_routes -->|"checks roles"| node_role_middleware
node_auth_middleware -->|"gets database and secret"| node_app_context
node_auth_middleware -->|"validates token"| node_jwt_provider
node_auth_middleware -->|"finds user"| node_user_storage
node_like_storage -->|"queries"| node_postgres

click node_server "https://github.com/du380202/restaurant-api/blob/main/cmd/main.go"
click node_user_routes "https://github.com/du380202/restaurant-api/blob/main/cmd/user_router.go"
click node_admin_routes "https://github.com/du380202/restaurant-api/blob/main/cmd/admin_router.go"
click node_app_context "https://github.com/du380202/restaurant-api/blob/main/component/appctx/app_context.go"
click node_postgres_config "https://github.com/du380202/restaurant-api/blob/main/config/db.go"
click node_auth_middleware "https://github.com/du380202/restaurant-api/blob/main/middleware/authenticate.go"
click node_role_middleware "https://github.com/du380202/restaurant-api/blob/main/middleware/role_require.go"
click node_jwt_provider "https://github.com/du380202/restaurant-api/blob/main/component/tokenprovider/jwt/jwt.go"
click node_user_storage "https://github.com/du380202/restaurant-api/blob/main/internal/user/storage/find.go"
click node_user_transport "https://github.com/du380202/restaurant-api/blob/main/internal/user/transport/login.go"
click node_user_business "https://github.com/du380202/restaurant-api/blob/main/internal/user/biz/login.go"
click node_restaurant_transport "https://github.com/du380202/restaurant-api/blob/main/internal/restaurant/transport/ginrestaurant/list_restaurant.go"
click node_restaurant_business "https://github.com/du380202/restaurant-api/blob/main/internal/restaurant/biz/list_restaurant.go"
click node_restaurant_storage "https://github.com/du380202/restaurant-api/blob/main/internal/restaurant/storage/list.go"
click node_like_transport "https://github.com/du380202/restaurant-api/blob/main/internal/restaurantlike/transport/user_like_restaurant.go"
click node_like_business "https://github.com/du380202/restaurant-api/blob/main/internal/restaurantlike/biz/user_like_restaurant.go"
click node_like_storage "https://github.com/du380202/restaurant-api/blob/main/internal/restaurantlike/storage/list.go"

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_user_routes,node_admin_routes,node_app_context,node_postgres_config,node_client toneBlue
class node_auth_middleware,node_role_middleware,node_jwt_provider,node_user_storage,node_user_transport,node_user_business,node_postgres toneAmber
class node_restaurant_transport,node_restaurant_business,node_restaurant_storage toneMint
class node_like_transport,node_like_business,node_like_storage toneRose
```

## Components

### API runtime

- [HTTP server](https://github.com/du380202/restaurant-api/blob/main/cmd/main.go): `cmd/main.go`
- [User routes](https://github.com/du380202/restaurant-api/blob/main/cmd/user_router.go): `cmd/user_router.go`
- [Admin routes](https://github.com/du380202/restaurant-api/blob/main/cmd/admin_router.go): `cmd/admin_router.go`
- [App context](https://github.com/du380202/restaurant-api/blob/main/component/appctx/app_context.go): `component/appctx/app_context.go`
- [Postgres setup](https://github.com/du380202/restaurant-api/blob/main/config/db.go): `config/db.go`

### Accounts and security

- [Authentication](https://github.com/du380202/restaurant-api/blob/main/middleware/authenticate.go): `middleware/authenticate.go`
- [Role checks](https://github.com/du380202/restaurant-api/blob/main/middleware/role_require.go): `middleware/role_require.go`
- [JWT provider](https://github.com/du380202/restaurant-api/blob/main/component/tokenprovider/jwt/jwt.go): `component/tokenprovider/jwt/jwt.go`
- [User storage](https://github.com/du380202/restaurant-api/blob/main/internal/user/storage/find.go): `internal/user/storage/find.go`
- [User endpoints](https://github.com/du380202/restaurant-api/blob/main/internal/user/transport/login.go): `internal/user/transport/login.go`
- [User logic](https://github.com/du380202/restaurant-api/blob/main/internal/user/biz/login.go): `internal/user/biz/login.go`

### Restaurant management

- [Restaurant endpoints](https://github.com/du380202/restaurant-api/blob/main/internal/restaurant/transport/ginrestaurant/list_restaurant.go): `internal/restaurant/transport/ginrestaurant/list_restaurant.go`
- [Restaurant logic](https://github.com/du380202/restaurant-api/blob/main/internal/restaurant/biz/list_restaurant.go): `internal/restaurant/biz/list_restaurant.go`
- [Restaurant storage](https://github.com/du380202/restaurant-api/blob/main/internal/restaurant/storage/list.go): `internal/restaurant/storage/list.go`

### Restaurant likes

- [Like endpoints](https://github.com/du380202/restaurant-api/blob/main/internal/restaurantlike/transport/user_like_restaurant.go): `internal/restaurantlike/transport/user_like_restaurant.go`
- [Like logic](https://github.com/du380202/restaurant-api/blob/main/internal/restaurantlike/biz/user_like_restaurant.go): `internal/restaurantlike/biz/user_like_restaurant.go`
- [Like storage](https://github.com/du380202/restaurant-api/blob/main/internal/restaurantlike/storage/list.go): `internal/restaurantlike/storage/list.go`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → HTTP server: sends requests
- HTTP server → Postgres setup: connects
- Postgres setup → PostgreSQL: opens database
- HTTP server → User routes: registers routes
- HTTP server → Admin routes: registers routes
- HTTP server → App context: creates context
- User routes → User endpoints: dispatches
- User routes → Restaurant endpoints: dispatches
- User routes → Like endpoints: dispatches
- User routes → Authentication: protects routes
- Admin routes → User endpoints: dispatches profile
- Admin routes → Authentication: requires authentication
- Admin routes → Role checks: checks roles
- Authentication → App context: gets database and secret
- Authentication → JWT provider: validates token
- Authentication → User storage: finds user
- Like storage → PostgreSQL: queries
