# guillermoscript/lms architecture

> Architecture diagram of the GitHub repository guillermoscript/lms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/guillermoscript/lms
- Repository: https://github.com/guillermoscript/lms

## Overview

##### Project type and purpose
- This is a backend‐focused, full LMS application built on Payload CMS (Node.js + TypeScript) with an auto-generated admin UI and REST/GraphQL APIs for end users.
- Its main features include course/lesson management, subscriptions and orders, payments, evaluations, reviews, notifications, and scheduled tasks (cron jobs).

##### File structure
- Top-level files: Dockerfile, docker-compose.yml, .env, Travis CI config, Postman collections—indicate containerization, CI, and API testing.
- src/server.ts: Application entry point (Express + Payload).
- src/collections: Domain models (Courses, Lessons, Users, Orders, Subscriptions, etc.). Each “collection” maps to a MongoDB collection with hooks (e.g., send email, enforce roles).
- src/access: Access control rules (isAdmin, isLoggedIn, isEnrolledOrHasAccess, etc.).
- src/services: Business logic modules (openAi integration, scoring, email notifications).
- src/lib/cron.ts: Schedules daily checks on subscriptions.
- src/templates: Email templates for notifications.
- src/seed: Data-seeding scripts for initial data.

##### README for additional insights
- Confirms tech stack: Node.js 14.x, Yarn 1.x, MongoDB 4.x, Docker support.
- Lists core features and flows (course creation/enrollment, subscription lifecycle, payment flow, evaluations).
- Mentions ext. env vars: MONGODB_URI, PAYLOAD_SECRET, PAYLOAD_CONFIG_PATH.

##### Main components and relationships
a. User Interfaces
- Admin UI (served by Payload CMS) for managing courses, plans, products, etc.
- End-user Web UI or mobile client (consumes REST/GraphQL APIs).
b. Backend Application
- Node.js + Express + Payload CMS
- Authentication & Authorization (passport, src/access rules)
- Business logic services (src/services)
- Cron scheduler (src/lib/cron.ts)
c. Data Storage
- MongoDB (collections correspond to payload collections)
d. External Services
- Payment gateways (Zelle, Pago Móvil, generic payment methods)
- Email service (SMTP or 3rd-party) for notifications
- OpenAI API (for any AI-driven features)

##### Architectural patterns and design principles
- Payload CMS enforces a form of MVC: Collections = models, hooks = controllers, admin UI = views.
- Separation of concerns: access control in src/access, domain logic in src/services, data models in src/collections, scheduling in src/lib/cron.
- Event-driven hooks trigger side effects (email notifications, order post-processing).
- Containerization via Docker for consistent environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        AdminUI["Admin UI (Payload CMS)"]:::client
        EndUserUI["End-User UI (Web/Mobile)"]:::client
    end

    subgraph "API Layer"
        Server["Node.js Server\nExpress + Payload CMS"]:::internal
        Config["payload.config.ts"]:::internal
        Types["payload-types.ts"]:::internal
        subgraph "Collections"
            Collections["Domain Models\n(src/collections/)"]:::internal
            Hooks["Collection Hooks\n(src/collections/**/hooks/)"]:::internal
        end
        subgraph "Access Control"
            Access["Access Rules\n(src/access/)"]:::internal
        end
        subgraph "Business Services"
            Services["Business Logic\n(src/services/)"]:::internal
        end
        HooksGlobal["Global Hooks\n(src/hooks/)"]:::internal
        Auth["Auth Utilities\n(src/utilities/passport.ts)"]:::internal
        Utils["Misc Utilities\n(src/utilities/)"]:::internal
        Templates["Email Templates\n(src/templates/)"]:::internal
    end

    subgraph "Data Layer"
        Mongo["MongoDB"]:::internal
    end

    subgraph "Scheduler"
        Cron["Cron Scheduler\n(src/lib/cron.ts)"]:::internal
    end

    subgraph "External Services"
        Payment["Payment Gateways\n(src/globals/)"]:::external
        EmailService["Email Service"]:::external
        OpenAI["OpenAI API"]:::external
    end

    AdminUI -->|"HTTP (REST/GraphQL)"| Server
    EndUserUI -->|"HTTP (REST/GraphQL)"| Server

    Server --> Config
    Server --> Types
    Server --> Collections
    Server --> Hooks
    Server --> Access
    Server --> Services
    Server --> HooksGlobal
    Server --> Auth
    Server --> Utils
    Server --> Templates
    Server -->|"DB Read/Write"| Mongo
    Server -->|"Payment Process"| Payment
    Server -->|"Send Emails"| EmailService
    Server -->|"AI Calls"| OpenAI

    Cron -.->|"scheduled jobs"| Server
    Cron -.-> Mongo

    classDef client fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef internal fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef external fill:#ffe5cc,stroke:#333,stroke-width:1px

    click Server "https://github.com/guillermoscript/lms/blob/master/src/server.ts"
    click Config "https://github.com/guillermoscript/lms/blob/master/src/payload.config.ts"
    click Types "https://github.com/guillermoscript/lms/blob/master/src/payload-types.ts"
    click Collections "https://github.com/guillermoscript/lms/tree/master/src/collections/"
    click Hooks "https://github.com/guillermoscript/lms/tree/master/src/collections/**/hooks/"
    click Access "https://github.com/guillermoscript/lms/tree/master/src/access/"
    click Services "https://github.com/guillermoscript/lms/tree/master/src/services/"
    click HooksGlobal "https://github.com/guillermoscript/lms/tree/master/src/hooks/"
    click Auth "https://github.com/guillermoscript/lms/blob/master/src/utilities/passport.ts"
    click Utils "https://github.com/guillermoscript/lms/tree/master/src/utilities/"
    click Templates "https://github.com/guillermoscript/lms/tree/master/src/templates/"
    click Cron "https://github.com/guillermoscript/lms/blob/master/src/lib/cron.ts"
    click Payment "https://github.com/guillermoscript/lms/tree/master/src/globals/"
```
