# kong-chansila/backend-portfolio architecture

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

- Interactive diagram: https://gitdiagram.com/kong-chansila/backend-portfolio
- Repository: https://github.com/kong-chansila/backend-portfolio

## Overview

This is a Go backend for a portfolio site: it serves public content and contact submissions, plus a protected CMS and account-management API. The main request path is client → routed middleware/handler → domain service → repository → MySQL. Authentication resolves cookie sessions before protected handlers; adminctl separately bootstraps and manages accounts. The README is empty, so capability coverage follows the routes and source index. Some service-to-repository links rely on indexed references rather than sampled call bodies.

Main entry points: [`internal/routes/routes.go`](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/routes/routes.go) (Route wiring), [`internal/repositories`](https://github.com/kong-chansila/backend-portfolio/tree/main/internal/repositories) (Domain repositories), [`internal/handlers/admin.go`](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/admin.go) (CMS endpoints), [`internal/services/auth.go`](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/auth.go) (Authentication service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_api["HTTP server<br/>[main.go]"]
  node_routes["Route wiring<br/>[routes.go]"]
  node_middleware["Request guards"]
  node_config["Configuration"]
end

subgraph group_domain["Domain workflows"]
  node_auth_handler["Auth endpoints<br/>[auth.go]"]
  node_admin_handler["CMS endpoints<br/>[admin.go]"]
  node_content_handler["Public content<br/>[content.go]"]
  node_contact_handler["Contact intake<br/>[contact.go]"]
  node_health_handler["Health check<br/>[health.go]"]
  node_auth_service["Authentication service<br/>[auth.go]"]
  node_content_service["Content service<br/>[content.go]"]
  node_translation_service["Translation service<br/>[translation.go]"]
  node_contact_service["Contact service<br/>[contact.go]"]
  node_audit_service["Audit service<br/>[audit.go]"]
end

subgraph group_persistence["Persistence"]
  node_repositories["Domain repositories"]
  node_mysql[("MySQL database")]
end

subgraph group_operations["Account operations"]
  node_adminctl["Admin CLI<br/>[main.go]"]
end

node_client(("Site / admin client"))

node_client -->|"sends requests"| node_api
node_api -->|"serves handler"| node_routes
node_api -->|"loads settings"| node_config
node_api -->|"opens connection"| node_mysql
node_routes -->|"routes auth"| node_auth_handler
node_routes -->|"routes admin"| node_admin_handler
node_routes -->|"routes content"| node_content_handler
node_routes -->|"routes contact"| node_contact_handler
node_routes -->|"routes health"| node_health_handler
node_routes -->|"wraps handlers"| node_middleware
node_middleware -->|"resolves sessions"| node_auth_service
node_auth_handler -->|"handles credentials"| node_auth_service
node_auth_handler -->|"records events"| node_audit_service
node_admin_handler -->|"manages content"| node_content_service
node_admin_handler -->|"manages users"| node_auth_service
node_admin_handler -->|"records admin actions"| node_audit_service
node_admin_handler -->|"reads messages"| node_repositories
node_content_handler -->|"fetches site content"| node_content_service
node_contact_handler -->|"submits message"| node_contact_service
node_content_service -->|"reads and writes content"| node_repositories
node_content_service -->|"applies translations"| node_translation_service
node_translation_service -->|"loads translations"| node_repositories
node_contact_service -->|"stores submissions"| node_repositories
node_auth_service -->|"uses account stores"| node_repositories
node_audit_service -->|"persists audit events"| node_repositories
node_repositories -->|"queries database"| node_mysql
node_adminctl -->|"loads settings"| node_config
node_adminctl -->|"opens connection"| node_mysql
node_adminctl -->|"creates and lists users"| node_auth_service

click node_api "https://github.com/kong-chansila/backend-portfolio/blob/main/cmd/api/main.go"
click node_routes "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/routes/routes.go"
click node_middleware "https://github.com/kong-chansila/backend-portfolio/tree/main/internal/middleware"
click node_auth_handler "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/auth.go"
click node_admin_handler "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/admin.go"
click node_content_handler "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/content.go"
click node_contact_handler "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/contact.go"
click node_health_handler "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/health.go"
click node_auth_service "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/auth.go"
click node_content_service "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/content.go"
click node_translation_service "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/translation.go"
click node_contact_service "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/contact.go"
click node_audit_service "https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/audit.go"
click node_repositories "https://github.com/kong-chansila/backend-portfolio/tree/main/internal/repositories"
click node_adminctl "https://github.com/kong-chansila/backend-portfolio/blob/main/cmd/adminctl/main.go"
click node_config "https://github.com/kong-chansila/backend-portfolio/tree/main/internal/config"

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_routes,node_middleware,node_config,node_client toneBlue
class node_auth_handler,node_admin_handler,node_content_handler,node_contact_handler,node_health_handler,node_auth_service,node_content_service,node_translation_service,node_contact_service,node_audit_service toneAmber
class node_repositories,node_mysql toneMint
class node_adminctl toneRose
```

## Components

### API entry

- [HTTP server](https://github.com/kong-chansila/backend-portfolio/blob/main/cmd/api/main.go): `cmd/api/main.go`
- [Route wiring](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/routes/routes.go): `internal/routes/routes.go`
- [Request guards](https://github.com/kong-chansila/backend-portfolio/tree/main/internal/middleware): `internal/middleware`
- [Configuration](https://github.com/kong-chansila/backend-portfolio/tree/main/internal/config): `internal/config`

### Domain workflows

- [Auth endpoints](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/auth.go): `internal/handlers/auth.go`
- [CMS endpoints](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/admin.go): `internal/handlers/admin.go`
- [Public content](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/content.go): `internal/handlers/content.go`
- [Contact intake](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/contact.go): `internal/handlers/contact.go`
- [Health check](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/handlers/health.go): `internal/handlers/health.go`
- [Authentication service](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/auth.go): `internal/services/auth.go`
- [Content service](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/content.go): `internal/services/content.go`
- [Translation service](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/translation.go): `internal/services/translation.go`
- [Contact service](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/contact.go): `internal/services/contact.go`
- [Audit service](https://github.com/kong-chansila/backend-portfolio/blob/main/internal/services/audit.go): `internal/services/audit.go`

### Persistence

- [Domain repositories](https://github.com/kong-chansila/backend-portfolio/tree/main/internal/repositories): `internal/repositories`
- **MySQL database**

### Account operations

- [Admin CLI](https://github.com/kong-chansila/backend-portfolio/blob/main/cmd/adminctl/main.go): `cmd/adminctl/main.go`

### Other components

- **Site / admin client**

## Connections

- Site / admin client → HTTP server: sends requests
- HTTP server → Route wiring: serves handler (evidence: `cmd/api/main.go`)
- HTTP server → Configuration: loads settings (evidence: `cmd/api/main.go`)
- HTTP server → MySQL database: opens connection (evidence: `cmd/api/main.go`)
- Route wiring → Auth endpoints: routes auth (evidence: `internal/routes/routes.go`)
- Route wiring → CMS endpoints: routes admin (evidence: `internal/routes/routes.go`)
- Route wiring → Public content: routes content (evidence: `internal/routes/routes.go`)
- Route wiring → Contact intake: routes contact (evidence: `internal/routes/routes.go`)
- Route wiring → Health check: routes health (evidence: `internal/routes/routes.go`)
- Route wiring → Request guards: wraps handlers (evidence: `internal/routes/routes.go`)
- Request guards → Authentication service: resolves sessions (evidence: `internal/middleware/auth.go`)
- Auth endpoints → Authentication service: handles credentials (evidence: `internal/handlers/auth.go`)
- Auth endpoints → Audit service: records events (evidence: `internal/handlers/auth.go`)
- CMS endpoints → Content service: manages content (evidence: `internal/handlers/admin.go`)
- CMS endpoints → Authentication service: manages users (evidence: `internal/handlers/admin.go`)
- CMS endpoints → Audit service: records admin actions (evidence: `internal/handlers/admin.go`)
- CMS endpoints → Domain repositories: reads messages (evidence: `internal/handlers/admin.go`)
- Public content → Content service: fetches site content (evidence: `internal/handlers/content.go`)
- Contact intake → Contact service: submits message (evidence: `internal/handlers/contact.go`)
- Content service → Domain repositories: reads and writes content (evidence: `internal/services/content.go`)
- Content service → Translation service: applies translations (evidence: `internal/services/content.go`)
- Translation service → Domain repositories: loads translations (evidence: `internal/services/translation.go`)
- Contact service → Domain repositories: stores submissions (evidence: `internal/services/contact.go`)
- Authentication service → Domain repositories: uses account stores (evidence: `internal/services/auth.go`)
- Audit service → Domain repositories: persists audit events (evidence: `internal/services/audit.go`)
- Domain repositories → MySQL database: queries database (evidence: `internal/repositories/session.go`)
- Admin CLI → Configuration: loads settings (evidence: `cmd/adminctl/main.go`)
- Admin CLI → MySQL database: opens connection (evidence: `cmd/adminctl/main.go`)
- Admin CLI → Authentication service: creates and lists users (evidence: `cmd/adminctl/main.go`)
