How nsaltun/todolist-service works
Project Type and Purpose
• This is a microservice dedicated to managing a TODOLIST, built using Golang.
• It follows a Hexagonal architecture style, ensuring that core domain logic remains decoupled from the infrastructure.
• The README indicates a focus on features such as user CRUD operations, health & metrics endpoints, and integration with observability tools like Prometheus and Grafana. It also leverages the Fiber framework for HTTP handling, Zap for logging, and OpenTelemetry.
Analyzing the File Structure
• Entry Point: The “cmd/main.go” file is where the application starts, initializing configuration and setting up servers.
• Application Layer: The “app” directory contains subdirectories for specific functionality:
• “app/healthcheck” for health endpoints.
• “app/todoitem” for handlers that manage TODOLIST item creation and retrieval.
• Domain Layer: The “domain” directory holds core business models (e.g., “todo.go” and “filter.go”) representing the central logic.
• Infrastructure Layer:
• The “infra” directory (particularly “infra/postgres”) manages Postgresql connectivity and the concrete implementation of repositories.
• Middleware: Contains “middleware/error_middleware.go” and “middleware/logging_middleware.go” to handle error logging and request monitoring.
• Reusable Packages: Under “pkg”, you have generic HTTP handler logic, logging, and pagination which support the service’s operations.
• Deployment and Observability:
• The “deploy” directory includes configuration for Grafana (dashboards and datasources) and Prometheus, highlighting focus on monitoring.
• Additional Configuration & DB:
• The “config” directory offers centralized application configuration.
• The “migrations” folder holds the SQL migration scripts for evolving the database schema.
Main Components & Their Relationships
• Client Layer: Any external client (or internal user) sending HTTP requests to the service endpoints.
• API/Adapter Layer (HTTP Handlers): Represented by the “app/todoitem” and “app/healthcheck” packages. This layer leverages the generic HTTP handler logic from “pkg/httphandler/fiber_handler.go” to map incoming requests to the service's business logic.
• Domain Core: The “domain” directory encapsulates the business models and rules. This is the core of your Hexagonal architecture.
• Infrastructure / Adapters:
• Database: “infra/postgres” shows the database connection management and repository implementation, interfacing directly with your Postgresql DB.
• External Adapters: Deployment scripts and resources for Grafana and Prometheus link the internal metrics and logs to these external monitoring systems.
• Middleware: Ensures cross-cutting concerns (logging, error handling) are applied to requests throughout the system.
• Configuration & Logging: Centralized configuration (via “config/config.go”) and logging mechanisms (via “pkg/logging”) are incorporated throughout the service.
• Deployment/DevOps: Docker, Docker-compose, and deployment configs that ensure the service runs in containerized environments.
Architectural Principles
• Hexagonal Architecture: Separate core (Domain) from the outer layers (HTTP handlers, database, and other external systems). Emphasize clear boundaries with ports (interfaces) and adapters (implementations).
• Port-Adaptor Design: Layer the application to isolate the business logic from both the web framework (Fiber) and the infrastructure details (Postgresql, Prometheus, Grafana).
• Observability: Integration with Grafana and Prometheus ensures health and metrics endpoints are properly monitored.
• Extensibility & Modularity: Use of middleware and generic HTTP handlers supports easy extension to other protocols or frameworks if needed.