# nonlight/test-for-go-pet-shop architecture

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

- Interactive diagram: https://gitdiagram.com/nonlight/test-for-go-pet-shop
- Repository: https://github.com/nonlight/test-for-go-pet-shop

## Overview

This is a Go Pet Shop HTTP service exposing health checks and product listing, creation, updating, and deletion. Its main workflow is an HTTP request routed to a product handler, validated or decoded, then passed to PostgreSQL storage; the handler returns JSON and errors as HTTP responses. Startup loads configuration, initializes logging and storage, and registers routes. The README emphasizes handler tests and mock variants, but those are excluded from this runtime map. The migration command is shown separately; unsampled migration details are not inferred.

Main entry points: [`cmd/app/main.go`](https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/app/main.go) (App startup), [`internal/handlers/product/products.go`](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/handlers/product/products.go) (Product handlers), [`internal/storage/postgres/postgres.go`](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/storage/postgres/postgres.go) (Postgres storage), [`cmd/migrator/main.go`](https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/migrator/main.go) (Migration command)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_app["App startup<br/>[main.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_logger["Logger<br/>[logger.go]"]
  node_router["Chi router<br/>[main.go]"]
  node_health["Health handler<br/>[status.go]"]
end

subgraph group_product["Product Domain"]
  node_product_handler["Product handlers<br/>[products.go]"]
  node_product_model["Product models<br/>[models.go]"]
end

subgraph group_persistence["Persistence"]
  node_storage_interface["Storage errors<br/>[storage.go]"]
  node_postgres_storage["Postgres storage<br/>[postgres.go]"]
  node_product_queries["Product queries<br/>[product.go]"]
  node_database[("PostgreSQL")]
  node_migrator["Migration command<br/>[main.go]"]
  node_migration_files["Schema migrations"]
end

node_client(("HTTP client"))

node_client -->|"sends requests"| node_router
node_app -->|"loads settings"| node_config
node_app -->|"sets up"| node_logger
node_app -->|"initializes"| node_postgres_storage
node_app -->|"registers routes"| node_router
node_app -->|"constructs"| node_product_handler
node_router -->|"dispatches health"| node_health
node_router -->|"dispatches products"| node_product_handler
node_product_handler -->|"decodes and returns"| node_product_model
node_product_handler -->|"calls product methods"| node_postgres_storage
node_postgres_storage -->|"provides storage"| node_product_queries
node_product_queries -->|"queries products"| node_database
node_migrator -->|"applies migrations"| node_database
node_migrator -->|"reads migration files"| node_migration_files

click node_app "https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/app/main.go"
click node_config "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/config/config.go"
click node_logger "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/lib/logger/logger.go"
click node_router "https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/app/main.go"
click node_health "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/handlers/status.go"
click node_product_handler "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/handlers/product/products.go"
click node_product_model "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/models/models.go"
click node_storage_interface "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/storage/storage.go"
click node_postgres_storage "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/storage/postgres/postgres.go"
click node_product_queries "https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/storage/postgres/product.go"
click node_migrator "https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/migrator/main.go"
click node_migration_files "https://github.com/nonlight/test-for-go-pet-shop/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_app,node_config,node_logger,node_router,node_health,node_client toneBlue
class node_product_handler,node_product_model toneAmber
class node_storage_interface,node_postgres_storage,node_product_queries,node_database,node_migrator,node_migration_files toneMint
```

## Components

### HTTP API

- [App startup](https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/app/main.go): `cmd/app/main.go`
- [Configuration](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/config/config.go): `internal/config/config.go`
- [Logger](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/lib/logger/logger.go): `internal/lib/logger/logger.go`
- [Chi router](https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/app/main.go): `cmd/app/main.go`
- [Health handler](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/handlers/status.go): `internal/handlers/status.go`

### Product Domain

- [Product handlers](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/handlers/product/products.go): `internal/handlers/product/products.go`
- [Product models](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/models/models.go): `internal/models/models.go`

### Persistence

- [Storage errors](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/storage/storage.go): `internal/storage/storage.go`
- [Postgres storage](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/storage/postgres/postgres.go): `internal/storage/postgres/postgres.go`
- [Product queries](https://github.com/nonlight/test-for-go-pet-shop/blob/main/internal/storage/postgres/product.go): `internal/storage/postgres/product.go`
- **PostgreSQL**
- [Migration command](https://github.com/nonlight/test-for-go-pet-shop/blob/main/cmd/migrator/main.go): `cmd/migrator/main.go`
- [Schema migrations](https://github.com/nonlight/test-for-go-pet-shop/tree/main/migrations): `migrations`

### Other components

- **HTTP client**

## Connections

- HTTP client → Chi router: sends requests
- App startup → Configuration: loads settings
- App startup → Logger: sets up
- App startup → Postgres storage: initializes
- App startup → Chi router: registers routes
- App startup → Product handlers: constructs
- Chi router → Health handler: dispatches health
- Chi router → Product handlers: dispatches products
- Product handlers → Product models: decodes and returns
- Product handlers → Postgres storage: calls product methods
- Postgres storage → Product queries: provides storage
- Product queries → PostgreSQL: queries products
- Migration command → PostgreSQL: applies migrations
- Migration command → Schema migrations: reads migration files
