How kgesh/lms-backend works
Main Architectural Layers
• Frontline API Layer (Controllers):
– All the v1 directories (e.g., v1/auth, v1/course, v1/ebook, v1/order, etc.) hold the controllers that expose HTTP endpoints.
• Business Logic / Service Layer:
– Each domain module has associated service files handling domain-specific business logic.
– Additional core services (e.g., app.service.ts, auth.service.ts, promotion service, etc.) are located in both src and domain-specific directories.
• Data Access / Repository Layer:
– Every module has its own repository files (e.g., course.repository.ts, coupon.repository.ts, etc.) indicating a repository pattern.
– The infra/db folder includes Drizzle ORM modules, helpers, and schema definitions.
• Infrastructure & Integration:
– The “infra” directory contains integrations for databases, HTTP client, payment (including Portone API), S3 storage, and SMS providers.
– Included also are configuration and helper modules found in src/configs and src/shared (helpers, types, utils).
• Core Components and Cross‑Cutting Concerns:
– The src/core directory holds base repository classes, decorators, guards, middlewares (such as logger and API guards) and error handling.
Representing Components and Their Interactions
– API Gateway / Controllers (group by domain e.g., Auth, Course, Ebook, Order, etc.)
– Business Logic / Service Layer (each module’s services)
– Data Access / Repositories (group all repository modules including Drizzle ORM integration)
– Infrastructure Services (database connections, S3 client, Payment service, SMS provider, HTTP client)
– Shared/Common Utilities (configs, shared/helpers, core decorators and guards)
– Controllers call Services.
– Services interact with Repositories for data access.
– Repositories call the Database (visualized as the DB server component) via Drizzle ORM.
– Infrastructure components (e.g., Payment, S3, SMS) are invoked by the services when needed.
– Configuration modules and shared utilities are used across each layer.
Architectural Patterns & Design Principles
• Modular Structure (each v1 domain is self-contained, with its own controller, service, repository, and sometimes additional sub‑modules).
• Separation of Concerns – different folders (e.g., core, infra, shared, configs) indicate strong layering.
• Dependency Injection – evidenced by Nest’s provider setup.
• Use of External Integrations – clearly called out in infra (HTTP client, S3, payment, SMS) suggesting communication with external systems.
• Testing/Quality Assurance – the existence of a dedicated “test” directory with end-to-end tests supports a test‑driven design.
Elements
– Domain Modules (v1/auth, v1/course, v1/ebook, etc.)
– Core services (application bootstrap, middleware, logging, error handling)
– Repository/Database Access Layer (Drizzle ORM integration)
– Infrastructure modules (database connection pool, HTTP client, payment service, S3 client, SMS provider)
– External Services (e.g., external payment API, S3 storage service, external HTTP endpoints)
– Indicate that controllers forward incoming requests to services.
– Show that services query repositories and call integration modules.
• Annotations/Legends that describe:
– What each module is responsible for (e.g., “Handles user authentication and session management” in the auth module).
Putting It All Together
• Inside, create sub‑sections for different layers:
– Presentation Layer (controllers from v1/*),
– Business Layer (services),
– Data Layer (repositories and ORM integration),
– Infrastructure & Integrations (infra/* modules).
• That all modules (auth, course, ebook, coupon, review, teacher, term, etc.) are represented either as individual blocks or as grouped components if there are common patterns.