# abhadimishra/erp architecture

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

- Interactive diagram: https://gitdiagram.com/abhadimishra/erp
- Repository: https://github.com/abhadimishra/erp

## Overview

#### Purpose and Top-Level Shape
This is a full-stack ERP-style application with a React/Vite client and a separate backend organized around authentication, user/admin/staff, and student operations. The README is only the Vite template; repository structure is the primary architectural evidence.

#### Runtime Entry Points
- Frontend bootstraps from `src/main.jsx`, composes the application in `src/App.jsx`, and is served/built through `vite.config.js`.
- Backend starts from `backend_ERP/server.js`; database setup is isolated in `backend_ERP/config/db.js`.
- Environment-dependent values are expected through `.env`, likely covering database, server, auth, and/or email settings.

#### Frontend Application Shell and Views
The frontend is a React single-page application. Core user-facing areas include authentication, dashboard/navigation, student management, and staff/user data:
- `src/components/frontend/Login.jsx`
- `src/components/frontend/Dashboard.jsx`
- `src/components/frontend/Student_Page.jsx`
- `src/components/frontend/StaffData.jsx`
- `src/components/frontend/SideBar.jsx`

Shared UI patterns for tables and update/delete actions are represented by `src/components/frontend/DataTable.jsx` and `src/components/frontend/Delete_Update.jsx`.

#### Client State, Routing Protection, and API Boundary
Authentication state is centralized in Redux:
- `src/components/reduxStore/store.js`
- `src/components/reduxStore/authSlice.js`

Route access is guarded by `src/components/ProtectedRoutes/ProtectedRoute.jsx`, forming the client-side authorization boundary. HTTP concerns are consolidated rather than embedded directly in page components:
- `src/api_gateway/axiosInstance.js`
- `src/api_gateway/interceptors.js`
- `src/api_gateway/api.js`

This layer likely attaches credentials, handles common response failures, and presents a consistent API interface to views.

#### Backend HTTP and Authorization Pipeline
Backend routing is grouped by domain and composed through:
- `backend_ERP/routes/index.js`
- `backend_ERP/routes/auth.routes.js`
- `backend_ERP/routes/admin.routes.js`
- `backend_ERP/routes/student.routes.js`
- `backend_ERP/routes/user.routes.js`

Requests pass through authentication and role/permission enforcement middleware before protected controller actions:
- `backend_ERP/middlewares/auth.js`
- `backend_ERP/middlewares/authorize.js`

Controllers provide the HTTP-facing boundary for their domains, including `backend_ERP/controllers/auth.controller.js`, `backend_ERP/controllers/admin.controller.js`, and `backend_ERP/controllers/student.controller.js`.

#### Domain Services and Persistence
Business operations are separated into services, keeping controllers focused on request/response handling:
- `backend_ERP/services/admin.service.js`
- `backend_ERP/services/student.service.js`
- `backend_ERP/services/user.service.js`

Persistent entities cover users, employees/staff, students, and OTP records:
- `backend_ERP/models/user.model.js`
- `backend_ERP/models/employee.model.js`
- `backend_ERP/models/student.model.js`
- `backend_ERP/models/otp.model.js`

The database connection boundary is `backend_ERP/config/db.js`; the specific database vendor is not established by the provided tree.

#### Authentication and Recovery Flow
Authentication is a cross-cutting flow spanning frontend login/recovery screens, Redux state, API interception, backend auth routes/controllers, and auth middleware. Password-recovery/OTP support is explicitly represented by:
- `src/components/frontend/ForgotPass.jsx`
- `backend_ERP/controllers/otp.js`
- `backend_ERP/routes/opt.routes.js`
- `backend_ERP/services/forgotpassword.js`

Backend error propagation is standardized through `backend_ERP/utils/AppError.js` and `backend_ERP/utils/asyncHandler.js`, while the client has a UI failure boundary at `src/components/errorBoundary/GenericFallback.jsx`.

