How tidurak/govnoedpromoapi works
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: promo.go Promo Handler · main.go API Bootstrap · migrations.go Migration Runner · health.go Health Handler
Components 15
Go API Runtime
- API Bootstrap · Wires dependencies and starts the HTTP server.
cmd/api/main.go - Configuration
internal/config/config.go - Promo Handler
internal/handler/promo.go - Generation Request
internal/handler/generateRequest.go - Generation Response
internal/handler/generateResponse.go - Health Handler
internal/handler/health.go - Response Formatting · Formats success and error responses.
internal/handler/response.go - Promo Service · Generates and validates promo codes.
internal/service/promo.go
Persistence
- Promo Repository
internal/repository/promo.go - SQLite Database Lifecycle · Opens the externally hosted SQLite database.
internal/database/database.go - Migration Runner
internal/database/migrations.go - Redeem Keys Schema
internal/database/migrations/001_create_redeem_keys.sql
External Systems
- govnoed.de Website
- External SQLite Database · Durably stores generated redeem keys.
- DebilBot · Uses generated promo codes in a separate project.
Connections 18
- 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