# darsh-jogi/employee-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/darsh-jogi/employee-management-system
- Repository: https://github.com/darsh-jogi/employee-management-system

## Overview

##### Project Type & Purpose
- This is a full-stack MERN (MongoDB, Express.js, React.js, Node.js) web application named “Employees Management System (EMS).”
- It supports two major user roles: HR professionals and Employees, offering dashboards, attendance/leave/salary management, recruitment tracking, notifications, and email workflows.

##### File Structure Analysis
- Top level separates “client” (frontend) and “server” (backend).
- Frontend (“client”) uses React with Vite, Redux (Slices & Thunks), Tailwind CSS, and ShadCN UI components.
- Backend (“server”) uses Node.js/Express, follows MVC:
- routes/ → maps HTTP endpoints
- controllers/ → request handlers
- services/ → business logic (light, here mostly models + utils)
- models/ → Mongoose schemas for MongoDB
- middlewares/ → JWT auth & role-based checks
- Config files: .env, Vite config, tailwind.config, connectDB, mailtrap settings.

##### Key Architectural Patterns
- Frontend: Component-based UI, global state via Redux, asynchronous data fetching via Thunks, client-side routing with React Router.
- Backend: RESTful API, layered MVC, middleware for authentication/authorization, external email service via Mailtrap.
- Security: JWT-based auth, role-based access control (RBAC).

