How mathvaillant/ticket-booking-backend works
Project Type and Purpose
• This is a single‐service REST API written in Go.
• It implements authentication, event management, and ticketing endpoints.
• It persists data in a relational database and is containerized via Docker.
File Structure
• cmd/api/main.go: entry point for the API server
• handlers/: HTTP handler functions (auth.go, event.go, ticket.go)
• middlewares/: request filtering (auth‐protected endpoints)
• services/: business logic layer
• repositories/: data access layer (CRUD against DB)
• models/: domain entities (User, Event, Ticket, Auth structures)
• db/: database initialization and migration code
• config/: configuration loader (env, .env)
• utils/: JWT utilities for token generation and validation
• Dockerfile, docker-compose.yaml: container definitions
• Makefile, .air.toml: developer tooling (build, run, live‐reload)
README
• Minimal content; no architectural hints beyond “main” branch.
• Rely primarily on directory naming and code conventions.
Main Components
a. API Server
• Layered internally:
• HTTP Layer (handlers + middlewares)
• Service Layer (business logic)
• Repository Layer (DB access)
• Models (shared data structures)
• Config & Utils (global helpers)
b. Database
• Relational DB (e.g., PostgreSQL/MySQL) launched via docker-compose
• Migration subsystem (db/auto-migrate.go)
c. External Clients
• Web/Mobile clients or API consumers sending HTTP/HTTPS requests
d. Infrastructure
• Docker container for API
• Docker network linking API ←→ DB
Relationships & Data Flow
• Client → HTTP(S) → API Gateway (if present) or directly to API
• API Entry (cmd/api) → HTTP Middleware (auth, logging) → Handler
• Handler invokes Service methods
• Service calls Repository methods
• Repository runs SQL via db.Database instance → Database container
• Database returns rows → Repository → Service → Handler → Response to Client
• Config loader initializes environment variables; Utils (JWT) injects tokens into HTTP headers.
Architectural Patterns & Design Principles
• Layered (Onion) Architecture: separate concerns (Presentation, Domain, Persistence)
• Dependency Injection via config/config.go and main.go wiring
• Single Responsibility: each package handles a single aspect (e.g., auth, events)
• Containerization: reproducible environments with Docker & docker-compose
• Auto‐migration at startup ensures schema is in sync.
Technologies, Frameworks & Libraries
• Go (Go modules for dependency management)
• Gorilla Mux or built‐in net/http for routing (implied by handlers)
• Docker, docker-compose
• .air for hot‐reload in development
• JWT (utils/jwt.go) for stateless auth
• SQL driver (MySQL/Postgres) via db/database.go
• Makefile for build/test automation