# govindadd/crm architecture

> Architecture diagram of the GitHub repository govindadd/crm, 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/govindadd/crm
- Repository: https://github.com/govindadd/crm

## Overview

##### Project type and purpose
- This is a modern, enterprise-ready full-stack CRM (Customer Relationship Management) system.
- Frontend: React + Redux Toolkit + Vite + Tailwind CSS for a highly interactive, animated dashboard.
- Backend: Node.js + Express + MongoDB (Mongoose) following an API-first, modular design.
- Core features: user & role management, department management, attendance tracking, modular business domains (HR, Sales, Training, Data Mining, After Sales, Telecom), JWT & OAuth authentication, file uploads (Cloudinary), email notifications (Nodemailer), RBAC.

##### File structure
A. Top-level directories
- client/ → React SPA code
- server/ → Express API code
- z/ → Postman collection and image assets (auxiliary)
B. Frontend layout
- public/ (static files)
- src/
- assets (logos, videos)
- components (feature folders: attendance, department, forms, hrTabs, profile, ui)
- hooks (domain-specific custom hooks)
- layouts, pages (route-level components)
- services (API wrappers, private route)
- store (Redux slices, store config)
- utils (helpers: date formatting, PDF export)
- entry points: main.jsx, App.jsx, AppLayout.jsx
C. Backend layout
- src/
- config (Passport, constants)
- controllers (business logic per domain)
- db (MongoDB connection)
- middlewares (auth, roles, Multer uploads)
- models (Mongoose schemas per domain)
- routes (REST endpoints per resource)
- utils (error handling, async, Cloudinary, email, OTP)
- app.js, index.js (server bootstrap)
D. Cross-cutting files
- .env & .envExample, ESLint/Prettier configs, package.json in each module

##### README insights
- Confirms architecture: API-first, modular backend, React + Redux front.
- Lists technologies, major endpoints, environment variables, developer & deployment steps.

##### Detail
- Don’t just lump “backend” together—break it into Routes, Middlewares, Controllers, Models.
- On the frontend, separate pages, components, hooks, store.
- Critical flows: authentication handshake, role validation, OTP flow, file upload.
- Environment configurations (e.g., .env endpoints) if relevant for deployment.

## Diagram (Mermaid)