##### Main Components & Interactions
a. Frontend Components
- Browser / React SPA (AppRoutes, AuthRoutes, protected routes)
- UI Components (ShadCN + Tailwind)
- Redux Store (Slices, AsyncReducers, Thunks)
- API Service module (APIService, APIEndpoints)
b. Backend Components
- Express Server (index.js)
- Route Layer (routes/*.route.js)
- Controller Layer (controllers/*.controller.js)
- Model Layer (models/*.model.js)
- Middleware (Auth.middleware, RoleAuth.middleware)
- Utility Modules (JWT token generator, verification token, mail templates)
- External Service: Mailtrap (email sending)
- Database: MongoDB via Mongoose
c. Data Flows & Relationships
1. User → Browser UI → Redux Action → Thunk → APIService → HTTP Request
2. Express Route → Auth/Role Middleware → Controller → Service/Model → MongoDB
3. Controller → Utility → Mailtrap (for emails)
4. MongoDB → Mongoose → Controller → Response → Frontend Redux → UI

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Browser
    Browser["Browser / Public Internet"]:::external

    subgraph "Client" 
        direction TB
        Main["main.jsx"]:::frontend
        App["App.jsx"]:::frontend
        AppRoutes["AppRoutes.jsx"]:::frontend
        AuthRoutes["AuthRoutes.jsx"]:::frontend
        ProtectedRoutes["protectedroutes.jsx"]:::frontend
        HRProtected["HRprotectedroutes.jsx"]:::frontend
        EmpRoutes["employeeroutes.jsx"]:::frontend
        UIComponents["UI Components (ShadCN + Tailwind)"]:::frontend
        DashboardUI["Dashboard UI Components"]:::frontend
        AuthPages["Auth Pages & Forms"]:::frontend
        HRPages["HR Pages"]:::frontend
        EmpPages["Employee Pages"]:::frontend
        Store["Redux Store (store.js)"]:::frontend
        Slices["Redux Slices"]:::frontend
        Thunks["Redux Thunks"]:::frontend
        APIService["API Service Module"]:::frontend
        UtilsClient["Common Handler Utils"]:::frontend
    end

    subgraph "Server (MVC)" 
        direction TB
        ServerEntry["server/index.js"]:::backend
        ConnectDB["connectDB.js"]:::backend
        RouteLayer["Route Layer"]:::backend
        AuthMiddleware["Auth.middleware.js"]:::backend
        RoleMiddleware["RoleAuth.middleware.js"]:::backend
        Controllers["Controller Layer"]:::backend
        Models["Model Layer"]:::backend
        UtilsServer["JWT & Verification Utils"]:::backend
        MailtrapConfig["Mailtrap Config"]:::backend
        MailtrapUtils["Mailtrap Emails & Templates"]:::backend
    end

    MongoDB["MongoDB"]:::datastore
    Mailtrap["Mailtrap Email Service"]:::external

    %% Client flow
    Browser --> Main
    Main --> App
    App --> AppRoutes
    App --> AuthRoutes
    AppRoutes --> ProtectedRoutes
    AppRoutes --> HRProtected
    AppRoutes --> EmpRoutes
    AppRoutes --> UIComponents
    UIComponents --> DashboardUI
    UIComponents --> AuthPages
    AppRoutes --> HRPages
    AppRoutes --> EmpPages
    UIComponents --> Store
    Store --> Slices
    Store --> Thunks
    Thunks --> APIService
    APIService --> ServerEntry

    %% Server flow
    ServerEntry --> ConnectDB
    ConnectDB --> MongoDB
    ServerEntry --> RouteLayer
    RouteLayer --> AuthMiddleware
    AuthMiddleware --> RoleMiddleware
    RoleMiddleware --> Controllers
    Controllers --> Models
    Models --> MongoDB
    ServerEntry --> UtilsServer
    Controllers --> MailtrapConfig
    MailtrapConfig --> MailtrapUtils
    MailtrapUtils --> Mailtrap

    %% Return path
    Controllers -->|Response| APIService
    APIService --> Store
    Store --> UIComponents
    UIComponents --> Browser

    %% Click Events
    click Main "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/main.jsx"
    click App "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/App.jsx"
    click AppRoutes "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/routes/AppRoutes.jsx"
    click AuthRoutes "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/routes/AuthRoutes.jsx"
    click ProtectedRoutes "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/routes/protectedroutes.jsx"
    click HRProtected "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/routes/HRprotectedroutes.jsx"
    click EmpRoutes "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/routes/employeeroutes.jsx"
    click UIComponents "https://github.com/darsh-jogi/employee-management-system/tree/main/client/src/components/ui"
    click DashboardUI "https://github.com/darsh-jogi/employee-management-system/tree/main/client/src/components/common/Dashboard"
    click AuthPages "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/components/common/sign-in.jsx"
    click Store "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/redux/app/store.js"
    click Slices "https://github.com/darsh-jogi/employee-management-system/tree/main/client/src/redux/Slices"
    click Thunks "https://github.com/darsh-jogi/employee-management-system/tree/main/client/src/redux/Thunks"
    click APIService "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/redux/apis/APIService.js"
    click UtilsClient "https://github.com/darsh-jogi/employee-management-system/blob/main/client/src/utils/commonhandler.js"
    click ServerEntry "https://github.com/darsh-jogi/employee-management-system/blob/main/server/index.js"
    click ConnectDB "https://github.com/darsh-jogi/employee-management-system/blob/main/server/config/connectDB.js"
    click RouteLayer "https://github.com/darsh-jogi/employee-management-system/tree/main/server/routes"
    click AuthMiddleware "https://github.com/darsh-jogi/employee-management-system/blob/main/server/middlewares/Auth.middleware.js"
    click RoleMiddleware "https://github.com/darsh-jogi/employee-management-system/blob/main/server/middlewares/RoleAuth.middleware.js"
    click Controllers "https://github.com/darsh-jogi/employee-management-system/tree/main/server/controllers"
    click Models "https://github.com/darsh-jogi/employee-management-system/tree/main/server/models"
    click UtilsServer "https://github.com/darsh-jogi/employee-management-system/blob/main/server/utils/generatejwttokenandsetcookies.js"
    click MailtrapConfig "https://github.com/darsh-jogi/employee-management-system/blob/main/server/mailtrap/mailtrap.config.js"
    click MailtrapUtils "https://github.com/darsh-jogi/employee-management-system/tree/main/server/mailtrap"

    %% Styles
    classDef frontend fill:#A8DADC,stroke:#457B9D,color:#1D3557
    classDef backend fill:#A2D5AB,stroke:#2F4F4F,color:#073B4C
    classDef datastore fill:#F4A261,stroke:#E76F51,color:#9A3412
    classDef external fill:#B5838D,stroke:#6D6875,color:#3D405B
```
