How tronghghe172557/ecommerce_backend_typescript works
Project Type and Purpose
• This is a monolithic TypeScript-based backend for an e‑commerce application.
• It exposes RESTful endpoints (see /src/modules/*/router and docs/openapi.yml).
• Core features: user/shop authentication, product management, cart, discounts, inventory, checkout.
File Structure
• Top‑level “Ecommerce_Backend” directory contains:
• src/server.ts (entry point)
• src/base (common infrastructure: routing, error handling, logging, DB & Redis helpers, Swagger setup)
• src/modules (domain modules: auth, products, cart, discount, inventory, checkouts)
• docs/openapi.yml & docs/api (API specs & test scripts)
• package.json, .env, tsconfig.json, and build/test config files show a standard Node/TS toolchain.
• Logging lives under logs/, environment variables via .env.example, nodemon.json for dev.
Key Architectural Insights from the README
• Layered architecture: routers → controllers → services → models → database/Redis.
• Uses Bruno for API testing, Swagger/OpenAPI for documentation.
• Emphasis on DTOs for input/output validation, custom exceptions for error handling.
Main Components & Their Relationships
a. API Gateway / HTTP Server
• Express (or similar) listening on port (src/server.ts).
• Central router (src/base/router/app.router.ts) composes module routers.
b. Routing Layer
• Module-specific routers forward to controllers.
c. Controller Layer
• Orchestrates request → calls Service → returns response/throws exceptions.
d. Service Layer
• Business logic, orchestrates Models & external calls.
e. Model Layer & Data Layer
• ORM/ODM models under src/modules/*/models.
• Database connection via src/base/database.
• Redis cache layer via src/base/redis.
f. Cross‑Cutting Infrastructure
• Common utilities (logger, env, error handlers) under src/base/common.
• Swagger initialization under src/base/swagger.
g. External Systems
• Relational/NoSQL database (configure .env for host, credentials).
• Redis for caching/session.
• Bruno CLI for testing (external tool but not in production path).
Architectural Patterns & Principles
• Layered (hexagonal-like) separation: presentation (router/controller) → domain (service/model) → infrastructure (DB/Redis).
• DTOs and centralized exception handling enforce consistency.
• Modular design: each domain (auth, products, cart, etc.) encapsulates its own controllers, services, models.
• Single monolith deployable as one container/process.
• Use clear, consistent labels (e.g., “ProductController”, “CartService”).
• Major protocols (HTTP/REST, Redis protocol, SQL/NoSQL).