# tidurak/govnoedpromoapi architecture

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

- Interactive diagram: https://gitdiagram.com/tidurak/govnoedpromoapi
- Repository: https://github.com/tidurak/govnoedpromoapi

## Overview

#### Purpose and Runtime

DebilBot/GovnoedPromoAPI is a lightweight Go HTTP backend for govnoed.de. It generates promo/redeem codes for the DebilBot ecosystem and persists them in an externally hosted SQLite database. The executable entry point is `cmd/api/main.go`.

#### Application Bootstrap

`cmd/api/main.go` initializes configuration, opens the database, applies migrations, constructs repository/service/handler dependencies, and starts the HTTP server. Environment-oriented settings are centralized in `internal/config/config.go`; database lifecycle and schema migration execution are owned by `internal/database/database.go` and `internal/database/migrations.go`.

#### HTTP API Boundary

The handler layer is the public HTTP boundary. It receives website requests, parses generation inputs, invokes business logic, and serializes API responses:
- `internal/handler/promo.go`
- `internal/handler/generateRequest.go`
- `internal/handler/generateResponse.go`

Health checking is exposed separately through `internal/handler/health.go`. Shared response/error formatting is kept in `internal/handler/response.go`.

#### Promo Generation Service

`internal/service/promo.go` contains the core use case: generate promo codes and coordinate their persistence. It isolates business rules from HTTP mechanics and database access, allowing handlers to remain request/response adapters and repositories to remain storage adapters.

#### Persistence and Schema Ownership

`internal/repository/promo.go` is the data-access boundary for promo/redeem-key records. SQLite connection management is in `internal/database/database.go`; database schema evolution is migration-driven:
- `internal/database/migrations/001_create_redeem_keys.sql`
- `internal/database/migrations.go`

The redeem-key table is the durable system-of-record for generated codes.

#### Primary Flow

A website client calls an HTTP promo-generation endpoint. The handler decodes the request into the generation request model, calls the promo service, and returns a structured generation response. The service creates and validates the code according to its domain rules, then uses the promo repository to write it to SQLite. Errors cross back through the handler response layer as HTTP-safe responses.

#### Infrastructure and External Dependencies

The deployed runtime is a Go API process backed by an external SQLite database, appropriate for a resource-constrained VPS. The consumer-facing external integration is the govnoed.de website over HTTP; generated codes are intended for the separate DebilBot project. No separate frontend or message-broker runtime is represented in this repository.

