How gehmac/desafio-backend-wallet works
Project Type and Purpose
• The project is a backend API, built with NestJS, for managing users, wallets, and transfers. It handles user authentication using JWT tokens (access and refresh) and supports transactional operations such as transfers and reverts.
• The README outlines a clear RESTful API with versioned endpoints (under /v1/) for authentication, wallet operations, and transaction management. It also notes the use of Docker containers, database migrations via TypeORM, and Node.js (version 22).
Analyzing the File Structure
• Top-Level Files & Config: Files like .env, docker-compose.yml, nest-cli.json, and TypeScript configuration files (tsconfig.json) indicate that this is a Node.js project using NestJS, with environment configuration and containerized deployment.
• Core Application Entry Points: The src/main.ts and src/app.ts suggest the starting point of the NestJS application.
• Modular Organization: The project is divided into several modules:
• “auth”: Contains its own controllers, DTOs, services, and strategies for handling token-based authentication.
• “users”: Manages user-related operations with controllers, DTOs for creating/updating users, entities, repositories, and a dedicated service.
• “wallets”: Handles wallet operations, including querying balances and transfers.
• “transactions”: Manages transfer transactions and reversion of transfers.
• “_shared”: Provides shared modules for configuration, database connectivity (migrations and TypeORM configuration), decorators, and guards.
• Each module has its own controller, service, entities, and repository directories. This suggests a modular style (often aligning with Domain Driven Design), and possibly indicating separation of concerns via NestJS modules.
a. Main Components to Include:
• Client / Consumer: Represents external users or clients making HTTP requests to the API.
• API Gateway/Controller: Denotes the entry point of the application (using NestJS), where requests are routed based on endpoints.
• Authentication Module: Handles registration and login endpoints with token issuance and token refreshing. Also includes the strategies and guards to protect routes.
• Users Module: Manages the CRUD operations for user entities.
• Wallets Module: Manages wallet-related functionalities, such as balance checks and wallet-specific endpoints.
• Transactions Module: Manages transfer operations; includes processes for initiating, monitoring, and reverting transfers.
• Shared Components:
– Config Module: Reads environment variables and configuration settings.
– Database Module: Manages the connection to the database and the migration processes (using TypeORM).
– Shared Decorators & Guards: Handles cross-cutting concerns like obtaining the current user and authentication validations.
• Infrastructure Components:
– Docker Containers: Representing the containerized environment (as per docker-compose.yml).
– Relational Database: Represents persistent storage for users, wallets, transactions, etc.
b. Relationships and Interactions:
• Data flow between controllers and their respective service layers.
• Interactions between services – for example, the Wallets Module and Transactions Module may both rely on common validations or shared fundamental business logic.
• Database communication: Indicate that migrations and runtime queries (handled by repositories using TypeORM) connect to a relational database.
c. Architectural Patterns & Design Principles:
• Modular architecture that separates concerns into distinct modules.
• Clean layering (Controller → Service → Repository) which aligns well with Domain-Driven Architecture.
• Authentication is token-based with clear strategies (access and refresh tokens) and utilizes guards to protect secured routes.
• Containerization via Docker highlights a microservice-friendly or at least an isolated, reproducible environment approach.
d. Relevant Technologies and Tools:
• NestJS as the framework for building the API.
• TypeORM for managing database operations and migrations.
• Docker for container orchestration.
• Node.js (version 22) as the runtime.
• JWT (implied by access and refresh tokens) for authentication.