# sewy-bit/go-and-eat architecture

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

- Interactive diagram: https://gitdiagram.com/sewy-bit/go-and-eat
- Repository: https://github.com/sewy-bit/go-and-eat

## Overview

GO-and-eat is a restaurant ordering REST service. Clients create restaurants and menus, place orders, retrieve orders or user order history, and update order status. Order creation checks menu items and stock, computes totals, decreases stock, and saves the order in a transaction. The main program wires HTTP handlers to PostgreSQL-backed storage and runs migrations. The sampled code supports these links; getter implementations and some internal wiring are represented only where startup explicitly injects them.

Main entry points: [`internal/order/handler/http.go`](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/handler/http.go) (Order Endpoints), [`internal/order/usecase/create_order.go`](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/create_order.go) (Create Order), [`internal/pkg/database/postgres.go`](https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/database/postgres.go) (PostgreSQL Pool), [`internal/order/storage/postgres.go`](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/storage/postgres.go) (Order Storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_order_http["Order Endpoints<br/>[http.go]"]
  node_restaurant_http["Restaurant Endpoints<br/>[http.go]"]
end

subgraph group_orders["Order Workflow"]
  node_create_order["Create Order<br/>[create_order.go]"]
  node_get_order["Get Order<br/>[get_order.go]"]
  node_update_status["Update Status"]
  node_user_orders["User Orders<br/>[get_user_orders.go]"]
  node_order_domain["Order Model<br/>[order.go]"]
  node_order_storage["Order Storage<br/>[postgres.go]"]
end

subgraph group_restaurants["Restaurant Catalog"]
  node_restaurant_domain["Restaurant Model<br/>[restaurant.go]"]
  node_restaurant_storage["Restaurant Storage<br/>[postgres.go]"]
end

subgraph group_platform["Persistence Platform"]
  node_config["Configuration<br/>[config.go]"]
  node_database["PostgreSQL Pool<br/>[postgres.go]"]
  node_transactions["Transaction Adapter<br/>[transaction.go]"]
  node_migrator["Migration Runner<br/>[migrate.go]"]
  node_schema["Database Migrations"]
end

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

node_client -->|"sends requests"| node_order_http
node_client -->|"sends requests"| node_restaurant_http
node_order_http -->|"executes"| node_create_order
node_order_http -->|"executes"| node_get_order
node_order_http -->|"executes"| node_update_status
node_order_http -->|"executes"| node_user_orders
node_restaurant_http -->|"calls"| node_restaurant_storage
node_create_order -->|"checks menu and stock"| node_restaurant_storage
node_create_order -->|"saves order"| node_order_storage
node_create_order -->|"manages transaction"| node_transactions
node_update_status -->|"reads and updates"| node_order_storage
node_user_orders -->|"fetches history"| node_order_storage
node_order_http -->|"uses status model"| node_order_domain
node_create_order -->|"builds order"| node_order_domain
node_create_order -->|"uses menu items"| node_restaurant_domain
node_restaurant_http -->|"builds catalog data"| node_restaurant_domain
node_restaurant_storage -->|"reads and writes"| node_postgres
node_order_storage -->|"reads and writes"| node_postgres
node_config -->|"provides settings"| node_database
node_database -->|"opens pool"| node_postgres
node_database -->|"provides pool"| node_restaurant_storage
node_database -->|"provides pool"| node_order_storage
node_database -->|"provides pool"| node_transactions
node_migrator -->|"applies migrations"| node_schema
node_database -->|"provides pool"| node_migrator
node_migrator -.->|"updates schema"| node_postgres

click node_order_http "https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/handler/http.go"
click node_restaurant_http "https://github.com/sewy-bit/go-and-eat/blob/main/internal/restaurant/handler/http.go"
click node_create_order "https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/create_order.go"
click node_get_order "https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/get_order.go"
click node_update_status "https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/update_order_status.go"
click node_user_orders "https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/get_user_orders.go"
click node_order_domain "https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/domain/order.go"
click node_restaurant_domain "https://github.com/sewy-bit/go-and-eat/blob/main/internal/restaurant/domain/restaurant.go"
click node_restaurant_storage "https://github.com/sewy-bit/go-and-eat/blob/main/internal/restaurant/storage/postgres.go"
click node_order_storage "https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/storage/postgres.go"
click node_config "https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/config/config.go"
click node_database "https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/database/postgres.go"
click node_transactions "https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/database/transaction.go"
click node_migrator "https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/migrate/migrate.go"
click node_schema "https://github.com/sewy-bit/go-and-eat/tree/main/scripts/migrations/restaurant"

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_order_http,node_restaurant_http,node_client toneBlue
class node_create_order,node_get_order,node_update_status,node_user_orders,node_order_domain,node_order_storage,node_postgres toneAmber
class node_restaurant_domain,node_restaurant_storage toneMint
class node_config,node_database,node_transactions,node_migrator,node_schema toneRose
```

## Components

### HTTP API

- [Order Endpoints](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/handler/http.go): `internal/order/handler/http.go`
- [Restaurant Endpoints](https://github.com/sewy-bit/go-and-eat/blob/main/internal/restaurant/handler/http.go): `internal/restaurant/handler/http.go`

### Order Workflow

- [Create Order](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/create_order.go): `internal/order/usecase/create_order.go`
- [Get Order](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/get_order.go): `internal/order/usecase/get_order.go`
- [Update Status](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/update_order_status.go): `internal/order/usecase/update_order_status.go`
- [User Orders](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/usecase/get_user_orders.go): `internal/order/usecase/get_user_orders.go`
- [Order Model](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/domain/order.go): `internal/order/domain/order.go`
- [Order Storage](https://github.com/sewy-bit/go-and-eat/blob/main/internal/order/storage/postgres.go): `internal/order/storage/postgres.go`

### Restaurant Catalog

- [Restaurant Model](https://github.com/sewy-bit/go-and-eat/blob/main/internal/restaurant/domain/restaurant.go): `internal/restaurant/domain/restaurant.go`
- [Restaurant Storage](https://github.com/sewy-bit/go-and-eat/blob/main/internal/restaurant/storage/postgres.go): `internal/restaurant/storage/postgres.go`

### Persistence Platform

- [Configuration](https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/config/config.go): `internal/pkg/config/config.go`
- [PostgreSQL Pool](https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/database/postgres.go): `internal/pkg/database/postgres.go`
- [Transaction Adapter](https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/database/transaction.go): `internal/pkg/database/transaction.go`
- [Migration Runner](https://github.com/sewy-bit/go-and-eat/blob/main/internal/pkg/migrate/migrate.go): `internal/pkg/migrate/migrate.go`
- [Database Migrations](https://github.com/sewy-bit/go-and-eat/tree/main/scripts/migrations/restaurant): `scripts/migrations/restaurant`

### Other components

- **API Client**
- **PostgreSQL**

## Connections

- API Client → Order Endpoints: sends requests
- API Client → Restaurant Endpoints: sends requests
- Order Endpoints → Create Order: executes (evidence: `internal/order/handler/http.go`)
- Order Endpoints → Get Order: executes (evidence: `internal/order/handler/http.go`)
- Order Endpoints → Update Status: executes (evidence: `internal/order/handler/http.go`)
- Order Endpoints → User Orders: executes (evidence: `internal/order/handler/http.go`)
- Restaurant Endpoints → Restaurant Storage: calls (evidence: `internal/restaurant/handler/http.go`)
- Create Order → Restaurant Storage: checks menu and stock
- Create Order → Order Storage: saves order
- Create Order → Transaction Adapter: manages transaction
- Update Status → Order Storage: reads and updates
- User Orders → Order Storage: fetches history
- Order Endpoints → Order Model: uses status model (evidence: `internal/order/handler/http.go`)
- Create Order → Order Model: builds order (evidence: `internal/order/usecase/create_order.go`)
- Create Order → Restaurant Model: uses menu items (evidence: `internal/order/usecase/create_order.go`)
- Restaurant Endpoints → Restaurant Model: builds catalog data (evidence: `internal/restaurant/handler/http.go`)
- Restaurant Storage → PostgreSQL: reads and writes (evidence: `internal/restaurant/storage/postgres.go`)
- Order Storage → PostgreSQL: reads and writes (evidence: `internal/order/storage/postgres.go`)
- Configuration → PostgreSQL Pool: provides settings
- PostgreSQL Pool → PostgreSQL: opens pool (evidence: `internal/pkg/database/postgres.go`)
- PostgreSQL Pool → Restaurant Storage: provides pool
- PostgreSQL Pool → Order Storage: provides pool
- PostgreSQL Pool → Transaction Adapter: provides pool
- Migration Runner → Database Migrations: applies migrations
- PostgreSQL Pool → Migration Runner: provides pool
- Migration Runner → PostgreSQL: updates schema
