How deepak-meena-github/forex-trading-system works
Project type & purpose (what you’re diagramming)
This repo is a backend-only NestJS (Node.js/TypeScript) REST API called “Forex Trading System API”. Its responsibilities (per README + endpoints) are:
• Expose HTTP endpoints for:
• Fetching live FX rates (GET /fx-rates)
• Top-up a user account (POST /top-up/:userId)
• Query account balance (GET /balance/:userId)
• Execute FX conversion (POST /fx-conversion)
• Integrate with Alpha Vantage (external API) using ALPHA_VANTAGE_API_KEY
• API consumers → NestJS app → domain/service logic → external Alpha Vantage
• Optional persistence (explicitly marked as “in-memory” if true, or “future DB” if intended)
Top-level
• src/ → source code (Nest app)
• dist/ → compiled JS output (deployment artifact)
• test/ → e2e tests (Jest)
• nest-cli.json, tsconfig*.json, package.json → build/runtime configuration
• Swagger PDFs + README mention /api → Swagger/OpenAPI is part of the runtime (likely configured in src/main.ts)
src/ (core runtime architecture)
• main.ts
• App bootstrap, global pipes/validation, Swagger setup, port binding.
• app.module.ts
• Nest module composition (providers/controllers).
• app.controller.ts
• Defines the REST endpoints. This is your API layer.
• app.service.ts
• Business logic: balances, top-ups, conversions, calling Alpha Vantage, and any “storage” logic present.
• src/dto/*.dto.ts
• Account.dto.ts, FxConversion.dto.ts represent request/response schema + validation boundaries.
Tests
• src/app.controller.spec.ts → unit tests around controller behavior
• test/app.e2e-spec.ts + test/jest-e2e.json → end-to-end tests that spin up the app
Key architecture pattern: classic NestJS layering:
Controller (transport) → Service (domain/application logic) → External API (Alpha Vantage) → (Optional persistence)
• “API Client(s)” (browser, mobile app, Postman, other service)
• “Forex Trading System API (NestJS)”
• “Alpha Vantage FX API” (external dependency)
• “Swagger UI (/api)” (optional: shown as part of API, or a separate “documentation endpoint”)
• Client → API: HTTPS REST calls
• API → Alpha Vantage: HTTPS requests for FX rates
• Client → Swagger UI: open docs endpoint
Notes to add
• Environment variable: ALPHA_VANTAGE_API_KEY used by the API when calling Alpha Vantage.
Even though this is a single service repo, you still want to separate “containers” conceptually:
Containers (inside your system boundary)
• NestJS Application (Node.js runtime)
• REST Controllers
• Services
• DTO validation layer
• Swagger/OpenAPI middleware
External containers
• Alpha Vantage API
Data store
Optional “Dev/CI” container
• “Jest test runner” calling the API in e2e tests (useful for engineering audiences).
This is where you map the repo structure directly.
Inside “NestJS Application” container
• AppModule (src/app.module.ts)
• Wires Controller + Service
• AppController (src/app.controller.ts)
• Endpoints:
• GET /fx-rates
• POST /top-up/:userId
• GET /balance/:userId
• POST /fx-conversion
• AppService (src/app.service.ts)
• Responsibilities to show as sub-components or bullet notes:
• Fetch live FX rate (Alpha Vantage integration)
• Perform conversion calculation
• Account balance update (top-up, debit)
• Store/retrieve latest rates + user balances (in-memory if applicable)
• DTOs (src/dto/Account.dto.ts, src/dto/FxConversion.dto.ts)
• Validation boundary (request payload shaping)
External dependency
• Alpha Vantage API
• Controller → Service (method calls)
• Service → Alpha Vantage (HTTP)
• Controller ↔ DTOs (validation/serialization)
• Service ↔ Store/DB (read/write)
Client sends conversion request (FxConversion.dto)
2. Service retrieves rate (from Store or Alpha Vantage), checks balance, debits/credits, persists transaction (if any)
Technologies/frameworks to explicitly label
Labels to prevent ambiguity:
• NestJS (Controllers/Providers/Modules)
• Node.js runtime
• TypeScript (build to dist/)
• Swagger/OpenAPI at /api (from main.ts)
• Jest (unit + e2e)
• Alpha Vantage (external HTTP API; requires API key)
• Client(s) → Forex Trading System API → Alpha Vantage
• Swagger UI endpoint shown
• Node/NestJS app container
• In-memory store (or planned DB)
• Alpha Vantage external
• main.ts (bootstrap + Swagger + global validation)
• AppModule (wiring)
• AppController (endpoint list)
• AppService (rate fetch, conversion, balances)
• DTOs (validation boundary)
• External Alpha Vantage API
• Client → Controller → Service → (Store + Alpha Vantage) → Service → Controller → Client
This set will be both accurate to the repo and detailed enough for a principal-level architecture review.