Project Structure
This document outlines the organization of the fintech platform's codebase. The project follows clean architecture principles with clear separation of concerns between domain logic, application services, and infrastructure.
๐ Directory Overview
The codebase is organized into several key directories, each with a specific purpose:
/cmd
- Application entry points/internal
- Private application code (not for external use)/pkg
- Public packages that can be used by external applications/configs
- Configuration files/deployments
- Deployment configurations/docs
- Documentation/test
- Test suites
๐๏ธ Architecture Layers
The application follows a clean architecture with these layers:
- Domain Layer - Core business logic and entities
- Application Layer - Use cases and business rules
- Interface Layer - API endpoints and external interfaces
- Infrastructure Layer - External services and persistence
๐ Development Workflow
- Configuration via environment variables
- Containerized with Docker
- CI/CD with GitHub Actions
- Automated testing and code quality checks
fintech/
โโโ .github/ # GitHub Actions workflows for CI/CD ๐
โโโ api/ # Vercel serverless function entry point (for serverless deployments) โ๏ธ
โโโ cmd/ # Main application entry points
โ โโโ cli/ # Command-Line Interface application ๐ป
โ โโโ server/ # HTTP server application ๐
โโโ docs/ # Project documentation, OpenAPI spec, HTTP request examples, coverage reports ๐
โโโ infra/ # Infrastructure Layer ๐๏ธ
โ โโโ eventbus/ # Internal event bus for domain/integration events โก
โ โโโ provider/ # Payment/currency providers, webhook simulation ๐ฆ
โ โโโ repository/ # Concrete repository implementations ๐พ
โโโ pkg/ # Core Application Packages (Domain, Application, and Shared Infrastructure) ๐ฆ
โ โโโ cache/ # Caching interfaces and implementations ๐๏ธ
โ โโโ commands/ # Command pattern implementations โก
โ โโโ currency/ # Currency domain logic and utilities ๐ฑ
โ โโโ domain/ # Domain Layer: Core business entities and rules โค๏ธ
โ โ โโโ account/ # Account domain entities and business logic ๐ณ
โ โ โโโ events/ # Domain events for event-driven architecture ๐ก
โ โ โโโ money/ # Money value object and currency handling ๐ฐ
โ โ โโโ user/ # User domain entities ๐ค
โ โโโ dto/ # Data Transfer Objects for API communication ๐
โ โโโ eventbus/ # Event bus interfaces and implementations ๐
โ โโโ handler/ # Event handlers for business flows ๐ฏ
โ โ โโโ account/ # Account-related event handlers
โ โ โ โโโ deposit/ # Deposit flow handlers
โ โ โ โโโ transfer/ # Transfer flow handlers
โ โ โ โโโ withdraw/ # Withdraw flow handlers
โ โ โโโ conversion/ # Currency conversion handlers
โ โ โโโ payment/ # Payment processing handlers
โ โ โโโ transaction/ # Transaction-related handlers
โ โโโ mapper/ # Object mapping utilities ๐
โ โโโ middleware/ # Shared middleware components ๐ฆ
โ โโโ processor/ # Business process orchestrators โ๏ธ
โ โโโ provider/ # External service provider interfaces ๐
โ โโโ queries/ # Query pattern implementations ๐
โ โโโ registry/ # Service registry and dependency injection ๐
โ โโโ repository/ # Repository interfaces & UoW ๐๏ธ
โ โโโ service/ # Application Layer: Orchestrates use cases, emits/handles events โ๏ธ
โ โ โโโ account/ # Account service implementations
โ โ โโโ auth/ # Authentication services
โ โ โโโ currency/ # Currency services
โ โ โโโ user/ # User services
โ โโโ utils/ # Shared utility functions ๐ ๏ธ
โโโ webapi/ # Presentation Layer (Web API) ๐
โ โโโ account/ # Account HTTP handlers, DTOs, webhooks, and related tests ๐ณ
โ โโโ auth/ # Authentication HTTP handlers and DTOs ๐
โ โโโ common/ # Shared web API utilities (e.g., error formatting) ๐ ๏ธ
โ โโโ currency/ # Currency HTTP handlers and DTOs ๐ฑ
โ โโโ testutils/ # Test helpers for web API layer ๐งช
โ โโโ user/ # User HTTP handlers and DTOs ๐ค
โ โโโ app.go # Fiber application setup and route registration ๐
โโโ internal/ # Internal packages (not for external use) ๐
โ โโโ fixtures/ # Test fixtures and mocks ๐งช
โโโ scripts/ # Build and deployment scripts ๐
โโโ config/ # Configuration management โ๏ธ
โโโ go.mod # Go module definition ๐
โโโ go.sum # Go module checksums โ
โโโ Makefile # Automation scripts ๐ค
โโโ Dockerfile # Docker build instructions ๐ณ
โโโ docker-compose.yml# Docker Compose config ๐ ๏ธ
โโโ .env.example # Example environment variables ๐
โโโ .gitignore # Ignore rules ๐
โโโ README.md # Project README ๐
โโโ ARCHITECTURE.md # Architecture documentation ๐๏ธ
โโโ CONTRIBUTING.md # Contribution guidelines ๐ค
โโโ vercel.json # Vercel deployment config โ๏ธ
๐๏ธ Architecture Layers
Domain Layer (pkg/domain/
)
- Pure business logic with no external dependencies
- Value objects like
Money
for type safety - Domain entities like
Account
andUser
- Domain events for event-driven architecture
Application Layer (pkg/service/
, pkg/handler/
)
- Use case orchestration through services
- Event handlers for business flow processing
- Application-specific business rules
Infrastructure Layer (infra/
)
- Database implementations using GORM
- External service integrations (Stripe, currency APIs)
- Event bus implementations
Presentation Layer (webapi/
)
- HTTP handlers using Fiber framework
- Request/response DTOs
- Authentication and middleware
๐ฏ Key Design Principles
- Clean Architecture: Clear separation between layers
- Domain-Driven Design: Business logic encapsulated in domain layer
- Event-Driven Architecture: Loose coupling through domain events
- Dependency Injection: Services registered through registry pattern
- Repository Pattern: Data access abstraction
- Unit of Work Pattern: Transaction management
๐งช Testing Structure
- Unit Tests: Located alongside source files (
*_test.go
) - Integration Tests: Test complete workflows
- E2E Tests: Test full business scenarios
- Test Fixtures: Shared test data in
internal/fixtures/
- Mocks: Generated mocks for interfaces
Each directory and file is designed to support clean architecture and event-driven design. See the rest of the docs for deeper dives into each layer.