# dharamshiyash/calmspace architecture

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

- Interactive diagram: https://gitdiagram.com/dharamshiyash/calmspace
- Repository: https://github.com/dharamshiyash/calmspace

## Overview

##### Project type and purpose
- This is a MERN-stack web application (“PBL”) with a React frontend and a Node.js/Express backend using MongoDB for data storage.
- Purpose: user authentication flow (register, login, verify OTP) with API endpoints secured by JWT.

##### File structure
- Top level: two main folders “frontend” and “backend.”
- Backend folder:
- config/db.js – MongoDB connection setup
- controllers/authController.js – business logic for registration, login, OTP
- middleware/authMiddleware.js – JWT verification for protected routes
- models/User.js – Mongoose schema for user data
- routes/authRoutes.js – Express routes for auth endpoints
- server.js – Express app initialization and route mounting
- utils/generateOTP.js – helper for one-time codes
- Frontend folder:
- public – static HTML, manifest, etc.
- src
– api.js – Axios or fetch wrapper pointing to backend
– pages/* – React components for Landing, Home, Login, Register, Verify OTP
– App.js – router setup and context
– index.js – React DOM bootstrap

##### README for additional insights
- Confirms use of environment variables (PORT, MONGO_URI, JWT_SECRET, REACT_APP_API_BASE_URL)
- Describes dev scripts for nodemon, React dev server, build process
- Emphasizes separation of concerns: frontend and backend run on different ports

##### Detail without overcomplication
- Layer and its responsibility
- How environment variables bridge configuration
- Secured routes via middleware
- Sequence: User → LoginPage → api.login() → authController → JWT → Store token in client

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        FSRC["React SPA"]:::frontend
        INDEX["Index.js\n(DOM bootstrap)"]:::frontend
        APP["App.js\n(Router Setup)"]:::frontend
        API["api.js\n(HTTP client)"]:::frontend
        LP["LandingPage.jsx"]:::frontend
        HP["HomePage.jsx"]:::frontend
        LOP["LoginPage.jsx"]:::frontend
        RP["RegisterPage.jsx"]:::frontend
        VP["VerifyOTPPage.jsx"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        SERVER["server.js\n(App Initialization)"]:::backend
        DBCONF["db.js\n(MongoDB Config)"]:::backend
        ROUTES["authRoutes.js\n(Routes)"]:::backend
        MIDDLEWARE["authMiddleware.js\n(JWT Guard)"]:::backend
        CONTROLLER["authController.js\n(Business Logic)"]:::backend
        MODEL["User.js\n(Mongoose Model)"]:::backend
        OTPUTIL["generateOTP.js\n(OTP Utility)"]:::backend
    end

    %% External and Database
    DB["MongoDB"]:::db
    OTP_SVC["External OTP Service"]:::external

    %% User Interaction
    User["User Browser"]:::external
    User --> FSRC
    FSRC --> INDEX
    INDEX --> APP
    APP --> LP
    APP --> HP
    APP --> LOP
    APP --> RP
    APP --> VP
    LOP --> API
    RP --> API
    VP --> API

    %% Frontend to Backend
    API -->|"/api/auth/*"| SERVER

    %% Backend flows
    SERVER --> DBCONF
    DBCONF --> DB
    SERVER --> ROUTES
    ROUTES --> CONTROLLER
    ROUTES --> MIDDLEWARE
    MIDDLEWARE --> CONTROLLER
    CONTROLLER --> MODEL
    MODEL --> DB
    CONTROLLER --> OTPUTIL
    OTPUTIL --> OTP_SVC

    %% Click Events
    click FSRC "https://github.com/dharamshiyash/calmspace/tree/main/frontend/src"
    click INDEX "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/index.js"
    click APP "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/App.js"
    click API "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/api.js"
    click LP "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/pages/LandingPage.jsx"
    click HP "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/pages/HomePage.jsx"
    click LOP "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/pages/LoginPage.jsx"
    click RP "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/pages/RegisterPage.jsx"
    click VP "https://github.com/dharamshiyash/calmspace/blob/main/frontend/src/pages/VerifyOTPPage.jsx"
    click SERVER "https://github.com/dharamshiyash/calmspace/blob/main/backend/server.js"
    click DBCONF "https://github.com/dharamshiyash/calmspace/blob/main/backend/config/db.js"
    click CONTROLLER "https://github.com/dharamshiyash/calmspace/blob/main/backend/controllers/authController.js"
    click ROUTES "https://github.com/dharamshiyash/calmspace/blob/main/backend/routes/authRoutes.js"
    click MIDDLEWARE "https://github.com/dharamshiyash/calmspace/blob/main/backend/middleware/authMiddleware.js"
    click MODEL "https://github.com/dharamshiyash/calmspace/blob/main/backend/models/User.js"
    click OTPUTIL "https://github.com/dharamshiyash/calmspace/blob/main/backend/utils/generateOTP.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#DFFFE0,stroke:#28A745,color:#22863A
    classDef db fill:#FFE8A1,stroke:#FF8C00,color:#8B4513
    classDef external fill:#F0F0F0,stroke:#999999,color:#555555
```
