# nirmaladitya306/ems architecture

> Architecture diagram of the GitHub repository nirmaladitya306/ems, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nirmaladitya306/ems
- Repository: https://github.com/nirmaladitya306/ems

## Overview

1. This is a two-tier MERN application: a React frontend in `client/` and an Express/MongoDB backend in `server/`. The main architectural boundary is the API layer between them, with the frontend acting as a role-specific UI and the backend owning authentication, business rules, persistence, email, and AI-assisted chat.

2. The frontend is organized by user role and feature area. `src/pages/Employees` and `src/pages/HumanResources` contain the major route targets for employee and HR workflows, while `src/components/common` and `src/components/ui` hold reusable dashboard, auth, and design-system-style components. This separation is important for the diagram because the employee and HR experiences are effectively two different shells on top of shared primitives.

3. Routing is a first-class boundary on the client. `src/routes` contains public auth routes, protected routes, employee routes, HR routes, and login checks. The app likely mounts different route trees depending on authentication and role, with dedicated access control for employee versus HR navigation.

4. State management is centralized in Redux. `src/redux` is split into `Slices`, `Thunks`, `Reducers`, `apis`, and `app/store.js`, which suggests a classic async flow: UI dispatches thunk actions, thunks call API endpoint wrappers, reducers persist results in the store, and pages/components render from Redux state. This is the primary frontend data flow for dashboards, lists, charts, attendance, leaves, recruitment, and similar modules.

5. The frontend API layer is explicitly separated from UI logic. `src/redux/apis` defines endpoint modules and a shared `APIService`, so the UI does not call the server directly. For architecture purposes, this is the client-side integration boundary: pages/components -> thunks -> API service -> backend routes.

6. Shared UI patterns appear to include dashboard shells, tables, dialogs, charts, toasts, and a chat widget. `src/components/common/Dashboard` and `src/components/common/Chat` provide cross-cutting dashboard utilities, while the `ui/` folder contains low-level building blocks such as buttons, sheets, dialogs, tables, and sidebars. `ThemeContext` and toast hooks indicate app-wide presentation and notification services.

7. The backend follows a standard layered Express structure: `routes` map HTTP endpoints, `controllers` implement request handling, `models` define MongoDB collections, and `middlewares` enforce authentication/authorization. This gives a clear diagram boundary of transport -> controller -> model -> database, with security checks injected before protected controllers.

8. Authentication and authorization are central backend concerns. There are separate auth controllers and routes for employee and HR accounts, plus middleware for auth, role auth, and permissions. JWT token generation/cookie setting lives in `utils/generatejwttokenandsetcookies.js`, and verification-token helpers support signup/password-reset flows. The design suggests role-based access control is enforced server-side, not just in the client router.

9. The data model is domain-heavy and maps closely to HR operations. Key entities include employees, HR users, attendance, leave, salary, notices, departments, roles/RBAC, recruitment/applicants, interviews, documents, exit clearance, activity logs, access drift, and organizational structure. Most frontend pages and Redux slices appear to correspond directly to one of these backend domains.

10. Email is a separate integration path. The `mailtrap/` folder contains templates and configuration for transactional emails such as verification, onboarding, password recovery, document expiry, and notifications. In the architecture diagram, this is an external outbound service used by auth and workflow controllers rather than part of the core request/response path.

11. There is also an AI/chat subsystem on the server. `server/ai` includes a `ChatService`, memory management, system prompts, domain context files for employee and HR, and provider abstractions for cloud or Ollama-based models. This suggests chat requests are routed through a provider factory and can use role-specific context before returning responses to the frontend chat widget.

12. Operational utilities support cross-cutting behavior. `accessDriftDetector` and `activityLogger` imply the backend tracks permission anomalies and user activity, which likely feed the access drift and activity log modules in the UI. These are not primary user-facing features but important infrastructure for auditability and security.

13. The most important end-to-end flows are: login/registration and verification; employee/HR dashboard reads; HR actions on leaves, attendance, salary, recruitment, and notices; and transactional notifications via email/chat. For diagrams, the clearest representation is two role-based UI branches converging on a shared Redux/API layer, then fanning out into backend domains guarded by auth/permission middleware and persisted in MongoDB.

14. In short, this repository is best understood as a role-separated HR management platform with a shared React shell, Redux-driven server communication, an Express/Mongoose domain backend, and a few specialized integration services for email, auditing, and AI chat.

