How ras0q/go-backend-template works
Main Components
• API Server: Represented by main.go that sets up the server and initializes dependencies.
• Request Handlers: Found in the internal/handler directory (handler.go, ping.go, user.go) – these map incoming HTTP requests to the appropriate logic.
• Database Layer: Although the DB isn’t directly coded (it’s spun up via Docker Compose), it is interfaced through the internal/repository directory where actual DB access methods (e.g., user.go) are implemented.
• Migrations: Shown in internal/migration (1_schema.sql, migration.go) – these manage DB schema changes.
• Configuration & Utility Packages: Located in internal/pkg/config – these hold configuration logic (e.g., DB connection settings).
• Integration Tests: Found in the integration directory, which uses ory/dockertest to spin up DB containers and test the real integrations.
• DevOps / Deployment Artifacts: Dockerfile, compose.yml, .github workflows, Makefile, etc. – representing CI/CD pipelines, containerization, and automation.
Relationships and Interactions
• The API Server (via main.go) initializes the router and middleware; it delegates routing to the request handlers.
• Request Handlers (in internal/handler) perform request processing and then call into the repository layer in internal/repository for DB operations.
• The repository layer abstracts interactions with the database, which is managed externally (via Docker Compose) and prepared using migrations.
• Migrations ensure the DB schema is up-to-date, acting as a pre-step before running the repository code.
• Configuration is centrally managed (in internal/pkg/config) and is used at initialization across the application.
• Integration tests validate the interactions among these components by spinning up actual instances (using dockertest and Docker Compose).
Architectural Patterns / Design Principles
• Layered Architecture: Separation into handlers, repositories, and migration/config packages.
• Dependency Injection: While not explicitly shown in every file, the main.go and config modules hint at a pattern where dependencies are injected during initialization.
• Modularization via Go’s internal package: The use of the internal directory ensures that core logic is encapsulated and not accessible from outside modules.
• DevOps Integration: Containerization with Docker and automation through Makefile and GitHub Actions indicate a CI/CD-friendly design.