Zum Inhalt springen

Backend

cms/backend/
├── cmd/http/
│ ├── main.go # Server-Setup, DB, Migrations, Workers, Middleware
│ ├── routes.go # Alle Endpoints zentral
│ ├── handlers_auth.go # Auth HTTP-Adapter
│ ├── handlers_account.go # Account HTTP-Adapter
│ ├── handlers_team.go # Team HTTP-Adapter
│ ├── middleware.go # Session-Auth, RequestContext
│ ├── cookies.go # Cookie Get/Set
│ └── config.go # envconfig
├── internal/
│ ├── usecase/
│ │ ├── usecase.go # UseCases Struct (Auth, Account, Team)
│ │ └── context.go # ResolveAgencyContext, ResolveClientContext
│ ├── feature/
│ │ ├── auth/ # Login, 2FA, Session, Logout
│ │ ├── account/ # Profil, Passwort, Sessions (Self-Service)
│ │ ├── team/ # Account-CRUD (Admin-Verwaltung)
│ │ ├── email/ # Template-Rendering, Queue, Workers
│ │ └── geolocation/ # MaxMind Integration
│ ├── database/
│ │ ├── database.go # PostgreSQL-Connection (pgx via stdlib)
│ │ └── migrations.go # golang-migrate
│ └── shared/
│ ├── httputil/ # JSON Response Helpers
│ ├── logging/ # slog Wrapper, Request-Logging
│ └── requestctx/ # RequestContext Struct
├── migrations/ # SQL-Dateien (000001-000005)
└── gen/ # Jet-generierter Code (committed)
cmd/http/ → internal/usecase/ → internal/feature/*/
routes.go usecase.go usecase.go
handlers_*.go context.go repository.go
middleware.go jet_repository.go
cookies.go errors.go
SchichtVerantwortung
HTTP (cmd/http/)JSON en/decode, Cookies, Routing, X-Header-Parsing
UseCase (internal/usecase/)RequestContext, Session-Aufloesung, Feature-Gruppierung
Feature (internal/feature/*/)Business-Logik, Repository-Interfaces, Jet-Implementierungen

UseCases sind exportierte Structs pro Feature-Domain — keine Interfaces. Interfaces gibt es nur fuer Repositories (Testbarkeit/Mocking).

type UseCases struct {
Auth *auth.Auth
Account *account.Account
Team *team.Team
}

Jede UseCase-Methode bekommt: (ctx context.Context, rc requestctx.RequestContext, req FeatureRequest).

type RequestContext struct {
IPAddress string // X-Client-Ip
IPCountry string // X-Client-Ip-Country
UserAgent string // X-User-Agent
RayID string // X-Client-Ray-Id
SessionID *uuid.UUID
Account *AccountInfo // nil bei Public-Endpoints
}

Alle Endpoints stehen in einer Datei (cmd/http/routes.go) — nicht in Feature-Packages versteckt. Handler sind duenne HTTP-Adapter: JSON rein → UseCase aufrufen → JSON raus + ggf. Cookie setzen.

Die Session-Aufloesung (Session-ID → Account-Info) ist Business-Logik und lebt in der UseCase-Schicht (usecase.Resolve*Context), nicht in der HTTP-Middleware. Die HTTP-Middleware extrahiert nur rohe Daten und delegiert.

  • GitHub Actions: Backend (Go Build, Test, Lint) + Frontend (Build, Lint)
  • Dependabot: Woechentlich, gruppiert (npm + GitHub Actions)