Main entry points: [`server/controllers`](https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/controllers) (Controllers), [`client/src/routes`](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/routes) (Routes), [`client/src/pages/Employees`](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/pages/Employees) (Employee UI), [`client/src/pages/HumanResources`](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/pages/HumanResources) (HR UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_app["App shell<br/>react entry<br/>[main.jsx]"]
  node_client_routes["Routes<br/>route trees"]
  node_client_employee_ui["Employee UI<br/>role shell"]
  node_client_hr_ui["HR UI<br/>role shell"]
  node_client_common["Shared UI<br/>components"]
  node_client_design_system["UI kit<br/>primitives"]
  node_client_redux["Redux store<br/>state layer<br/>[store.js]"]
  node_client_thunks["Thunks<br/>async actions"]
  node_client_api["API client<br/>endpoint wrappers"]
end

subgraph group_server["Server"]
  node_server_routes["Routes<br/>http endpoints"]
  node_server_auth["Auth layer<br/>security<br/>[Auth.middleware.js]"]
  node_server_controllers["Controllers<br/>request handlers"]
  node_server_models[("Mongo models<br/>persistence models")]
  node_server_ai["AI chat<br/>chat service<br/>[ChatService.js]"]
  node_server_utils["Audit utils<br/>cross-cutting utils"]
  node_server_db[("MongoDB<br/>database")]
end

subgraph group_integrations["Integrations"]
  node_server_email["Email templates<br/>mail integration"]
  node_server_external_ai(("Model providers<br/>external AI"))
end

node_client_app -->|"mounts"| node_client_routes
node_client_routes -->|"employee views"| node_client_employee_ui
node_client_routes -->|"HR views"| node_client_hr_ui
node_client_employee_ui -->|"uses"| node_client_common
node_client_hr_ui -->|"uses"| node_client_common
node_client_common -->|"builds on"| node_client_design_system
node_client_employee_ui -->|"reads state"| node_client_redux
node_client_hr_ui -->|"reads state"| node_client_redux
node_client_redux -->|"dispatches"| node_client_thunks
node_client_thunks -->|"calls"| node_client_api
node_client_api -->|"HTTP API"| node_server_routes
node_server_routes -->|"protects"| node_server_auth
node_server_routes -->|"dispatches"| node_server_controllers
node_server_controllers -->|"reads/writes"| node_server_models
node_server_models -->|"stores in"| node_server_db
node_server_controllers -->|"sends mail"| node_server_email
node_server_controllers -->|"chat flow"| node_server_ai
node_server_ai -->|"invokes"| node_server_external_ai
node_server_controllers -->|"logs / tokens"| node_server_utils
node_server_utils -->|"supports"| node_server_auth

click node_client_app "https://github.com/nirmaladitya306/ems/blob/frontend-changes/client/src/main.jsx"
click node_client_routes "https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/routes"
click node_client_employee_ui "https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/pages/Employees"
click node_client_hr_ui "https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/pages/HumanResources"
click node_client_common "https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/components/common"
click node_client_design_system "https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/components/ui"
click node_client_redux "https://github.com/nirmaladitya306/ems/blob/frontend-changes/client/src/redux/app/store.js"
click node_client_thunks "https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/redux/Thunks"
click node_client_api "https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/redux/apis"
click node_server_routes "https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/routes"
click node_server_auth "https://github.com/nirmaladitya306/ems/blob/frontend-changes/server/middlewares/Auth.middleware.js"
click node_server_controllers "https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/controllers"
click node_server_models "https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/models"
click node_server_ai "https://github.com/nirmaladitya306/ems/blob/frontend-changes/server/ai/ChatService.js"
click node_server_email "https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/mailtrap"
click node_server_utils "https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/utils"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_app,node_client_routes,node_client_employee_ui,node_client_hr_ui,node_client_common,node_client_design_system,node_client_redux,node_client_thunks,node_client_api toneBlue
class node_server_routes,node_server_auth,node_server_controllers,node_server_models,node_server_ai,node_server_utils,node_server_db toneAmber
class node_server_email,node_server_external_ai toneMint
```

## Components

### Client

React frontend with role-based UI, routing, state, and shared components

- [App shell](https://github.com/nirmaladitya306/ems/blob/frontend-changes/client/src/main.jsx): react entry · Bootstraps the React application and mounts routing, theme, and global UI. · `client/src/main.jsx`
- [Routes](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/routes): route trees · Public, protected, employee, and HR route trees with login checks. · `client/src/routes`
- [Employee UI](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/pages/Employees): role shell · Employee-facing pages and dashboard flows. · `client/src/pages/Employees`
- [HR UI](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/pages/HumanResources): role shell · HR-facing dashboards and operational pages. · `client/src/pages/HumanResources`
- [Shared UI](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/components/common): components · Reusable dashboard, auth, chat, and other cross-cutting components. · `client/src/components/common`
- [UI kit](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/components/ui): primitives · Low-level reusable controls such as buttons, dialogs, tables, sheets, sidebars, and toasts. · `client/src/components/ui`
- [Redux store](https://github.com/nirmaladitya306/ems/blob/frontend-changes/client/src/redux/app/store.js): state layer · Central state management for dashboards, attendance, leave, recruitment, and related modules. · `client/src/redux/app/store.js`
- [Thunks](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/redux/Thunks): async actions · Async orchestration layer between UI and API wrappers. · `client/src/redux/Thunks`
- [API client](https://github.com/nirmaladitya306/ems/tree/frontend-changes/client/src/redux/apis): endpoint wrappers · Shared API service and endpoint modules used by thunks instead of direct server calls. · `client/src/redux/apis`

### Server

Express backend with domain controllers, security, persistence, and integrations

- [Routes](https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/routes): http endpoints · HTTP entry points for auth, HR, employee, and domain features. · `server/routes`
- [Auth layer](https://github.com/nirmaladitya306/ems/blob/frontend-changes/server/middlewares/Auth.middleware.js): security · Employee and HR authentication, role checks, and permission enforcement. · `server/middlewares/Auth.middleware.js`
- [Controllers](https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/controllers): request handlers · Domain request handlers for dashboards, attendance, leave, recruitment, chat, and more. · `server/controllers`
- [Mongo models](https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/models): persistence models · MongoDB collections for employees, HR, attendance, leave, salary, roles, and operational records. · `server/models`
- [AI chat](https://github.com/nirmaladitya306/ems/blob/frontend-changes/server/ai/ChatService.js): chat service · Role-aware chat service with memory, prompts, contexts, and provider abstraction. · `server/ai/ChatService.js`
- [Audit utils](https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/utils): cross-cutting utils · Activity logging, access drift detection, and JWT/verification token helpers. · `server/utils`
- **MongoDB**: database · Persistent datastore for HR, employee, workflow, and audit data.

### Integrations

Out-of-process services used by the backend

- [Email templates](https://github.com/nirmaladitya306/ems/tree/frontend-changes/server/mailtrap): mail integration · Transactional email templates and configuration for verification, recovery, and workflow notifications. · `server/mailtrap`
- **Model providers**: external AI · Cloud or Ollama providers used by the backend chat service.

## Connections

- App shell → Routes: mounts · App shell installs the route tree.
- Routes → Employee UI: employee views · Employee route branch renders employee pages.
- Routes → HR UI: HR views · HR route branch renders HR pages.
- Employee UI → Shared UI: uses · Employee screens compose shared dashboard and auth components.
- HR UI → Shared UI: uses · HR screens compose shared dashboard and auth components.
- Shared UI → UI kit: builds on · Shared components are assembled from design-system primitives.
- Employee UI → Redux store: reads state · Employee pages render from Redux state.
- HR UI → Redux store: reads state · HR pages render from Redux state.
- Redux store → Thunks: dispatches · Store updates are driven through thunked async flows.
- Thunks → API client: calls · Thunks invoke shared endpoint wrappers and API service.
- API client → Routes: HTTP API · Client API layer talks to backend routes.
- Routes → Auth layer: protects · Protected routes apply authentication, role, and permission checks.
- Routes → Controllers: dispatches · Routes forward requests to domain controllers.
- Controllers → Mongo models: reads/writes · Controllers persist and query domain data through models.
- Mongo models → MongoDB: stores in · Mongo models map onto the database.
- Controllers → Email templates: sends mail · Workflow and auth controllers emit transactional email.
- Controllers → AI chat: chat flow · Chat requests are handled by the AI service.
- AI chat → Model providers: invokes · Provider factory routes requests to cloud or local model backends.
- Controllers → Audit utils: logs / tokens · Controllers use audit utilities and token helpers.
- Audit utils → Auth layer: supports · JWT and verification helpers support auth middleware.
