# afarmo/forum architecture

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

- Interactive diagram: https://gitdiagram.com/afarmo/forum
- Repository: https://github.com/afarmo/forum

## Overview

Literary Lions Forum is a Go web forum for book-club discussions, with categories organizing posts. The main workflow is an HTTP request routed through middleware to a handler, then through a domain service to SQLite-backed repositories; results are returned as JSON or rendered templates. The graph includes authentication, posts/search, categories, comments, profiles, and the persistence layer. Some domain capabilities are documented by route registrations or the README but their implementation details were not sampled, so those internal links are limited to supported wiring.

Main entry points: [`cmd/main.go`](https://github.com/afarmo/forum/blob/main/cmd/main.go) (HTTP server), [`internal/router/router.go`](https://github.com/afarmo/forum/blob/main/internal/router/router.go) (Route dispatch), [`internal/middleware/auth.go`](https://github.com/afarmo/forum/blob/main/internal/middleware/auth.go) (Request middleware), [`internal/service/auth.go`](https://github.com/afarmo/forum/blob/main/internal/service/auth.go) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["HTTP and UI"]
  node_server["HTTP server<br/>[main.go]"]
  node_routing["Route dispatch<br/>[router.go]"]
  node_middleware["Request middleware<br/>[auth.go]"]
  node_templates["Web templates"]
  node_static["Static assets"]
end

subgraph group_domain["Forum capabilities"]
  node_auth_handler["Auth handlers<br/>[auth.go]"]
  node_auth_service["Authentication<br/>[auth.go]"]
  node_passwords["Password hashing<br/>[password.go]"]
  node_post_handler["Post handlers<br/>[post.go]"]
  node_post_service["Post and search<br/>[post.go]"]
  node_category_handler["Category handlers<br/>[categories.go]"]
  node_category_service["Categories<br/>[category.go]"]
  node_comment_handler["Comment handlers<br/>[comment.go]"]
  node_comment_service["Comments<br/>[comment.go]"]
  node_user_handler["Profile handlers<br/>[user.go]"]
  node_user_service["User profiles<br/>[user.go]"]
  node_home_handler["Home feed<br/>[home.go]"]
  node_reaction_service["Reactions<br/>[reaction.go]"]
end

subgraph group_persistence["Persistence and models"]
  node_sqlite[("SQLite database<br/>[db.go]")]
  node_schema["Forum schema<br/>[schema.sql]"]
  node_seed["Initial data<br/>[seed.go]"]
  node_post_repo["Post repository<br/>[post.go]"]
  node_category_repo["Category repository<br/>[category.go]"]
  node_comment_repo["Comment repository<br/>[comment.go]"]
  node_session_repo["Session repository<br/>[session.go]"]
  node_user_repo["User repository<br/>[user.go]"]
  node_models["Forum data models"]
end

node_member(("Forum member"))

node_member -->|"sends requests"| node_server
node_server -->|"opens database"| node_sqlite
node_server -->|"initializes schema"| node_schema
node_server -->|"serves routes"| node_routing
node_server -->|"wraps requests"| node_middleware
node_server -->|"constructs repository"| node_post_repo
node_server -->|"constructs repository"| node_category_repo
node_server -->|"constructs repository"| node_comment_repo
node_server -->|"constructs repository"| node_session_repo
node_server -->|"constructs repository"| node_user_repo
node_server -->|"parses templates"| node_templates
node_routing -->|"routes auth"| node_auth_handler
node_routing -->|"routes posts"| node_post_handler
node_routing -->|"routes categories"| node_category_handler
node_routing -->|"routes comments"| node_comment_handler
node_routing -->|"routes profiles"| node_user_handler
node_routing -->|"routes home"| node_home_handler
node_routing -->|"serves assets"| node_static
node_middleware -->|"dispatches requests"| node_routing
node_auth_handler -->|"invokes auth"| node_auth_service
node_auth_service -->|"hashes passwords"| node_passwords
node_auth_service -->|"looks up users"| node_user_repo
node_auth_service -->|"creates sessions"| node_session_repo
node_middleware -->|"checks sessions"| node_session_repo
node_middleware -->|"loads user"| node_user_repo
node_post_handler -->|"invokes post actions"| node_post_service
node_post_service -->|"queries and writes"| node_post_repo
node_post_repo -->|"reads and writes"| node_sqlite
node_category_handler -->|"invokes categories"| node_category_service
node_category_service -->|"queries categories"| node_category_repo
node_comment_handler -->|"invokes comments"| node_comment_service
node_comment_service -->|"queries and writes"| node_comment_repo
node_user_handler -->|"updates profile"| node_user_service
node_user_handler -->|"loads categories"| node_category_service
node_user_handler -->|"loads user posts"| node_post_service
node_home_handler -->|"loads categories"| node_category_service
node_home_handler -->|"loads feed"| node_post_service
node_user_service -->|"accesses user data"| node_user_repo
node_templates -.->|"renders pages"| node_member
node_reaction_service -.->|"reaction storage"| node_post_repo
node_models -.->|"represents stored data"| node_sqlite

click node_server "https://github.com/afarmo/forum/blob/main/cmd/main.go"
click node_routing "https://github.com/afarmo/forum/blob/main/internal/router/router.go"
click node_middleware "https://github.com/afarmo/forum/blob/main/internal/middleware/auth.go"
click node_templates "https://github.com/afarmo/forum/tree/main/internal/web/templates"
click node_static "https://github.com/afarmo/forum/tree/main/internal/web/static"
click node_auth_handler "https://github.com/afarmo/forum/blob/main/internal/handlers/auth.go"
click node_auth_service "https://github.com/afarmo/forum/blob/main/internal/service/auth.go"
click node_passwords "https://github.com/afarmo/forum/blob/main/internal/auth/password.go"
click node_post_handler "https://github.com/afarmo/forum/blob/main/internal/handlers/post.go"
click node_post_service "https://github.com/afarmo/forum/blob/main/internal/service/post.go"
click node_category_handler "https://github.com/afarmo/forum/blob/main/internal/handlers/categories.go"
click node_category_service "https://github.com/afarmo/forum/blob/main/internal/service/category.go"
click node_comment_handler "https://github.com/afarmo/forum/blob/main/internal/handlers/comment.go"
click node_comment_service "https://github.com/afarmo/forum/blob/main/internal/service/comment.go"
click node_user_handler "https://github.com/afarmo/forum/blob/main/internal/handlers/user.go"
click node_user_service "https://github.com/afarmo/forum/blob/main/internal/service/user.go"
click node_home_handler "https://github.com/afarmo/forum/blob/main/internal/handlers/home.go"
click node_reaction_service "https://github.com/afarmo/forum/blob/main/internal/service/reaction.go"
click node_sqlite "https://github.com/afarmo/forum/blob/main/internal/database/db.go"
click node_schema "https://github.com/afarmo/forum/blob/main/internal/database/schema.sql"
click node_seed "https://github.com/afarmo/forum/blob/main/internal/database/seed.go"
click node_post_repo "https://github.com/afarmo/forum/blob/main/internal/repository/post.go"
click node_category_repo "https://github.com/afarmo/forum/blob/main/internal/repository/category.go"
click node_comment_repo "https://github.com/afarmo/forum/blob/main/internal/repository/comment.go"
click node_session_repo "https://github.com/afarmo/forum/blob/main/internal/repository/session.go"
click node_user_repo "https://github.com/afarmo/forum/blob/main/internal/repository/user.go"
click node_models "https://github.com/afarmo/forum/tree/main/internal/models"

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_server,node_routing,node_middleware,node_templates,node_static toneBlue
class node_auth_handler,node_auth_service,node_passwords,node_post_handler,node_post_service,node_category_handler,node_category_service,node_comment_handler,node_comment_service,node_user_handler,node_user_service,node_home_handler,node_reaction_service toneAmber
class node_sqlite,node_schema,node_seed,node_post_repo,node_category_repo,node_comment_repo,node_session_repo,node_user_repo,node_models toneMint
class node_member toneIndigo
```

## Components

### HTTP and UI

- [HTTP server](https://github.com/afarmo/forum/blob/main/cmd/main.go): `cmd/main.go`
- [Route dispatch](https://github.com/afarmo/forum/blob/main/internal/router/router.go): `internal/router/router.go`
- [Request middleware](https://github.com/afarmo/forum/blob/main/internal/middleware/auth.go): `internal/middleware/auth.go`
- [Web templates](https://github.com/afarmo/forum/tree/main/internal/web/templates): `internal/web/templates`
- [Static assets](https://github.com/afarmo/forum/tree/main/internal/web/static): `internal/web/static`

### Forum capabilities

- [Auth handlers](https://github.com/afarmo/forum/blob/main/internal/handlers/auth.go): `internal/handlers/auth.go`
- [Authentication](https://github.com/afarmo/forum/blob/main/internal/service/auth.go): `internal/service/auth.go`
- [Password hashing](https://github.com/afarmo/forum/blob/main/internal/auth/password.go): `internal/auth/password.go`
- [Post handlers](https://github.com/afarmo/forum/blob/main/internal/handlers/post.go): `internal/handlers/post.go`
- [Post and search](https://github.com/afarmo/forum/blob/main/internal/service/post.go): `internal/service/post.go`
- [Category handlers](https://github.com/afarmo/forum/blob/main/internal/handlers/categories.go): `internal/handlers/categories.go`
- [Categories](https://github.com/afarmo/forum/blob/main/internal/service/category.go): `internal/service/category.go`
- [Comment handlers](https://github.com/afarmo/forum/blob/main/internal/handlers/comment.go): `internal/handlers/comment.go`
- [Comments](https://github.com/afarmo/forum/blob/main/internal/service/comment.go): `internal/service/comment.go`
- [Profile handlers](https://github.com/afarmo/forum/blob/main/internal/handlers/user.go): `internal/handlers/user.go`
- [User profiles](https://github.com/afarmo/forum/blob/main/internal/service/user.go): `internal/service/user.go`
- [Home feed](https://github.com/afarmo/forum/blob/main/internal/handlers/home.go): `internal/handlers/home.go`
- [Reactions](https://github.com/afarmo/forum/blob/main/internal/service/reaction.go): `internal/service/reaction.go`

### Persistence and models

- [SQLite database](https://github.com/afarmo/forum/blob/main/internal/database/db.go): `internal/database/db.go`
- [Forum schema](https://github.com/afarmo/forum/blob/main/internal/database/schema.sql): `internal/database/schema.sql`
- [Initial data](https://github.com/afarmo/forum/blob/main/internal/database/seed.go): `internal/database/seed.go`
- [Post repository](https://github.com/afarmo/forum/blob/main/internal/repository/post.go): `internal/repository/post.go`
- [Category repository](https://github.com/afarmo/forum/blob/main/internal/repository/category.go): `internal/repository/category.go`
- [Comment repository](https://github.com/afarmo/forum/blob/main/internal/repository/comment.go): `internal/repository/comment.go`
- [Session repository](https://github.com/afarmo/forum/blob/main/internal/repository/session.go): `internal/repository/session.go`
- [User repository](https://github.com/afarmo/forum/blob/main/internal/repository/user.go): `internal/repository/user.go`
- [Forum data models](https://github.com/afarmo/forum/tree/main/internal/models): `internal/models`

### Other components

- **Forum member**

## Connections

- Forum member → HTTP server: sends requests (evidence: `cmd/main.go`)
- HTTP server → SQLite database: opens database (evidence: `cmd/main.go`)
- HTTP server → Forum schema: initializes schema (evidence: `cmd/main.go`)
- HTTP server → Route dispatch: serves routes (evidence: `cmd/main.go`)
- HTTP server → Request middleware: wraps requests (evidence: `cmd/main.go`)
- HTTP server → Post repository: constructs repository (evidence: `cmd/main.go`)
- HTTP server → Category repository: constructs repository (evidence: `cmd/main.go`)
- HTTP server → Comment repository: constructs repository (evidence: `cmd/main.go`)
- HTTP server → Session repository: constructs repository (evidence: `cmd/main.go`)
- HTTP server → User repository: constructs repository (evidence: `cmd/main.go`)
- HTTP server → Web templates: parses templates (evidence: `cmd/main.go`)
- Route dispatch → Auth handlers: routes auth (evidence: `internal/router/router.go`)
- Route dispatch → Post handlers: routes posts (evidence: `internal/router/router.go`)
- Route dispatch → Category handlers: routes categories (evidence: `internal/router/router.go`)
- Route dispatch → Comment handlers: routes comments (evidence: `internal/router/router.go`)
- Route dispatch → Profile handlers: routes profiles (evidence: `internal/router/router.go`)
- Route dispatch → Home feed: routes home (evidence: `internal/router/router.go`)
- Route dispatch → Static assets: serves assets (evidence: `internal/router/router.go`)
- Request middleware → Route dispatch: dispatches requests
- Auth handlers → Authentication: invokes auth (evidence: `internal/handlers/auth.go`)
- Authentication → Password hashing: hashes passwords (evidence: `internal/service/auth.go`)
- Authentication → User repository: looks up users (evidence: `internal/service/auth.go`)
- Authentication → Session repository: creates sessions (evidence: `internal/service/auth.go`)
- Request middleware → Session repository: checks sessions (evidence: `internal/middleware/auth.go`)
- Request middleware → User repository: loads user (evidence: `internal/middleware/auth.go`)
- Post handlers → Post and search: invokes post actions (evidence: `internal/handlers/post.go`)
- Post and search → Post repository: queries and writes (evidence: `internal/service/post.go`)
- Post repository → SQLite database: reads and writes (evidence: `internal/repository/post.go`)
- Category handlers → Categories: invokes categories (evidence: `internal/handlers/categories.go`)
- Categories → Category repository: queries categories (evidence: `internal/service/category.go`)
- Comment handlers → Comments: invokes comments (evidence: `internal/handlers/comment.go`)
- Comments → Comment repository: queries and writes (evidence: `internal/service/comment.go`)
- Profile handlers → User profiles: updates profile (evidence: `internal/handlers/user.go`)
- Profile handlers → Categories: loads categories (evidence: `internal/handlers/user.go`)
- Profile handlers → Post and search: loads user posts (evidence: `internal/handlers/user.go`)
- Home feed → Categories: loads categories (evidence: `internal/handlers/home.go`)
- Home feed → Post and search: loads feed (evidence: `internal/handlers/home.go`)
- User profiles → User repository: accesses user data (evidence: `internal/service/user.go`)
- Web templates → Forum member: renders pages
- Reactions → Post repository: reaction storage
- Forum data models → SQLite database: represents stored data