Main entry points: [`src/App.jsx`](https://github.com/abhadimishra/erp/blob/main/src/App.jsx) (Application shell), [`src/components/frontend/Dashboard.jsx`](https://github.com/abhadimishra/erp/blob/main/src/components/frontend/Dashboard.jsx) (ERP views), [`src/api_gateway/api.js`](https://github.com/abhadimishra/erp/blob/main/src/api_gateway/api.js) (API gateway), [`backend_ERP/routes/index.js`](https://github.com/abhadimishra/erp/blob/main/backend_ERP/routes/index.js) (Domain routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React Client"]
  node_vite{{"Vite runtime<br/>build runtime<br/>[vite.config.js]"}}
  node_client_entry["Client entry<br/>React bootstrap<br/>[main.jsx]"]
  node_app_shell["Application shell<br/>React composition<br/>[App.jsx]"]
  node_views["ERP views<br/>React screens<br/>[Dashboard.jsx]"]
  node_shared_ui["Shared data UI<br/>table/actions<br/>[DataTable.jsx]"]
  node_auth_state["Auth state<br/>Redux store<br/>[store.js]"]
  node_route_guard["Protected routes<br/>route guard<br/>[ProtectedRoute.jsx]"]
  node_api_client["API gateway<br/>Axios client<br/>[api.js]"]
  node_client_fallback["UI error fallback<br/>error boundary"]
end

subgraph group_backend["ERP Backend"]
  node_server{{"Backend server<br/>HTTP runtime<br/>[server.js]"}}
  node_routes["Domain routes<br/>route composition<br/>[index.js]"]
  node_authz["Auth and authorization<br/>middleware<br/>[auth.js]"]
  node_controllers["HTTP controllers<br/>controller layer<br/>[auth.controller.js]"]
  node_services["Domain services<br/>service layer<br/>[admin.service.js]"]
  node_recovery["Password recovery<br/>OTP flow<br/>[otp.js]"]
  node_error_handling["Backend error handling<br/>error utilities<br/>[AppError.js]"]
end

subgraph group_data["Persistence"]
  node_models["ERP entities<br/>data models<br/>[user.model.js]"]
  node_database[("Database connection<br/>database boundary<br/>[db.js]")]
end

node_vite -->|"serves/builds"| node_client_entry
node_client_entry -->|"mounts"| node_app_shell
node_app_shell -->|"renders"| node_views
node_app_shell -->|"guards navigation"| node_route_guard
node_views -->|"uses"| node_shared_ui
node_views -->|"requests data"| node_api_client
node_views -->|"reads auth"| node_auth_state
node_route_guard -->|"checks session"| node_auth_state
node_api_client -.->|"updates auth failures"| node_auth_state
node_app_shell -.->|"handles UI failures"| node_client_fallback
node_api_client -->|"HTTP API"| node_server
node_server -->|"mounts"| node_routes
node_routes -->|"protects endpoints"| node_authz
node_authz -->|"permits requests"| node_controllers
node_routes -->|"recovery endpoints"| node_recovery
node_controllers -->|"delegates"| node_services
node_recovery -->|"stores OTPs"| node_models
node_services -->|"reads/writes"| node_models
node_models -->|"persists through"| node_database
node_controllers -.->|"propagates errors"| node_error_handling

click node_vite "https://github.com/abhadimishra/erp/blob/main/vite.config.js"
click node_client_entry "https://github.com/abhadimishra/erp/blob/main/src/main.jsx"
click node_app_shell "https://github.com/abhadimishra/erp/blob/main/src/App.jsx"
click node_views "https://github.com/abhadimishra/erp/blob/main/src/components/frontend/Dashboard.jsx"
click node_shared_ui "https://github.com/abhadimishra/erp/blob/main/src/components/frontend/DataTable.jsx"
click node_auth_state "https://github.com/abhadimishra/erp/blob/main/src/components/reduxStore/store.js"
click node_route_guard "https://github.com/abhadimishra/erp/blob/main/src/components/ProtectedRoutes/ProtectedRoute.jsx"
click node_api_client "https://github.com/abhadimishra/erp/blob/main/src/api_gateway/api.js"
click node_client_fallback "https://github.com/abhadimishra/erp/blob/main/src/components/errorBoundary/GenericFallback.jsx"
click node_server "https://github.com/abhadimishra/erp/blob/main/backend_ERP/server.js"
click node_routes "https://github.com/abhadimishra/erp/blob/main/backend_ERP/routes/index.js"
click node_authz "https://github.com/abhadimishra/erp/blob/main/backend_ERP/middlewares/auth.js"
click node_controllers "https://github.com/abhadimishra/erp/blob/main/backend_ERP/controllers/auth.controller.js"
click node_services "https://github.com/abhadimishra/erp/blob/main/backend_ERP/services/admin.service.js"
click node_recovery "https://github.com/abhadimishra/erp/blob/main/backend_ERP/controllers/otp.js"
click node_error_handling "https://github.com/abhadimishra/erp/blob/main/backend_ERP/utils/AppError.js"
click node_models "https://github.com/abhadimishra/erp/blob/main/backend_ERP/models/user.model.js"
click node_database "https://github.com/abhadimishra/erp/blob/main/backend_ERP/config/db.js"

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_vite,node_client_entry,node_app_shell,node_views,node_shared_ui,node_auth_state,node_route_guard,node_api_client,node_client_fallback toneBlue
class node_server,node_routes,node_authz,node_controllers,node_services,node_recovery,node_error_handling toneAmber
class node_models,node_database toneMint
```

## Components

### React Client

- [Vite runtime](https://github.com/abhadimishra/erp/blob/main/vite.config.js): build runtime · Serves and builds the client. · `vite.config.js`
- [Client entry](https://github.com/abhadimishra/erp/blob/main/src/main.jsx): React bootstrap · `src/main.jsx`
- [Application shell](https://github.com/abhadimishra/erp/blob/main/src/App.jsx): React composition · `src/App.jsx`
- [ERP views](https://github.com/abhadimishra/erp/blob/main/src/components/frontend/Dashboard.jsx): React screens · Login, dashboard, student, and staff screens. · `src/components/frontend/Dashboard.jsx`
- [Shared data UI](https://github.com/abhadimishra/erp/blob/main/src/components/frontend/DataTable.jsx): table/actions · Reusable tables and update/delete controls. · `src/components/frontend/DataTable.jsx`
- [Auth state](https://github.com/abhadimishra/erp/blob/main/src/components/reduxStore/store.js): Redux store · `src/components/reduxStore/store.js`
- [Protected routes](https://github.com/abhadimishra/erp/blob/main/src/components/ProtectedRoutes/ProtectedRoute.jsx): route guard · `src/components/ProtectedRoutes/ProtectedRoute.jsx`
- [API gateway](https://github.com/abhadimishra/erp/blob/main/src/api_gateway/api.js): Axios client · Central API calls, credentials, and response interception. · `src/api_gateway/api.js`
- [UI error fallback](https://github.com/abhadimishra/erp/blob/main/src/components/errorBoundary/GenericFallback.jsx): error boundary · `src/components/errorBoundary/GenericFallback.jsx`

### ERP Backend

- [Backend server](https://github.com/abhadimishra/erp/blob/main/backend_ERP/server.js): HTTP runtime · `backend_ERP/server.js`
- [Domain routes](https://github.com/abhadimishra/erp/blob/main/backend_ERP/routes/index.js): route composition · Auth, admin, student, and user endpoints. · `backend_ERP/routes/index.js`
- [Auth and authorization](https://github.com/abhadimishra/erp/blob/main/backend_ERP/middlewares/auth.js): middleware · Authenticates requests and enforces roles. · `backend_ERP/middlewares/auth.js`
- [HTTP controllers](https://github.com/abhadimishra/erp/blob/main/backend_ERP/controllers/auth.controller.js): controller layer · Auth, admin, and student request handlers. · `backend_ERP/controllers/auth.controller.js`
- [Domain services](https://github.com/abhadimishra/erp/blob/main/backend_ERP/services/admin.service.js): service layer · Admin, student, and user business operations. · `backend_ERP/services/admin.service.js`
- [Password recovery](https://github.com/abhadimishra/erp/blob/main/backend_ERP/controllers/otp.js): OTP flow · OTP and forgot-password handling. · `backend_ERP/controllers/otp.js`
- [Backend error handling](https://github.com/abhadimishra/erp/blob/main/backend_ERP/utils/AppError.js): error utilities · Standardized async and application errors. · `backend_ERP/utils/AppError.js`

### Persistence

- [ERP entities](https://github.com/abhadimishra/erp/blob/main/backend_ERP/models/user.model.js): data models · Users, employees, students, and OTP records. · `backend_ERP/models/user.model.js`
- [Database connection](https://github.com/abhadimishra/erp/blob/main/backend_ERP/config/db.js): database boundary · Vendor is unspecified. · `backend_ERP/config/db.js`

## Connections

- Vite runtime → Client entry: serves/builds
- Client entry → Application shell: mounts
- Application shell → ERP views: renders
- Application shell → Protected routes: guards navigation
- ERP views → Shared data UI: uses
- ERP views → API gateway: requests data
- ERP views → Auth state: reads auth
- Protected routes → Auth state: checks session
- API gateway → Auth state: updates auth failures
- Application shell → UI error fallback: handles UI failures
- API gateway → Backend server: HTTP API
- Backend server → Domain routes: mounts
- Domain routes → Auth and authorization: protects endpoints
- Auth and authorization → HTTP controllers: permits requests
- Domain routes → Password recovery: recovery endpoints
- HTTP controllers → Domain services: delegates
- Password recovery → ERP entities: stores OTPs
- Domain services → ERP entities: reads/writes
- ERP entities → Database connection: persists through
- HTTP controllers → Backend error handling: propagates errors
