How sewy-bit/go-and-eat works
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: http.go Order Endpoints · create_order.go Create Order · database/postgres.go PostgreSQL Pool · storage/postgres.go Order Storage
Components 17
HTTP API
- Order Endpoints
internal/order/handler/http.go - Restaurant Endpoints
internal/restaurant/handler/http.go
Order Workflow
- Create Order
internal/order/usecase/create_order.go - Get Order
internal/order/usecase/get_order.go - Update Status
internal/order/usecase/update_order_status.go - User Orders
internal/order/usecase/get_user_orders.go - Order Model
internal/order/domain/order.go - Order Storage
internal/order/storage/postgres.go
Restaurant Catalog
- Restaurant Model
internal/restaurant/domain/restaurant.go - Restaurant Storage
internal/restaurant/storage/postgres.go
Persistence Platform
- Configuration
internal/pkg/config/config.go - PostgreSQL Pool
internal/pkg/database/postgres.go - Transaction Adapter
internal/pkg/database/transaction.go - Migration Runner
internal/pkg/migrate/migrate.go - Database Migrations
scripts/migrations/restaurant
Other components
- API Client
- PostgreSQL
Connections 26
- API Client → Order Endpoints: sends requests
- API Client → Restaurant Endpoints: sends requests
- Order Endpoints → Create Order: executes
internal/order/handler/http.go - Order Endpoints → Get Order: executes
internal/order/handler/http.go - Order Endpoints → Update Status: executes
internal/order/handler/http.go - Order Endpoints → User Orders: executes
internal/order/handler/http.go - Restaurant Endpoints → Restaurant Storage: calls
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
internal/order/handler/http.go - Create Order → Order Model: builds order
internal/order/usecase/create_order.go - Create Order → Restaurant Model: uses menu items
internal/order/usecase/create_order.go - Restaurant Endpoints → Restaurant Model: builds catalog data
internal/restaurant/handler/http.go - Restaurant Storage → PostgreSQL: reads and writes
internal/restaurant/storage/postgres.go - Order Storage → PostgreSQL: reads and writes
internal/order/storage/postgres.go - Configuration → PostgreSQL Pool: provides settings
- PostgreSQL Pool → PostgreSQL: opens pool
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