How isadoramsouza/rinha-backend-go-2024-q1 works
Project Type and Purpose
• This is a single-service, full-stack backend API written in Go (using the Gin framework) that implements two endpoints for transaction recording and statement retrieval.
• It uses PostgreSQL for persistence and NGINX as a reverse proxy/load-balancer, all orchestrated via Docker Compose.
File Structure
• cmd/api/: application entrypoint
• main.go: bootstraps Gin, loads routes (cmd/api/routes/routes.go) and handlers (cmd/api/handler/transacao.go).
• internal/: business logic
• domain/: core entities (cliente, transacao, extrato)
• transacao/: service layer (service.go) + repository (repository.go)
• pkg/web/: response models/serializers
• config/deploy: Dockerfile, docker-compose.yml, docker-compose-local.yml, nginx.conf, init.sql
• Scripts: run.sh for local startup
• CI: .github/workflows/ci.yml
README Highlights
• Two HTTP endpoints (POST /clientes/:id/transacoes, GET /clientes/:id/extrato)
• Stack: Go 1.21 (Gin), PostgreSQL, NGINX
• Run via docker-compose up -d exposing port 9999
Main Components and Their Relationships
a. Client (Postman/cURL/Browser)
b. NGINX reverse proxy (nginx.conf)
c. Go/Gin API service
• HTTP Router → Handlers → Service layer → Repository → PostgreSQL
d. PostgreSQL database
e. Supporting artifacts
• init.sql for schema
• Docker containers
Architectural Patterns & Design Principles
• Clean/Chex pattern: separation of layers (presentation in cmd/, domain in internal/domain, application logic in internal/transacao, delivery in pkg/web)
• Dependency inversion: handlers depend on service interfaces, services depend on repository interfaces
• Containerization: each component (NGINX, API, Postgres) runs in its own Docker container
Essential Elements
• Clear labels on all components (e.g., “Gin API Service,” “PostgreSQL DB,” “NGINX Proxy”)
• Version or config references (e.g., “↓ port 9999,” “init.sql → DB schema”)