How nirmaladitya306/ems works
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: controllers Controllers · routes Routes · Employees Employee UI · HumanResources HR UI
Components 18
Client
React frontend with role-based UI, routing, state, and shared components
- App shell · Bootstraps the React application and mounts routing, theme, and global UI.
client/src/main.jsx - Routes · Public, protected, employee, and HR route trees with login checks.
client/src/routes - Employee UI · Employee-facing pages and dashboard flows.
client/src/pages/Employees - HR UI · HR-facing dashboards and operational pages.
client/src/pages/HumanResources - Shared UI · Reusable dashboard, auth, chat, and other cross-cutting components.
client/src/components/common - UI kit · Low-level reusable controls such as buttons, dialogs, tables, sheets, sidebars, and toasts.
client/src/components/ui - Redux store · Central state management for dashboards, attendance, leave, recruitment, and related modules.
client/src/redux/app/store.js - Thunks · Async orchestration layer between UI and API wrappers.
client/src/redux/Thunks - API client · 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 · HTTP entry points for auth, HR, employee, and domain features.
server/routes - Auth layer · Employee and HR authentication, role checks, and permission enforcement.
server/middlewares/Auth.middleware.js - Controllers · Domain request handlers for dashboards, attendance, leave, recruitment, chat, and more.
server/controllers - Mongo models · MongoDB collections for employees, HR, attendance, leave, salary, roles, and operational records.
server/models - AI chat · Role-aware chat service with memory, prompts, contexts, and provider abstraction.
server/ai/ChatService.js - Audit utils · Activity logging, access drift detection, and JWT/verification token helpers.
server/utils - MongoDB · Persistent datastore for HR, employee, workflow, and audit data.
Integrations
Out-of-process services used by the backend
- Email templates · Transactional email templates and configuration for verification, recovery, and workflow notifications.
server/mailtrap - Model providers · Cloud or Ollama providers used by the backend chat service.
Connections 20
- 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.