Courses
Orchestrates the full course lifecycle—including creation, versioning, hierarchical organization, and content management—leveraging a robust, type-safe architecture for optimal performance.
🗂️ Structure
courses/
├── controllers/
│ ├── CourseController.ts # CRUD operations for courses
│ ├── CourseVersionController.ts # Manage version lifecycles (draft, publish, rollback)
│ ├── ModuleController.ts # CRUD operations for modules within a version
│ ├── SectionController.ts # CRUD and ordering for sections
│ └── ItemController.ts # CRUD, reordering, and retrieval of items
├── services/
│ ├── CourseService.ts # Core business logic for courses & versions
│ ├── ModuleService.ts # Module validation and hierarchy management
│ ├── SectionService.ts # Section ordering and batch updates
│ └── ItemService.ts # Item operations: create, read, update, delete, move
├── interfaces/
│ └── ICourseRepository.ts # Abstraction layer for course data access
├── validators/
│ ├── CourseValidators.ts # Validation DTOs for course and version APIs
│ ├── ModuleValidators.ts # Validation DTOs for module endpoints
│ ├── SectionValidators.ts # Validation DTOs for section endpoints
│ └── ItemValidators.ts # Validation DTOs for each item type
├── types.ts # Dependency injection tokens
└── container.ts # Binds controllers, services, and repositories
🎯 Core Components
Course
- CourseController: Endpoints to create, retrieve, update, and delete course records.
- CourseService: Enforces data integrity, unique constraints, and business rules.
- Versioning: Supports multiple course versions (e.g., draft, published) with isolated state.
Course Version
- CourseVersionController: Endpoints for version creation, publication, rollback, and cloning.
- CourseService: Executes deep cloning of module, section, and item hierarchies when creating new versions.
- Persistence: Stores version metadata (status, timestamps) alongside the hierarchical payload.
Module
- ModuleController: Manages modules within a specific course version.
- ModuleService: Validates module payloads, enforces unique ordering, and updates parent version timestamps.
- Structure: Modules serve as logical groupings for related sections.
Section
- SectionController: CRUD operations and reordering capabilities for sections.
- SectionService: Calculates sequence order, handles bulk repositioning, and updates timestamps.
- ItemsGroup: Each section references an
itemsGroupId
to decouple item collections.
Item
- ItemController: Routes for item creation, retrieval, updating, deletion, and reordering.
- ItemService:
- createItem: Validates parent hierarchy, persists type-specific data, augments version counts, and updates transactional state.
- readAllItems / readItem: Retrieves item references or full item details.
- updateItem: Ensures type consistency, applies content updates, and refreshes version metadata.
- deleteItem: Removes item records, adjusts version counters, and cleans up related progress data within a transaction.
- moveItem: Reorders items in a section using precise ordering algorithms (
calculateNewOrder
) and cascades timestamp updates.
📦 Supported Item Types
- VideoItem: Includes streaming URI, playback duration, caption metadata, and resume-position support.
- QuizItem: Integrates with the quiz module, providing question linking, validation rules, and immediate feedback.
- BlogItem: Comprises a title, summary, author metadata, tags, and a Markdown body that supports LaTeX math syntax ($…$ for inline, $$…$$ for display equations)..
🔁 Typical Workflow
- Course Creation:
CourseController
→CourseService
→ repository persistence. - Version Management: Clone or publish versions via
CourseVersionController
, preserving hierarchical snapshots. - Module & Section Updates: Add, reposition, or remove modules/sections with services ensuring order and timestamp integrity.
- Item Handling: Use
ItemController
to manage items—each operation is orchestrated within MongoDB transactions for consistency. - Hierarchy Retrieval: Aggregate-fetch full course-version-module-section-item tree for UI rendering.
- Rollback: Switch active version atomically to revert to prior content states.