Skip to content

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:

  1. Domain Layer - Core business logic and entities
  2. Application Layer - Use cases and business rules
  3. Interface Layer - API endpoints and external interfaces
  4. 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 and User
  • 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.