# bipbopaw/go-pet-shop architecture

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

- Interactive diagram: https://gitdiagram.com/bipbopaw/go-pet-shop
- Repository: https://github.com/bipbopaw/go-pet-shop

## Overview

Go Pet Shop is a Go REST API backed by PostgreSQL. Its shown runtime workflow is HTTP request → router → product or health handler → PostgreSQL storage → JSON response; configuration and logging are initialized by the server entry point. The README also describes users, orders, transactional checkout, order history and analytics, but the supplied source excerpts only implement product CRUD and health-check, so those documented capabilities are shown as unverified subsystems without asserted runtime links.

Main entry points: [`cmd/app/main.go`](https://github.com/bipbopaw/go-pet-shop/blob/v1/cmd/app/main.go) (Server Entry), [`internal/handlers/product/products.go`](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/handlers/product/products.go) (Product CRUD), [`internal/storage/postgres/product.go`](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/storage/postgres/product.go) (Product Storage), [`internal/storage/postgres/postgres.go`](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/storage/postgres/postgres.go) (PostgreSQL Pool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_router["HTTP Router<br/>[main.go]"]
  node_product_handler["Product CRUD<br/>[products.go]"]
  node_health_handler["Health Check<br/>[status.go]"]
end

subgraph group_domain["Shop Domain"]
  node_models["Domain Models<br/>[models.go]"]
  node_users["User Management"]
  node_orders["Order Creation"]
  node_checkout["Transactional Checkout"]
  node_history["Order History"]
  node_analytics["Shop Analytics"]
end

subgraph group_persistence["Persistence"]
  node_product_store["Product Storage<br/>[product.go]"]
  node_pg_pool["PostgreSQL Pool<br/>[postgres.go]"]
  node_postgres[("PostgreSQL")]
  node_migrations["Database Schema"]
end

subgraph group_runtime["Server Runtime"]
  node_app["Server Entry<br/>[main.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_logger["Logging<br/>[logger.go]"]
end

node_client(("API Client"))

node_client -->|"sends requests"| node_router
node_app -->|"loads settings"| node_config
node_app -->|"configures logging"| node_logger
node_app -->|"opens pool"| node_pg_pool
node_app -->|"registers routes"| node_router
node_router -->|"routes product requests"| node_product_handler
node_router -->|"routes health requests"| node_health_handler
node_product_handler -->|"calls CRUD"| node_product_store
node_product_handler -->|"uses products"| node_models
node_product_store -->|"scans products"| node_models
node_product_store -->|"executes queries"| node_pg_pool
node_pg_pool -.->|"connects"| node_postgres
node_migrations -.->|"defines schema"| node_postgres

click node_app "https://github.com/bipbopaw/go-pet-shop/blob/v1/cmd/app/main.go"
click node_config "https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/config/config.go"
click node_logger "https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/lib/logger/logger.go"
click node_router "https://github.com/bipbopaw/go-pet-shop/blob/v1/cmd/app/main.go"
click node_product_handler "https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/handlers/product/products.go"
click node_health_handler "https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/handlers/status.go"
click node_models "https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/models/models.go"
click node_product_store "https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/storage/postgres/product.go"
click node_pg_pool "https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/storage/postgres/postgres.go"
click node_users "https://github.com/bipbopaw/go-pet-shop/tree/v1/internal"
click node_orders "https://github.com/bipbopaw/go-pet-shop/tree/v1/internal"
click node_checkout "https://github.com/bipbopaw/go-pet-shop/tree/v1/internal"
click node_history "https://github.com/bipbopaw/go-pet-shop/tree/v1/internal"
click node_analytics "https://github.com/bipbopaw/go-pet-shop/tree/v1/internal"
click node_migrations "https://github.com/bipbopaw/go-pet-shop/tree/v1/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_router,node_product_handler,node_health_handler,node_client toneBlue
class node_models,node_users,node_orders,node_checkout,node_history,node_analytics toneAmber
class node_product_store,node_pg_pool,node_postgres,node_migrations toneMint
class node_app,node_config,node_logger toneRose
```

## Components

### HTTP API

- [HTTP Router](https://github.com/bipbopaw/go-pet-shop/blob/v1/cmd/app/main.go): `cmd/app/main.go`
- [Product CRUD](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/handlers/product/products.go): `internal/handlers/product/products.go`
- [Health Check](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/handlers/status.go): `internal/handlers/status.go`

### Shop Domain

- [Domain Models](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/models/models.go): `internal/models/models.go`
- [User Management](https://github.com/bipbopaw/go-pet-shop/tree/v1/internal): `internal`
- [Order Creation](https://github.com/bipbopaw/go-pet-shop/tree/v1/internal): `internal`
- [Transactional Checkout](https://github.com/bipbopaw/go-pet-shop/tree/v1/internal): `internal`
- [Order History](https://github.com/bipbopaw/go-pet-shop/tree/v1/internal): `internal`
- [Shop Analytics](https://github.com/bipbopaw/go-pet-shop/tree/v1/internal): `internal`

### Persistence

- [Product Storage](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/storage/postgres/product.go): `internal/storage/postgres/product.go`
- [PostgreSQL Pool](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/storage/postgres/postgres.go): `internal/storage/postgres/postgres.go`
- **PostgreSQL**
- [Database Schema](https://github.com/bipbopaw/go-pet-shop/tree/v1/migrations): `migrations`

### Server Runtime

- [Server Entry](https://github.com/bipbopaw/go-pet-shop/blob/v1/cmd/app/main.go): `cmd/app/main.go`
- [Configuration](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/config/config.go): `internal/config/config.go`
- [Logging](https://github.com/bipbopaw/go-pet-shop/blob/v1/internal/lib/logger/logger.go): `internal/lib/logger/logger.go`

### Other components

- **API Client**

## Connections

- API Client → HTTP Router: sends requests (evidence: `cmd/app/main.go`)
- Server Entry → Configuration: loads settings (evidence: `cmd/app/main.go`)
- Server Entry → Logging: configures logging (evidence: `cmd/app/main.go`)
- Server Entry → PostgreSQL Pool: opens pool (evidence: `cmd/app/main.go`)
- Server Entry → HTTP Router: registers routes (evidence: `cmd/app/main.go`)
- HTTP Router → Product CRUD: routes product requests (evidence: `cmd/app/main.go`)
- HTTP Router → Health Check: routes health requests (evidence: `cmd/app/main.go`)
- Product CRUD → Product Storage: calls CRUD (evidence: `internal/handlers/product/products.go`)
- Product CRUD → Domain Models: uses products (evidence: `internal/handlers/product/products.go`)
- Product Storage → Domain Models: scans products (evidence: `internal/storage/postgres/product.go`)
- Product Storage → PostgreSQL Pool: executes queries (evidence: `internal/storage/postgres/product.go`)
- PostgreSQL Pool → PostgreSQL: connects
- Database Schema → PostgreSQL: defines schema
