How z1ngod/myfin-back-end works
Project type and purpose
• This is a backend API built with NestJS (TypeScript).
• Purpose: provide endpoints for “MyFin” expense management app—handling authentication, budgets, expenses, and user data.
• Monolithic, modular design: divided into core feature modules and shared “libs.”
File structure
• Top‑level:
– src/app.module.ts – Nest root module
– src/main.ts – entry point
– src/core – feature modules (auth, budgets, expenses, user)
– src/libs – shared modules (db, cache, redis, security)
• Each feature module contains: controllers, DTOs, services, tests.
• Shared “libs/db” uses schemas and repositories (Mongoose), migrations and seed scripts.
• “libs/redis” provides a caching module and service.
• “libs/security” contains guards, strategies, and token/password services.
• Config and environment validation under src/common.
• CI/CD workflows, linting, commit hooks, and release configs in root.
Key architectural insights from README
• Backend API only (no UI).
• NestJS modular architecture—emphasis on separation of concerns.
• Integrates with a MongoDB (via Mongoose schemas + migrations) and Redis for caching.
• JWT‑based auth (access & refresh token strategies).
Components & interactions
a. Main components:
1. Client (MyFin App or Postman)
2. API Gateway (NestJS application)
3. Feature Modules:
– Auth Module (login, token refresh)
– Budgets Module
– Expenses Module
– Users Module
4. Shared Modules:
– DB Module (Mongoose connection, repositories)
– Redis Cache Module
– Security Module (Guards, JWT strategies)
5. External Systems:
– MongoDB database
– Redis server
b. Relationships / Data Flow:
1. Client → HTTP request → NestJS Controllers (for each feature)
2. Controller → Service → (optional) Redis Cache lookup/write
3. If cache miss or non-cacheable: Service → Repository → MongoDB
4. Repository → returns data → Service (business logic) → Controller → HTTP response
5. Auth flows: Controller uses Security Guards → TokenService → issues/verifies JWT
6. Common Env & Config provider injects settings into all modules
c. Architectural patterns / design principles:
• Layered architecture: Controllers → Services → Repositories → DB
• Modular structure: each feature in its own Nest module
• Shared libraries for cross‑cutting concerns (cache, security, DB)
• Dependency injection via NestJS modules
• Separation of config (env validation, constants) from code
d. Relevant technologies / frameworks:
– NestJS (module-based DI)
– TypeScript
– Mongoose (schema definitions, migrations, seeders)
– Redis (caching)
– JWT (via passport strategies in security module)
– Testing: Jest (unit + e2e)