# lathiya50/learning-management-system architecture

> Architecture diagram of the GitHub repository lathiya50/learning-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lathiya50/learning-management-system
- Repository: https://github.com/lathiya50/learning-management-system

## Overview

##### Project type and purpose
- This is a full-stack Learning Management System (LMS) named “E-learning” built with Next.js (frontend) and Node.js/Express (backend).
- Its purpose is to enable course creation, user management, enrollment, real-time notifications, analytics, and administration.

##### File structure
A. Frontend (client/)
- Next.js v13 app directory (app/) for routing and UI pages
- pages/api/ for serverless endpoints (NextAuth)
- Redux Toolkit under client/redux/features for global state (auth, courses, analytics, etc.)
- TailwindCSS + CSS modules for styling
- Socket.io-client for real-time updates
- Utility hooks (useProtected, adminProtected) and components organized by feature (Auth, Admin, Course, Profile, etc.)
B. Backend
- server.ts: Bootstrap Express server and attach Socket.io
- socketServer.ts: Stand-alone WebSocket setup
- routes/*.route.ts → controllers/*.controller.ts → services/*.service.ts → models/*.model.ts
- Middleware (auth, error handlers)
- util/db.ts & util/redis.ts: MongoDB and Redis connections
- mails/*.ejs & utils/sendMail.ts for email templates
- payment, OAuth, JWT, and Cloudinary integrations

##### README insights
- Tech Stack: Next.js, Redux, Tailwind, Node.js, Express, MongoDB, Redis, Socket.io, Cloudinary, JWT, OAuth
- Features: Authentication, Course Management, Analytics, Real-time Notifications, Payment Processing

##### Detail
- Architectural elements: API layer, WebSocket server, caching, external integrations
- Don’t over-modularize: group by logical layer rather than every single file

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        FE["User Browser"]:::frontend
        APP["Next.js App"]:::frontend
        AUTH_ROUTE["NextAuth API Route"]:::api
        STORE["Redux Store"]:::frontend
        subgraph "State Slices & APIs"
            direction TB
            AUTH_SLICE["Auth Slice"]:::frontend
            AUTH_API["Auth API"]:::frontend
            COURSES_API["Courses API"]:::frontend
            ANALYTICS_API["Analytics API"]:::frontend
            NOTIF_API["Notifications API"]:::frontend
            ORDERS_API["Orders API"]:::frontend
            USER_API["User API"]:::frontend
        end
        CHECKOUT["Checkout Form"]:::frontend
        HOOK1["useProtected Hook"]:::frontend
        HOOK2["adminProtected Hook"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        SERVER["Express Server"]:::backend
        SOCKET_SERVER["WebSocket Server"]:::backend

        subgraph "Routes"
            direction TB
            R_COURSE["Course Route"]:::backend
            R_USER["User Route"]:::backend
            R_ORDER["Order Route"]:::backend
            R_NOTIF["Notification Route"]:::backend
            R_ANALYTICS["Analytics Route"]:::backend
            R_LAYOUT["Layout Route"]:::backend
        end

        subgraph "Controllers"
            direction TB
            C_COURSE["Course Controller"]:::backend
            C_USER["User Controller"]:::backend
            C_ORDER["Order Controller"]:::backend
            C_NOTIF["Notification Controller"]:::backend
            C_ANALYTICS["Analytics Controller"]:::backend
            C_LAYOUT["Layout Controller"]:::backend
        end

        subgraph "Services"
            direction TB
            S_COURSE["Course Service"]:::backend
            S_USER["User Service"]:::backend
            S_ORDER["Order Service"]:::backend
        end

        subgraph "Models"
            direction TB
            M_COURSE["Course Model"]:::backend
            M_USER["User Model"]:::backend
            M_ORDER["Order Model"]:::backend
            M_NOTIF["Notification Model"]:::backend
            M_LAYOUT["Layout Model"]:::backend
        end

        subgraph "Middleware"
            direction TB
            MW_AUTH["Auth Middleware"]:::backend
            MW_ERR["Error Handlers"]:::backend
        end

        subgraph "Utilities"
            direction TB
            U_DBUTIL["MongoDB Util"]:::backend
            U_REDIS["Redis Util"]:::backend
            U_SENDMAIL["Email Utility"]:::backend
            U_JWT["JWT Utility"]:::backend
            U_ANALYTICS["Analytics Gen Utility"]:::backend
            U_ERRORH["Global ErrorHandler"]:::backend
        end
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        MONGODB["MongoDB"]:::db
        REDIS["Redis"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        CLOUDINARY["Cloudinary"]:::external
        EMAIL["Email Service"]:::external
        PAYMENT["Payment Gateway"]:::external
        OAUTH["OAuth Providers"]:::external
    end

    %% Connections
    FE -->|"HTTP/SSR & JS"| APP
    APP -->|"REST API"| SERVER
    APP <-->|"WebSocket"| SOCKET_SERVER
    APP -->|"<oauth flow>"| AUTH_ROUTE
    STORE -->|">dispatch()/fetch"| AUTH_API
    STORE -->|"fetch"| COURSES_API
    STORE -->|"fetch"| ANALYTICS_API
    STORE -->|"fetch"| NOTIF_API
    STORE -->|"fetch"| ORDERS_API
    STORE -->|"fetch"| USER_API
    SERVER --> R_COURSE
    SERVER --> R_USER
    SERVER --> R_ORDER
    SERVER --> R_NOTIF
    SERVER --> R_ANALYTICS
    SERVER --> R_LAYOUT
    R_COURSE --> C_COURSE
    R_USER --> C_USER
    R_ORDER --> C_ORDER
    R_NOTIF --> C_NOTIF
    R_ANALYTICS --> C_ANALYTICS
    R_LAYOUT --> C_LAYOUT
    C_COURSE --> S_COURSE
    C_USER --> S_USER
    C_ORDER --> S_ORDER
    S_COURSE --> M_COURSE
    S_USER --> M_USER
    S_ORDER --> M_ORDER
    S_USER --> M_NOTIF
    S_USER --> M_LAYOUT
    SERVER --> U_DBUTIL
    SERVER --> U_REDIS
    SOCKET_SERVER --> U_REDIS
    SERVER --> CLOUDINARY
    SERVER --> EMAIL
    SERVER --> PAYMENT
    AUTH_ROUTE --> OAUTH
    SERVER --> U_SENDMAIL
    SERVER --> U_JWT
    SERVER --> U_ANALYTICS
    SERVER --> U_ERRORH
    SERVER --> MW_AUTH
    SERVER --> MW_ERR
    SERVER --> SOCKET_SERVER
    SERVER --> MONGODB
    SERVER --> REDIS

    %% Click Events
    click APP "https://github.com/lathiya50/learning-management-system/tree/master/client/app"
    click AUTH_ROUTE "https://github.com/lathiya50/learning-management-system/blob/master/client/pages/api/auth/[...nextauth].ts"
    click STORE "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/store.ts"
    click AUTH_SLICE "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/auth/authSlice.ts"
    click AUTH_API "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/auth/authApi.ts"
    click COURSES_API "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/courses/coursesApi.ts"
    click ANALYTICS_API "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/analytics/analyticsApi.ts"
    click NOTIF_API "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/notifications/notificationsApi.ts"
    click ORDERS_API "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/orders/ordersApi.ts"
    click USER_API "https://github.com/lathiya50/learning-management-system/blob/master/client/redux/features/user/userApi.ts"
    click CHECKOUT "https://github.com/lathiya50/learning-management-system/blob/master/client/app/components/Payment/CheckOutForm.tsx"
    click HOOK1 "https://github.com/lathiya50/learning-management-system/blob/master/client/app/hooks/useProtected.tsx"
    click HOOK2 "https://github.com/lathiya50/learning-management-system/blob/master/client/app/hooks/adminProtected.tsx"
    click SERVER "https://github.com/lathiya50/learning-management-system/blob/master/server.ts"
    click SOCKET_SERVER "https://github.com/lathiya50/learning-management-system/blob/master/socketServer.ts"
    click R_COURSE "https://github.com/lathiya50/learning-management-system/blob/master/routes/course.route.ts"
    click R_USER "https://github.com/lathiya50/learning-management-system/blob/master/routes/user.route.ts"
    click R_ORDER "https://github.com/lathiya50/learning-management-system/blob/master/routes/order.route.ts"
    click R_NOTIF "https://github.com/lathiya50/learning-management-system/blob/master/routes/notification.route.ts"
    click R_ANALYTICS "https://github.com/lathiya50/learning-management-system/blob/master/routes/analytics.route.ts"
    click R_LAYOUT "https://github.com/lathiya50/learning-management-system/blob/master/routes/layout.route.ts"
    click C_COURSE "https://github.com/lathiya50/learning-management-system/blob/master/controllers/course.controller.ts"
    click C_USER "https://github.com/lathiya50/learning-management-system/blob/master/controllers/user.controller.ts"
    click C_ORDER "https://github.com/lathiya50/learning-management-system/blob/master/controllers/order.controller.ts"
    click C_NOTIF "https://github.com/lathiya50/learning-management-system/blob/master/controllers/notification.controller.ts"
    click C_ANALYTICS "https://github.com/lathiya50/learning-management-system/blob/master/controllers/analytics.controller.ts"
    click C_LAYOUT "https://github.com/lathiya50/learning-management-system/blob/master/controllers/layout.controller.ts"
    click S_COURSE "https://github.com/lathiya50/learning-management-system/blob/master/services/course.service.ts"
    click S_USER "https://github.com/lathiya50/learning-management-system/blob/master/services/user.service.ts"
    click S_ORDER "https://github.com/lathiya50/learning-management-system/blob/master/services/order.service.ts"
    click M_COURSE "https://github.com/lathiya50/learning-management-system/blob/master/models/course.model.ts"
    click M_USER "https://github.com/lathiya50/learning-management-system/blob/master/models/user.model.ts"
    click M_ORDER "https://github.com/lathiya50/learning-management-system/blob/master/models/order.Model.ts"
    click M_NOTIF "https://github.com/lathiya50/learning-management-system/blob/master/models/notification.Model.ts"
    click M_LAYOUT "https://github.com/lathiya50/learning-management-system/blob/master/models/layout.model.ts"
    click MW_AUTH "https://github.com/lathiya50/learning-management-system/blob/master/middleware/auth.ts"
    click MW_ERR "https://github.com/lathiya50/learning-management-system/blob/master/middleware/error.ts"
    click U_DBUTIL "https://github.com/lathiya50/learning-management-system/blob/master/util/db.ts"
    click U_REDIS "https://github.com/lathiya50/learning-management-system/blob/master/util/redis.ts"
    click U_SENDMAIL "https://github.com/lathiya50/learning-management-system/blob/master/utils/sendMail.ts"
    click U_JWT "https://github.com/lathiya50/learning-management-system/blob/master/utils/jwt.ts"
    click U_ANALYTICS "https://github.com/lathiya50/learning-management-system/blob/master/utils/analytics.generator.ts"
    click U_ERRORH "https://github.com/lathiya50/learning-management-system/blob/master/utils/ErrorHandler.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef db fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef api fill:#b8daff,stroke:#004085,color:#004085;
```