```mermaid
flowchart LR
  subgraph "Browser Client (React SPA)"
    direction TB
    EP1["main.jsx"]:::frontend
    EP2["App.jsx"]:::frontend
    EP3["AppLayout.jsx"]:::frontend
    UI["UI Components"]:::frontend
    Hooks["Custom Hooks"]:::frontend
    Store["Redux Store & Slices"]:::frontend
    S1["store.js"]:::frontend
    S2["authSlice.js"]:::frontend
    S3["userSlice.js"]:::frontend
    S4["departmentSlice.js"]:::frontend
    S5["attendanceSlice.js"]:::frontend
    S6["publicProfileSlice.js"]:::frontend
    Services["API Service Layer"]:::frontend
    A1["axios.js"]:::frontend
    A2["PrivateRoute.jsx"]:::frontend

    EP1 --> EP2
    EP2 --> EP3
    EP3 --> UI
    UI --> Hooks
    Hooks --> Store
    Store --> S1
    Store --> S2
    Store --> S3
    Store --> S4
    Store --> S5
    Store --> S6
    Store --> Services
    Services --> A1
    Services --> A2
    A1 -->|"HTTP calls"| API
    A2 --> API

    click EP1 "https://github.com/govindadd/crm/blob/main/client/src/main.jsx"
    click EP2 "https://github.com/govindadd/crm/blob/main/client/src/App.jsx"
    click EP3 "https://github.com/govindadd/crm/blob/main/client/src/AppLayout.jsx"
    click UI "https://github.com/govindadd/crm/tree/main/client/src/components"
    click S1 "https://github.com/govindadd/crm/blob/main/client/src/store/store.js"
    click S2 "https://github.com/govindadd/crm/blob/main/client/src/store/authSlice.js"
    click S3 "https://github.com/govindadd/crm/blob/main/client/src/store/userSlice.js"
    click S4 "https://github.com/govindadd/crm/blob/main/client/src/store/departmentSlice.js"
    click S5 "https://github.com/govindadd/crm/blob/main/client/src/store/attendanceSlice.js"
    click S6 "https://github.com/govindadd/crm/blob/main/client/src/store/publicProfileSlice.js"
    click A1 "https://github.com/govindadd/crm/blob/main/client/src/services/axios.js"
    click A2 "https://github.com/govindadd/crm/blob/main/client/src/services/PrivateRoute.jsx"
  end

  subgraph "Express API Gateway" 
    direction TB
    API["Express Server"]:::backend
    EPa1["index.js"]:::backend
    EPa2["app.js"]:::backend
    API --> EPa2
    EPa2 --> EPa1

    subgraph "Route Definitions"
      direction TB
      R1["auth.routes.js"]:::backend
      R2["user.route.js"]:::backend
      R3["department.route.js"]:::backend
      R4["attendance.route.js"]:::backend
      R5["hr.routes.js"]:::backend
      R6["test.route.js"]:::backend

      EPa2 --> R1
      EPa2 --> R2
      EPa2 --> R3
      EPa2 --> R4
      EPa2 --> R5
      EPa2 --> R6

      click R1 "https://github.com/govindadd/crm/blob/main/server/src/routes/auth.routes.js"
      click R2 "https://github.com/govindadd/crm/blob/main/server/src/routes/user.route.js"
      click R3 "https://github.com/govindadd/crm/blob/main/server/src/routes/department.route.js"
      click R4 "https://github.com/govindadd/crm/blob/main/server/src/routes/attendance.route.js"
      click R5 "https://github.com/govindadd/crm/blob/main/server/src/routes/hr.routes.js"
      click R6 "https://github.com/govindadd/crm/blob/main/server/src/routes/test.route.js"
    end

    subgraph "Middlewares"
      direction TB
      M1["auth.middleware.js"]:::backend
      M2["role.middleware.js"]:::backend
      M3["multer.middleware.js"]:::backend

      R1 --> M1
      R2 --> M1
      R3 --> M1
      R4 --> M1
      R5 --> M1

      R1 --> M2
      R2 --> M2
      R3 --> M2
      R4 --> M2

      R4 --> M3

      click M1 "https://github.com/govindadd/crm/blob/main/server/src/middlewares/auth.middleware.js"
      click M2 "https://github.com/govindadd/crm/blob/main/server/src/middlewares/role.middleware.js"
      click M3 "https://github.com/govindadd/crm/blob/main/server/src/middlewares/multer.middleware.js"
    end

    subgraph "Controllers"
      direction TB
      C1["auth.controller.js"]:::backend
      C2["user.controller.js"]:::backend
      C3["department.controller.js"]:::backend
      C4["attendance.controller.js"]:::backend
      C5["hr.controller.js"]:::backend

      M1 --> C1
      M1 --> C2
      M1 --> C3
      M1 --> C4
      M1 --> C5

      click C1 "https://github.com/govindadd/crm/blob/main/server/src/controllers/auth.controller.js"
      click C2 "https://github.com/govindadd/crm/blob/main/server/src/controllers/user.controller.js"
      click C3 "https://github.com/govindadd/crm/blob/main/server/src/controllers/department.controller.js"
      click C4 "https://github.com/govindadd/crm/blob/main/server/src/controllers/attendance.controller.js"
      click C5 "https://github.com/govindadd/crm/blob/main/server/src/controllers/hr.controller.js"
    end

    subgraph "Models"
      direction TB
      MD1["user.model.js"]:::backend
      MD2["department.model.js"]:::backend
      MD3["attendance.model.js"]:::backend
      MD4["hr.model.js"]:::backend
      MD5["sales.model.js"]:::backend
      MD6["training.model.js"]:::backend
      MD7["datamining.model.js"]:::backend
      MD8["afterSales.model.js"]:::backend
      MD9["telecom.model.js"]:::backend
      MD10["jobApplication.model.js"]:::backend
      MD11["membership.model.js"]:::backend

      C1 --> MD1
      C2 --> MD1
      C3 --> MD2
      C4 --> MD3
      C5 --> MD4

      click MD1 "https://github.com/govindadd/crm/blob/main/server/src/models/user.model.js"
      click MD2 "https://github.com/govindadd/crm/blob/main/server/src/models/department.model.js"
      click MD3 "https://github.com/govindadd/crm/blob/main/server/src/models/attendance.model.js"
      click MD4 "https://github.com/govindadd/crm/blob/main/server/src/models/hr.model.js"
      click MD5 "https://github.com/govindadd/crm/blob/main/server/src/models/sales.model.js"
      click MD6 "https://github.com/govindadd/crm/blob/main/server/src/models/training.model.js"
      click MD7 "https://github.com/govindadd/crm/blob/main/server/src/models/datamining.model.js"
      click MD8 "https://github.com/govindadd/crm/blob/main/server/src/models/afterSales.model.js"
      click MD9 "https://github.com/govindadd/crm/blob/main/server/src/models/telecom.model.js"
      click MD10 "https://github.com/govindadd/crm/blob/main/server/src/models/jobApplication.model.js"
      click MD11 "https://github.com/govindadd/crm/blob/main/server/src/models/membership.model.js"
    end

    DB["MongoDB"]:::backend
    DBConn["DB Connection"]:::backend
    EPa2 --> DBConn
    DBConn --> DB
    click DBConn "https://github.com/govindadd/crm/blob/main/server/src/db/index.db.js"
  end

  subgraph "Utilities & Helpers"
    direction TB
    U1["ApiError.js"]:::backend
    U2["ApiResponse.js"]:::backend
    U3["asyncHandler.js"]:::backend
    U4["cloudinary.js"]:::backend
    U5["sendEmail.js"]:::backend
    U6["generateOTP.js"]:::backend

    C1 --> U1
    C1 --> U2
    C1 --> U3
    C1 --> U4
    C1 --> U5
    C1 --> U6

    click U1 "https://github.com/govindadd/crm/blob/main/server/src/utils/ApiError.js"
    click U2 "https://github.com/govindadd/crm/blob/main/server/src/utils/ApiResponse.js"
    click U3 "https://github.com/govindadd/crm/blob/main/server/src/utils/asyncHandler.js"
    click U4 "https://github.com/govindadd/crm/blob/main/server/src/utils/cloudinary.js"
    click U5 "https://github.com/govindadd/crm/blob/main/server/src/utils/sendEmail.js"
    click U6 "https://github.com/govindadd/crm/blob/main/server/src/utils/generateOTP.js"
  end

  subgraph "External Services"
    direction TB
    CL["Cloudinary"]:::external
    SMTP["SMTP (Nodemailer)"]:::external
    OAuth["Google OAuth"]:::external

    M3 --> CL
    C1 --> SMTP
    C1 --> OAuth
  end

  API -->|requests| DB
  Services --> API

  classDef frontend fill:#FFE4B5,stroke:#333,stroke-width:1px
  classDef backend fill:#B0E0E6,stroke:#333,stroke-width:1px
  classDef external fill:#98FB98,stroke:#333,stroke-width:1px
```
