- Architecture Overview
- Project Structure
- Dependency Injection
- API Endpoints
- Scalability
- Error Handling
The project adheres to Clean Architecture principles, ensuring a clear separation of concerns across layers. The structure is organized as follows:
pkg/
├── controllers/ # HTTP request handlers
├── services/ # Business logic
├── repositories/ # Data access
├── models/ # Domain models
├── dtos/ # Data Transfer Objects
├── interfaces/ # Layer interfaces
└── common/ # Shared utilities
- Controllers: Handle HTTP requests and responses.
- Services: Implement business logic and orchestrate operations.
- Repositories: Manage data persistence and retrieval.
- Models: Define core business entities.
- DTOs: Define request/response data structures.
- Interfaces: Define contracts between layers.
The typical flow of control in the system is as follows:
HTTP Request → Controller → Service → Repository → Database
↑ ↑ ↑
└─ DTOs ─────┴── Models ┘
pkg/
├── controllers/
│ ├── interfaces/
│ └── implementations/
├── services/
│ ├── interfaces/
│ └── implementations/
├── repositories/
│ ├── interfaces/
│ └── implementations/
├── models/
├── dtos/
│ ├── request/
│ └── response/
└── common/
├── exceptions/
└── helper/
- Clear Separation of Concerns: Independent layers for modularity and maintainability.
- Interface-Driven Development: Facilitates testability and flexibility.
- Dependency Injection: Promotes clean, decoupled code.
- Centralized Error Handling: Ensures consistent and structured error responses.
- Audit Logging: Tracks significant system events.
- Automated Testing: Mocks and unit tests for all critical components.
Dependency injection is implemented using constructor-based methods, enabling seamless integration and mockability for unit tests. Example:
func NewInvoiceController(
logger zerolog.Logger,
invoiceService services_interfaces.InvoiceService,
auditService services_interfaces.AuditService,
reminderService services_interfaces.ReminderService,
customerService services_interfaces.CustomerService,
) controller_interfaces.InvoiceController {
return &invoiceController{
logger: logger,
invoiceService: invoiceService,
auditService: auditService,
reminderService: reminderService,
customerService: customerService,
}
}
All endpoints require authentication via the x-customer-id header:
x-customer-id: <customer_id>
Full API documentation is available here: https://documenter.getpostman.com/view/14136605/2sAYBYe9So
- Efficient indexing
- Proper relationship modeling
- Connection pooling
- Query optimization
-
Caching
- Response caching
- Database query caching
- In-memory caching for frequently accessed data
-
Async Processing
- Background job processing and message queues for heavy operations
- Structured logging with zerolog
- Audit trail for important operations
- Performance metrics
- Error tracking
// Common error responses
func ThrowBadRequestException(ctx gin.Context, message string) {
ctx.JSON(http.StatusBadRequest, BuildErrorResponse(message))
}
- Validation errors
- Business logic errors
- Database errors
- External service errors