Executive Summary
The Learnille Server (server/) is an enterprise-grade NestJS RESTful API backend engineered for multi-tenant online learning, 1-on-1 expert consultations, real-time presence, wallet payouts, and multi-currency transaction processing.
🏛 1. High-Level Server System Diagram
🛠 2. Request Handling Pipeline & Lifecycle
When an HTTP request enters the NestJS server, it passes through a deterministic processing chain:📦 3. Deep Domain Module Architecture
3.1. Authentication & Security Subsystem (auth/, casl/, crypto/)
- Token Architecture: RS256 asymmetric key pairs (
CryptoModule). Short-lived JWT access tokens + Redis-rotated refresh tokens. - Social Login: OAuth flow handling for Google (
google/) and Apple (auth/). Account linking endpoints permit attaching social credentials to an existing user account. - CASL Role Permissions: Fine-grained access control supporting 4 primary roles (
Student,Instructor,Consultant,Admin).
3.2. Course Curriculum Engine (course/, category/)
- Normalized Curriculum: Supports hierarchical structure:
Course->Section->Subsection->Item(Video, Document, Quiz). - Progress Tracking: Continuous video timestamp tracking via heartbeat endpoints (
/course/video-progress) recalculating student completion percentage dynamically. - Category Hierarchy: Category tree mapping supporting parent-child categories, featured flags, and display order batch updating.
3.3. Consultation Booking & Availability (consultation/, consultant/)
- Dual Mode: Supports
ONEOFF(specific single date/time) andRECURRING(weekly interval windows) consultations. - Availability Engine: Calculates available time slots dynamically by cross-referencing consultant weekly hours, booked slot reservations, minimum notice buffers (e.g. 2 hours notice required), and timezone offsets.
- Reschedule Workflow: The owning consultant can prompt a student to reschedule a missed session. The student selects the replacement time and pays any applicable fee; the owning consultant or an admin approves. Repeat purchases create separate bookings. See Consultation rescheduling and rebooking.
3.4. Escrow, Wallet & Withdrawal System (wallet/, withdrawal/, payments/)
- Escrow Payment Hold: Funds from course sales or bookings enter
pending_holdin provider wallets, releasing toavailable_balanceupon course refund window expiry or consultation completion. - Dual Payment Gateways: Paystack and Flutterwave adapters with strict webhook signature verification (
x-paystack-signature, Flutterwave hash). - Multi-Step Withdrawal Flow:
- Add bank account method (
/withdrawals/methods). Bank account holder name is resolved via Flutterwave NGN lookup. - Verify account via SMS/email OTP (
/withdrawals/methods/verify). - Initiate withdrawal request (
/withdrawals/request). - Verify withdrawal with secondary OTP (
/withdrawals/:id/verify). - Admin approves and executes automated bank payout (
/withdrawals/:id/approve).
- Add bank account method (
3.5. Transactional Outbox & Background Processing (outbox/, bullmq/)
- Outbox Pattern: Changes to database entities write an outbox event in the same DB transaction (
outbox_events). - BullMQ Workers: BullMQ worker polls and processes outbox events asynchronously, handling external webhook dispatches, email triggers via Novu, and real-time Soketi broadcasts with automatic retries and dead-letter queues.
3.6. Search & Vector Engine (opensearch/)
- Catalog Indexing: Auto-indexes published courses and consultations into OpenSearch.
- Vector Search: Supports hybrid keyword search and semantic vector embeddings for recommendations and fast discovery.
🗄 4. Database & Persistence Standards
- Primary Database: PostgreSQL accessed via TypeORM.
- Naming Standard: All database columns use
snake_casetransformation (created_at,user_id,is_published). - Migrations: TypeORM migration scripts (
server/src/migrations/) maintain database schema changes. Direct schema alteration in production is strictly prohibited.
📊 5. Server Configuration & Observability
- Centralized Config:
ConfigModulevalidates all environment variables on boot viavalidateConfiginserver/src/config.ts. - Monitoring: Integrated with New Relic APM for transaction tracing, New Relic Log Enrichment for Winston logs, and Sentry for real-time exception reporting.
- Health Diagnostics:
HealthModulepowered by NestJS Terminus monitoring DB connection status, Redis availability, and host memory usage (/health).