# whiteshadow1234/e-course architecture

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

- Interactive diagram: https://gitdiagram.com/whiteshadow1234/e-course
- Repository: https://github.com/whiteshadow1234/e-course

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express.js, React, Node.js) web application for managing course enrollment with both user and admin functionality.
- Key features (from README): secure authentication, dynamic course management, interactive weekly schedule, admin controls, type-safe backend, Dockerized deployment.

##### File structure
- Top-level:
- client/ – React front-end (TypeScript, Jest tests, service layer)
- server/ – Express.js back-end (TypeScript, Mongoose models, Jest tests)
- docker-compose.yml, Dockerfile – container orchestration and builds
- .github/workflows/ci-cd.yml – CI/CD pipeline definition
- client/src/service contains authService & courseService indicating a clear API service layer.
- server/src/models and server/src/routes follow an MVC-like pattern.
- The presence of .env.example in both client & server implies environment-based configuration.

##### Inspect the README for architectural insights
- The tech stack badges confirm React ≥18, Node.js ≥20, Express ≥4.21, MongoDB ≥6.0, Docker.
- Docker Compose is the recommended deployment mechanism.
- CI/CD via GitHub Actions builds and tests both client and server.

##### Main components and their interactions
a. Frontend (React SPA)
- Hosts UI: Login, Registration, Schedule Calendar, Course Management
- Communicates over HTTPS/REST to the backend API
b. Backend API (Node.js + Express)
- Exposes auth routes (/login, /register) and course routes (/courses, /enroll)
- Implements business logic, validation, JWT auth, uses Mongoose to talk to MongoDB
c. Database (MongoDB)
- Stores User and Course documents
d. DevOps/Infrastructure
- Docker containers for client, server, and MongoDB (via docker-compose)
- CI/CD service (GitHub Actions) runs tests and builds images
e. External services (optional)
- Hosted database if not running locally
- Container registry (Docker Hub or similar)
- Render.com or other hosting for live demo

##### Architectural patterns and design principles
- Separation of concerns: UI layer ↔ API layer ↔ Persistence layer
- MVC-style in server: Models (User, Course), Controllers (routes), Services (business logic)
- Service layer in client abstracts API calls into authService & courseService
- Environment-based configuration via .env files
- Containerization to isolate dependencies and simplify deployment

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors
    UserActor["User (Browser)"]:::actor

    %% Frontend Container
    subgraph "Frontend Container (React)" 
        direction TB
        ReactSrc["client/src"]:::frontend
        ReactIndex["index.tsx"]:::frontend
        AppComponent["App.tsx"]:::frontend
        subgraph "Components"
            direction TB
            Login["Login.tsx"]:::frontend
            Register["Register.tsx"]:::frontend
            Calendar["Calendar.tsx"]:::frontend
            ProtectedRoute["ProtectedRoute.tsx"]:::frontend
        end
        subgraph "Service Layer"
            direction TB
            AuthService["authService.ts"]:::frontend
            CourseService["courseService.ts"]:::frontend
        end
        FrontendTests["__tests__"]:::frontend
        EnvClient[".env.example"]:::infra
        DockerIgnoreClient[".dockerignore"]:::infra
    end

    %% Backend Container
    subgraph "Backend Container (Express)" 
        direction TB
        BackendAPI["server/src"]:::backend
        ServerIndex["index.ts"]:::backend
        AuthRoutes["auth.ts"]:::backend
        CourseRoutes["course.ts"]:::backend
        subgraph "Models"
            direction TB
            UserModel["User.ts"]:::backend
            CourseModel["Course.ts"]:::backend
        end
        BackendTests["__tests__"]:::backend
        EnvServer[".env.example"]:::infra
        DockerIgnoreServer[".dockerignore"]:::infra
    end

    %% Database
    MongoDB["MongoDB ≥6.0\nUser & Course collections"]:::database

    %% DevOps/Infrastructure
    subgraph "DevOps & Deployment"
        direction TB
        DockerfileNode["Dockerfile"]:::infra
        DockerCompose["docker-compose.yml"]:::infra
        CICD["GitHub Actions CI/CD\n(test → build → push)"]:::infra
    end

    %% Data Flows
    UserActor -->|"UI Interaction\nHTTPS Requests"| ReactSrc
    ReactSrc -->|"REST API calls\n(JSON)"| ServerIndex
    ServerIndex -->|"Mongoose Queries"| MongoDB
    CICD -->|"build & push images"| DockerCompose
    DockerCompose -->|"orchestrates containers"| ReactSrc
    DockerCompose --> ReactSrc
    DockerCompose --> BackendAPI
    DockerCompose --> MongoDB

    %% Click Events
    click ReactSrc "https://github.com/whiteshadow1234/e-course/tree/main/client/src"
    click ReactIndex "https://github.com/whiteshadow1234/e-course/blob/main/client/src/index.tsx"
    click AppComponent "https://github.com/whiteshadow1234/e-course/blob/main/client/src/App.tsx"
    click Login "https://github.com/whiteshadow1234/e-course/blob/main/client/src/components/Login.tsx"
    click Register "https://github.com/whiteshadow1234/e-course/blob/main/client/src/components/Register.tsx"
    click Calendar "https://github.com/whiteshadow1234/e-course/blob/main/client/src/components/Calendar.tsx"
    click ProtectedRoute "https://github.com/whiteshadow1234/e-course/blob/main/client/src/components/ProtectedRoute.tsx"
    click AuthService "https://github.com/whiteshadow1234/e-course/blob/main/client/src/service/authService.ts"
    click CourseService "https://github.com/whiteshadow1234/e-course/blob/main/client/src/service/courseService.ts"
    click FrontendTests "https://github.com/whiteshadow1234/e-course/tree/main/client/src/__tests__"
    click EnvClient "https://github.com/whiteshadow1234/e-course/blob/main/client/.env.example"
    click DockerIgnoreClient "https://github.com/whiteshadow1234/e-course/blob/main/client/.dockerignore"
    click BackendAPI "https://github.com/whiteshadow1234/e-course/tree/main/server/src"
    click ServerIndex "https://github.com/whiteshadow1234/e-course/blob/main/server/src/index.ts"
    click AuthRoutes "https://github.com/whiteshadow1234/e-course/blob/main/server/src/routes/auth.ts"
    click CourseRoutes "https://github.com/whiteshadow1234/e-course/blob/main/server/src/routes/course.ts"
    click UserModel "https://github.com/whiteshadow1234/e-course/blob/main/server/src/models/User.ts"
    click CourseModel "https://github.com/whiteshadow1234/e-course/blob/main/server/src/models/Course.ts"
    click BackendTests "https://github.com/whiteshadow1234/e-course/tree/main/server/src/__tests__"
    click EnvServer "https://github.com/whiteshadow1234/e-course/blob/main/server/.env.example"
    click DockerIgnoreServer "https://github.com/whiteshadow1234/e-course/blob/main/server/.dockerignore"
    click DockerfileNode "https://github.com/whiteshadow1234/e-course/tree/main/Dockerfile"
    click DockerCompose "https://github.com/whiteshadow1234/e-course/blob/main/docker-compose.yml"
    click CICD "https://github.com/whiteshadow1234/e-course/blob/main/.github/workflows/ci-cd.yml"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#E6FFEA,stroke:#28A745,color:#28A745
    classDef database fill:#FFE8B3,stroke:#C18E00,color:#C18E00,shape:cylinder
    classDef infra fill:#F0F0F0,stroke:#6A737D,color:#6A737D
    classDef actor fill:#FFFFFF,stroke:#000000,color:#000000,nodeShape:actor
```
