# alexspx/courselab architecture

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

- Interactive diagram: https://gitdiagram.com/alexspx/courselab
- Repository: https://github.com/alexspx/courselab

## Overview

##### Project type and purpose
- CourseLab is a full-stack, online learning platform.
- Frontend is a Next.js/TypeScript app delivering SSR and CSR React pages.
- Backend is an Express/TypeScript API with real-time features via Socket.io.
- Core functionality: shared documents, video playback, quiz creation, attendance tracking.

##### File structure
- Top-level “client” folder: Next.js application
– src/pages: routing and SSR entry points
– src/components, modules, hooks, contexts: UI, state management, and re-usable logic
– public: static assets, localization JSON, service worker
– next.config.js, i18next, tailwind, Cypress config for E2E tests
- Top-level “server” folder: Express API and real-time layer
– src/api: REST endpoints (user, course, assignment, chatrooms, document, quiz, video)
– src/functions: business logic helpers (assignmentHelpers, quizHelpers, redisCaching, etc.)
– src/middlewares: auth, file-resize (multer)
– src/sockets: Socket.io setup and namespaces (chatRooms, documents, onlineUsers)
– prisma/schema.prisma: database schema (PostgreSQL or MySQL)
– Redis used for caching and Express-Session store

##### Extract insights from the README
- Tech stack: TypeScript, NextJs, Tailwind, ExpressJs, Socket.io, Prisma, Redis, Express Sessions
- Features: shared online documents, video player, quiz builder, attendance monitoring

##### Elements
- Clear labels (e.g., “Next.js Client”, “Express REST API”, “Prisma DB”)
– Blue rectangles for UI/Client components
– Green rectangles for backend services
– Rounded rectangles for cache/session (Redis)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["User Browser"]:::client
        NextJSApp["Next.js Client Application"]:::client
        SSR["SSR & Routing (Next.js Pages)"]:::client
        UIComp["UI Components (React)"]:::client
        Contexts["Client State & Contexts"]:::client
        Hooks["Custom React Hooks"]:::client
        APIHelpers["API Request Helpers"]:::client
        Configs["Tailwind & i18n Config"]:::client
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        ExpressAPI["Express REST API Endpoints"]:::backend
        BusinessLogic["Business Logic Functions"]:::backend
        AuthMW["Authentication Middleware"]:::backend
        FileMW["File Upload & Resize Middleware"]:::backend
        SocketSetup["Socket.io Setup (Core)"]:::backend
        ChatNS["Chat Rooms Namespace"]:::backend
        DocNS["Document Collaboration Namespace"]:::backend
        OnlineNS["Online Users Namespace"]:::backend
        DB["Prisma Database (PostgreSQL/MySQL)"]:::db
        Redis["Redis Cache & Session Store"]:::cache
        Storage["File Storage (Cloud/Local)"]:::external
        CDN["CDN for Static Assets"]:::external
    end

    %% Connections
    Browser -->|"HTTP/HTTPS"| NextJSApp
    NextJSApp -->|"Internal HTTP"| ExpressAPI
    Browser -->|"WebSocket (WS)"| SocketSetup
    ExpressAPI -->|"uses"| BusinessLogic
    ExpressAPI -->|"auth via"| AuthMW
    ExpressAPI -->|"file uploads"| FileMW
    ExpressAPI -->|"ORM calls"| DB
    ExpressAPI -->|"cache/session"| Redis
    ExpressAPI -->|"store files"| Storage
    NextJSApp --> SSR
    NextJSApp --> UIComp
    NextJSApp --> Contexts
    NextJSApp --> Hooks
    NextJSApp --> APIHelpers
    NextJSApp --> Configs
    SocketSetup --> ChatNS
    SocketSetup --> DocNS
    SocketSetup --> OnlineNS
    CDN --> NextJSApp

    %% Click Events - Frontend
    click NextJSApp "https://github.com/alexspx/courselab/tree/master/client/"
    click SSR "https://github.com/alexspx/courselab/tree/master/client/src/pages/"
    click UIComp "https://github.com/alexspx/courselab/tree/master/client/src/components/"
    click Contexts "https://github.com/alexspx/courselab/tree/master/client/src/contexts/"
    click Hooks "https://github.com/alexspx/courselab/tree/master/client/src/Hooks/"
    click APIHelpers "https://github.com/alexspx/courselab/blob/master/client/src/lib/fetcher.ts"
    click APIHelpers "https://github.com/alexspx/courselab/blob/master/client/src/lib/useRequest.tsx"
    click Configs "https://github.com/alexspx/courselab/blob/master/client/tailwind.config.js"
    click Configs "https://github.com/alexspx/courselab/blob/master/client/next-i18next.config.js"

    %% Click Events - Backend
    click ExpressAPI "https://github.com/alexspx/courselab/tree/master/server/src/api/"
    click BusinessLogic "https://github.com/alexspx/courselab/tree/master/server/src/functions/"
    click AuthMW "https://github.com/alexspx/courselab/blob/master/server/src/middlewares/auth.ts"
    click FileMW "https://github.com/alexspx/courselab/blob/master/server/src/settings/multer.ts"
    click FileMW "https://github.com/alexspx/courselab/blob/master/server/src/middlewares/resizeMiddleware.ts"
    click SocketSetup "https://github.com/alexspx/courselab/blob/master/server/src/sockets/setup.ts"
    click ChatNS "https://github.com/alexspx/courselab/blob/master/server/src/sockets/chatRoomsSetup.ts"
    click DocNS "https://github.com/alexspx/courselab/blob/master/server/src/sockets/documentsSetup.ts"
    click OnlineNS "https://github.com/alexspx/courselab/blob/master/server/src/sockets/onlineUsers.ts"
    click DB "https://github.com/alexspx/courselab/blob/master/server/prisma/schema.prisma"
    click Redis "https://github.com/alexspx/courselab/blob/master/server/src/functions/redisCaching.ts"
    click BusinessLogic "https://github.com/alexspx/courselab/blob/master/server/src/functions/online.ts"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#006064;
    classDef backend fill:#E8F5E9,stroke:#1B5E20;
    classDef db fill:#FFF9C4,stroke:#F57F17;
    classDef cache fill:#FFF3E0,stroke:#E65100;
    classDef external fill:#CFD8DC,stroke:#455A64;
```
