# lkorsman/golang_learning architecture

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

- Interactive diagram: https://gitdiagram.com/lkorsman/golang_learning
- Repository: https://github.com/lkorsman/golang_learning

## Overview

Go Store API serves product CRUD and user registration/login, with JWT protection for product writes. Its API entry point wires handlers, middleware, persistence, caching, and chat; product requests validate inputs, use the store, and optionally cache results. A separate WebSocket workflow connects CLI users to a shared chat hub. The README also documents migrations and Prometheus observability. Product, auth, middleware, cache, and chat links are supported by excerpts; unsampled migration and configuration details are represented only where documented or wired by the API entry point.

Main entry points: [`cmd/api/main.go`](https://github.com/lkorsman/golang_learning/blob/main/cmd/api/main.go) (HTTP API), [`internal/product/handler.go`](https://github.com/lkorsman/golang_learning/blob/main/internal/product/handler.go) (Product endpoints), [`internal/auth/handler.go`](https://github.com/lkorsman/golang_learning/blob/main/internal/auth/handler.go) (Auth endpoints), [`internal/http/middleware.go`](https://github.com/lkorsman/golang_learning/blob/main/internal/http/middleware.go) (HTTP middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_api["HTTP API<br/>[main.go]"]
  node_middleware["HTTP middleware<br/>[middleware.go]"]
  node_metrics["Prometheus metrics<br/>[metrics.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_prometheus["Metrics endpoint"]
end

subgraph group_commerce["Products and storage"]
  node_products["Product endpoints<br/>[handler.go]"]
  node_validation["Product validation<br/>[validation.go]"]
  node_mysql["MySQL product store<br/>[mysql_store.go]"]
  node_schema["Database migrations"]
  node_redis_cache["Redis cache<br/>[redis.go]"]
  node_mysql_db[("MySQL database")]
  node_redis[("Redis")]
end

subgraph group_identity["Authentication"]
  node_auth_handler["Auth endpoints<br/>[handler.go]"]
  node_jwt["JWT manager<br/>[jwt.go]"]
  node_users["User store<br/>[store.go]"]
  node_user_model["User model<br/>[user.go]"]
end

subgraph group_realtime["Real-time chat"]
  node_chat_handler["Chat HTTP handler<br/>[handler.go]"]
  node_chat_client["Chat connection<br/>[client.go]"]
  node_chat_hub["Chat hub<br/>[hub.go]"]
  node_cli["Chat CLI<br/>[main.go]"]
end

node_caller(("API user"))

node_caller -->|"sends requests"| node_api
node_api -->|"loads settings"| node_config
node_api -->|"installs middleware"| node_middleware
node_api -->|"routes auth"| node_auth_handler
node_api -->|"routes products"| node_products
node_api -->|"routes chat"| node_chat_handler
node_api -->|"serves metrics"| node_prometheus
node_middleware -->|"records requests"| node_metrics
node_middleware -->|"verifies tokens"| node_jwt
node_middleware -->|"loads user"| node_users
node_auth_handler -->|"creates or reads"| node_users
node_auth_handler -->|"generates tokens"| node_jwt
node_auth_handler -->|"records auth"| node_metrics
node_auth_handler -->|"returns user"| node_user_model
node_products -->|"validates input"| node_validation
node_products -->|"uses product store"| node_mysql
node_products -->|"reads and invalidates"| node_redis_cache
node_products -->|"records product activity"| node_metrics
node_mysql -->|"queries"| node_mysql_db
node_mysql -->|"runs migrations"| node_schema
node_redis_cache -->|"reads and writes"| node_redis
node_chat_handler -->|"registers clients"| node_chat_hub
node_chat_handler -->|"starts pumps"| node_chat_client
node_chat_client -->|"broadcasts messages"| node_chat_hub
node_cli -->|"connects by WebSocket"| node_chat_handler
node_prometheus -.->|"exposes metrics"| node_metrics

click node_api "https://github.com/lkorsman/golang_learning/blob/main/cmd/api/main.go"
click node_middleware "https://github.com/lkorsman/golang_learning/blob/main/internal/http/middleware.go"
click node_metrics "https://github.com/lkorsman/golang_learning/blob/main/internal/metrics/metrics.go"
click node_config "https://github.com/lkorsman/golang_learning/blob/main/internal/config/config.go"
click node_auth_handler "https://github.com/lkorsman/golang_learning/blob/main/internal/auth/handler.go"
click node_jwt "https://github.com/lkorsman/golang_learning/blob/main/internal/auth/jwt.go"
click node_users "https://github.com/lkorsman/golang_learning/blob/main/internal/auth/store.go"
click node_user_model "https://github.com/lkorsman/golang_learning/blob/main/internal/auth/user.go"
click node_products "https://github.com/lkorsman/golang_learning/blob/main/internal/product/handler.go"
click node_validation "https://github.com/lkorsman/golang_learning/blob/main/internal/product/validation.go"
click node_mysql "https://github.com/lkorsman/golang_learning/blob/main/internal/product/mysql_store.go"
click node_schema "https://github.com/lkorsman/golang_learning/tree/main/migrations"
click node_redis_cache "https://github.com/lkorsman/golang_learning/blob/main/internal/cache/redis.go"
click node_chat_handler "https://github.com/lkorsman/golang_learning/blob/main/internal/chat/handler.go"
click node_chat_client "https://github.com/lkorsman/golang_learning/blob/main/internal/chat/client.go"
click node_chat_hub "https://github.com/lkorsman/golang_learning/blob/main/internal/chat/hub.go"
click node_cli "https://github.com/lkorsman/golang_learning/blob/main/cmd/chat-client/main.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_api,node_middleware,node_metrics,node_config,node_prometheus,node_caller toneBlue
class node_products,node_validation,node_mysql,node_schema,node_redis_cache,node_mysql_db,node_redis toneAmber
class node_auth_handler,node_jwt,node_users,node_user_model toneMint
class node_chat_handler,node_chat_client,node_chat_hub,node_cli toneRose
```

## Components

### API runtime

- [HTTP API](https://github.com/lkorsman/golang_learning/blob/main/cmd/api/main.go): `cmd/api/main.go`
- [HTTP middleware](https://github.com/lkorsman/golang_learning/blob/main/internal/http/middleware.go): `internal/http/middleware.go`
- [Prometheus metrics](https://github.com/lkorsman/golang_learning/blob/main/internal/metrics/metrics.go): `internal/metrics/metrics.go`
- [Configuration](https://github.com/lkorsman/golang_learning/blob/main/internal/config/config.go): `internal/config/config.go`
- **Metrics endpoint**

### Products and storage

- [Product endpoints](https://github.com/lkorsman/golang_learning/blob/main/internal/product/handler.go): `internal/product/handler.go`
- [Product validation](https://github.com/lkorsman/golang_learning/blob/main/internal/product/validation.go): `internal/product/validation.go`
- [MySQL product store](https://github.com/lkorsman/golang_learning/blob/main/internal/product/mysql_store.go): `internal/product/mysql_store.go`
- [Database migrations](https://github.com/lkorsman/golang_learning/tree/main/migrations): `migrations`
- [Redis cache](https://github.com/lkorsman/golang_learning/blob/main/internal/cache/redis.go): `internal/cache/redis.go`
- **MySQL database**
- **Redis**

### Authentication

- [Auth endpoints](https://github.com/lkorsman/golang_learning/blob/main/internal/auth/handler.go): `internal/auth/handler.go`
- [JWT manager](https://github.com/lkorsman/golang_learning/blob/main/internal/auth/jwt.go): `internal/auth/jwt.go`
- [User store](https://github.com/lkorsman/golang_learning/blob/main/internal/auth/store.go): `internal/auth/store.go`
- [User model](https://github.com/lkorsman/golang_learning/blob/main/internal/auth/user.go): `internal/auth/user.go`

### Real-time chat

- [Chat HTTP handler](https://github.com/lkorsman/golang_learning/blob/main/internal/chat/handler.go): `internal/chat/handler.go`
- [Chat connection](https://github.com/lkorsman/golang_learning/blob/main/internal/chat/client.go): `internal/chat/client.go`
- [Chat hub](https://github.com/lkorsman/golang_learning/blob/main/internal/chat/hub.go): `internal/chat/hub.go`
- [Chat CLI](https://github.com/lkorsman/golang_learning/blob/main/cmd/chat-client/main.go): `cmd/chat-client/main.go`

### Other components

- **API user**

## Connections

- API user → HTTP API: sends requests (evidence: `README.md`)
- HTTP API → Configuration: loads settings (evidence: `cmd/api/main.go`)
- HTTP API → HTTP middleware: installs middleware (evidence: `cmd/api/main.go`)
- HTTP API → Auth endpoints: routes auth (evidence: `cmd/api/main.go`)
- HTTP API → Product endpoints: routes products (evidence: `cmd/api/main.go`)
- HTTP API → Chat HTTP handler: routes chat (evidence: `cmd/api/main.go`)
- HTTP API → Metrics endpoint: serves metrics (evidence: `cmd/api/main.go`)
- HTTP middleware → Prometheus metrics: records requests (evidence: `internal/http/middleware.go`)
- HTTP middleware → JWT manager: verifies tokens (evidence: `internal/http/middleware.go`)
- HTTP middleware → User store: loads user (evidence: `internal/http/middleware.go`)
- Auth endpoints → User store: creates or reads (evidence: `internal/auth/handler.go`)
- Auth endpoints → JWT manager: generates tokens (evidence: `internal/auth/handler.go`)
- Auth endpoints → Prometheus metrics: records auth (evidence: `internal/auth/handler.go`)
- Auth endpoints → User model: returns user (evidence: `internal/auth/handler.go`)
- Product endpoints → Product validation: validates input (evidence: `internal/product/handler.go`)
- Product endpoints → MySQL product store: uses product store
- Product endpoints → Redis cache: reads and invalidates (evidence: `internal/product/handler.go`)
- Product endpoints → Prometheus metrics: records product activity (evidence: `internal/product/handler.go`)
- MySQL product store → MySQL database: queries (evidence: `internal/product/mysql_store.go`)
- MySQL product store → Database migrations: runs migrations (evidence: `internal/product/mysql_store.go`)
- Redis cache → Redis: reads and writes (evidence: `internal/cache/redis.go`)
- Chat HTTP handler → Chat hub: registers clients (evidence: `internal/chat/handler.go`)
- Chat HTTP handler → Chat connection: starts pumps (evidence: `internal/chat/handler.go`)
- Chat connection → Chat hub: broadcasts messages (evidence: `internal/chat/client.go`)
- Chat CLI → Chat HTTP handler: connects by WebSocket (evidence: `README.md`)
- Metrics endpoint → Prometheus metrics: exposes metrics