Main entry points: [`internal/handler/promo.go`](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/promo.go) (Promo Handler), [`cmd/api/main.go`](https://github.com/tidurak/govnoedpromoapi/blob/master/cmd/api/main.go) (API Bootstrap), [`internal/database/migrations.go`](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/database/migrations.go) (Migration Runner), [`internal/handler/health.go`](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/health.go) (Health Handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Go API Runtime"]
  node_main{{"API Bootstrap<br/>Go entry point<br/>[main.go]"}}
  node_config["Configuration<br/>settings<br/>[config.go]"]
  node_promo_handler["Promo Handler<br/>HTTP handler<br/>[promo.go]"]
  node_generation_request["Generation Request<br/>request model<br/>[generateRequest.go]"]
  node_generation_response["Generation Response<br/>response model"]
  node_health_handler["Health Handler<br/>HTTP handler<br/>[health.go]"]
  node_response_formatter["Response Formatting<br/>HTTP response adapter<br/>[response.go]"]
  node_promo_service["Promo Service<br/>business service<br/>[promo.go]"]
end

subgraph group_persistence["Persistence"]
  node_promo_repository["Promo Repository<br/>data-access adapter<br/>[promo.go]"]
  node_database["SQLite Database Lifecycle<br/>connection management<br/>[database.go]"]
  node_migrations_runner["Migration Runner<br/>schema migration<br/>[migrations.go]"]
  node_redeem_keys_schema["Redeem Keys Schema<br/>SQL migration"]
end

subgraph group_external["External Systems"]
  node_website["govnoed.de Website<br/>HTTP client"]
  node_sqlite[("External SQLite Database<br/>system of record")]
  node_debilbot["DebilBot<br/>code consumer"]
end

node_website -->|"HTTP generation request"| node_promo_handler
node_website -->|"health request"| node_health_handler
node_main -->|"loads"| node_config
node_main -->|"opens"| node_database
node_main -->|"runs"| node_migrations_runner
node_main -->|"wires"| node_promo_handler
node_main -->|"wires"| node_health_handler
node_promo_handler -->|"decodes"| node_generation_request
node_promo_handler -->|"invokes"| node_promo_service
node_promo_handler -->|"serializes"| node_generation_response
node_promo_handler -->|"formats errors"| node_response_formatter
node_health_handler -->|"formats response"| node_response_formatter
node_promo_service -->|"persists code"| node_promo_repository
node_promo_repository -->|"uses connection"| node_database
node_database -->|"connects to"| node_sqlite
node_migrations_runner -->|"applies"| node_redeem_keys_schema
node_migrations_runner -->|"updates schema"| node_sqlite
node_sqlite -.->|"redeem codes available to"| node_debilbot

click node_main "https://github.com/tidurak/govnoedpromoapi/blob/master/cmd/api/main.go"
click node_config "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/config/config.go"
click node_promo_handler "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/promo.go"
click node_generation_request "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/generateRequest.go"
click node_generation_response "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/generateResponse.go"
click node_health_handler "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/health.go"
click node_response_formatter "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/response.go"
click node_promo_service "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/service/promo.go"
click node_promo_repository "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/repository/promo.go"
click node_database "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/database/database.go"
click node_migrations_runner "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/database/migrations.go"
click node_redeem_keys_schema "https://github.com/tidurak/govnoedpromoapi/blob/master/internal/database/migrations/001_create_redeem_keys.sql"

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_main,node_config,node_promo_handler,node_generation_request,node_generation_response,node_health_handler,node_response_formatter,node_promo_service toneBlue
class node_promo_repository,node_database,node_migrations_runner,node_redeem_keys_schema toneAmber
class node_website,node_sqlite,node_debilbot toneMint
```

## Components

### Go API Runtime

- [API Bootstrap](https://github.com/tidurak/govnoedpromoapi/blob/master/cmd/api/main.go): Go entry point · Wires dependencies and starts the HTTP server. · `cmd/api/main.go`
- [Configuration](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/config/config.go): settings · `internal/config/config.go`
- [Promo Handler](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/promo.go): HTTP handler · `internal/handler/promo.go`
- [Generation Request](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/generateRequest.go): request model · `internal/handler/generateRequest.go`
- [Generation Response](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/generateResponse.go): response model · `internal/handler/generateResponse.go`
- [Health Handler](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/health.go): HTTP handler · `internal/handler/health.go`
- [Response Formatting](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/handler/response.go): HTTP response adapter · Formats success and error responses. · `internal/handler/response.go`
- [Promo Service](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/service/promo.go): business service · Generates and validates promo codes. · `internal/service/promo.go`

### Persistence

- [Promo Repository](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/repository/promo.go): data-access adapter · `internal/repository/promo.go`
- [SQLite Database Lifecycle](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/database/database.go): connection management · Opens the externally hosted SQLite database. · `internal/database/database.go`
- [Migration Runner](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/database/migrations.go): schema migration · `internal/database/migrations.go`
- [Redeem Keys Schema](https://github.com/tidurak/govnoedpromoapi/blob/master/internal/database/migrations/001_create_redeem_keys.sql): SQL migration · `internal/database/migrations/001_create_redeem_keys.sql`

### External Systems

- **govnoed.de Website**: HTTP client
- **External SQLite Database**: system of record · Durably stores generated redeem keys.
- **DebilBot**: code consumer · Uses generated promo codes in a separate project.

## Connections

- govnoed.de Website → Promo Handler: HTTP generation request
- govnoed.de Website → Health Handler: health request
- API Bootstrap → Configuration: loads
- API Bootstrap → SQLite Database Lifecycle: opens
- API Bootstrap → Migration Runner: runs
- API Bootstrap → Promo Handler: wires
- API Bootstrap → Health Handler: wires
- Promo Handler → Generation Request: decodes
- Promo Handler → Promo Service: invokes
- Promo Handler → Generation Response: serializes
- Promo Handler → Response Formatting: formats errors
- Health Handler → Response Formatting: formats response
- Promo Service → Promo Repository: persists code
- Promo Repository → SQLite Database Lifecycle: uses connection
- SQLite Database Lifecycle → External SQLite Database: connects to
- Migration Runner → Redeem Keys Schema: applies
- Migration Runner → External SQLite Database: updates schema
- External SQLite Database → DebilBot: redeem codes available to
