How lucasbrito3001/ms-wallet-service works
Project Type and Purpose
• The project is a backend application that follows Hexagonal Architecture and Domain-Driven Design (DDD) principles.
• Its main business functions revolve around wallet management and account operations (evident from files like WalletController.ts, AccountRepository.ts, CreateWallet.ts, AddBalance.ts, etc.).
• It also uses messaging for asynchronous events (e.g., RabbitMQ adapters and queue subscribers) and incorporates several infrastructure components (database integration, error handling, logging).
Main Components
• Domain Layer:
– Entities: Account, Operation, Wallet (located in src/domain/entities).
– Domain Events: e.g., AccountCreated, OrderItemsApproved.
– Base Domain objects (e.g., Base.ts).
• Application Layer:
– Use Cases: AddBalance, CheckBalance, CreateWallet, PayOrder (under src/application/usecase).
– Controllers: OperationController and WalletController (under src/application/controller).
– Schema/Validation components: Input schemas (defined under src/application/schema/input) and related index.
– Services: JwtService, which may handle authentication or security aspects.
• Infrastructure Layer:
– Repositories: Both Domain repositories under src/application/repository and Infrastructure-specific repository implementations (database and mock versions found under src/infra/repository/database and src/infra/repository/mock).
– Server setup: The main Server (src/infra/Server.ts) responsible for bootstrapping the application, along with the DependencyRegistry for dependency injection.
– Routing: Routers (WalletRouter, OperationRouter) in the infra/router folder that represents the API layer.
– Queue / Messaging: Components under src/infra/queue, including the RabbitMQAdapter and queue subscribers that handle domain event publication/subscription.
– Additional infra: Data Source, Logging (GeneralLogger, Logger), and schema validator (ZodSchemaValidator).
• External Interfaces:
– API requests: The main entry points facilitated by the HTTP server and routers.
– Database: Suggested by init.sql and respective repository implementations.
– Messaging: Usage of RabbitMQ for asynchronous communication.
– Docker support: Deployment and environment configuration with Dockerfile, docker-compose.yaml, and nginx.conf.
Architectural Patterns and Design Principles
– The “driving adapters” (e.g., HTTP/REST controllers and queue subscribers) on one side of the core,
– And the “driven adapters” (e.g., repository implementations) on the other.
• Dependency inversion by showing that the Application and Domain layers do not depend directly on the Infrastructure implementations.
• Error handling components and testing (unit and e2e tests) as separate modules (if desired) to indicate robustness in design.