# akashakula327/major_project architecture

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

- Interactive diagram: https://gitdiagram.com/akashakula327/major_project
- Repository: https://github.com/akashakula327/major_project

## Overview

1. **Overall shape**
   - This is a two-tier municipal complaint system: a React frontend and an Express/MySQL backend.
   - The frontend talks directly to the backend API over HTTP; the backend owns authentication, authorization, complaint workflows, and persistence.

2. **Backend runtime boundary**
   - `backend/Server.js` is the entry point for the Node.js/Express server.
   - `backend/config/db.js` centralizes the MySQL connection.
   - The backend is organized around route modules, controllers, middleware, and shared constants rather than a larger framework.

3. **API surface and responsibility split**
   - `backend/routes/*` defines the public HTTP endpoints, separated by domain: auth, complaints, officer, and admin.
   - Each route file delegates to a matching controller in `backend/controllers/*`, so the controllers contain the business logic while routes stay thin.
   - This separation is important for diagramming: request enters route → middleware → controller → database.

4. **Cross-cutting security**
   - `backend/middleware/authMiddleware.js` verifies JWT-authenticated requests.
   - `backend/middleware/roleMiddleware.js` enforces role-based access control for admin/officer/citizen boundaries.
   - The app’s main security model is: authenticate user identity first, then authorize by role for the target endpoint.

5. **Domain modules in the backend**
   - `authController.js` handles registration and login.
   - `complaintController.js` handles complaint submission and citizen complaint retrieval.
   - `officerController.js` handles officer-scoped complaint views and status updates.
   - `adminController.js` handles system administration, including user management and manual assignment flows.

6. **Complaint workflow**
   - A citizen submits a complaint through the frontend, which posts to the complaint API.
   - The backend stores complaint data in MySQL and assigns metadata such as status, category, priority, summary, and location.
   - The README says complaints are AI-categorized and auto-assigned to officers based on specialization and workload; in the code layout, that logic would live in the complaint controller/backend flow even though no separate AI service module is shown.

7. **Data model boundaries**
   - The database schema described in the README uses `users`, `roles`, `user_roles`, and `complaints`.
   - `users` holds identities and officer specialization.
   - `user_roles` gives the system multi-role flexibility instead of a single role column.
   - `complaints` links each complaint to the submitting user and optionally to an assigned officer, while storing lifecycle fields like status and timestamps.

8. **Shared constants and domain vocabulary**
   - Both backend and frontend define role, status, and specialization constants.
   - This suggests the UI and API intentionally share the same business vocabulary for consistent rendering and validation.
   - `backend/constants/*` and `frontend/src/constants/*` are important diagram nodes because they reduce drift between server rules and UI labels.

9. **Frontend application structure**
   - The frontend is a Vite-based React app (`frontend/src/main.jsx`, `frontend/src/App.jsx`).
   - `frontend/src/config/api.js` centralizes the backend base URL, so all API calls route through one client configuration.
   - `AuthContext.jsx` and `ComplaintContext.jsx` provide global state for user session and complaint data.

10. **Frontend navigation and access control**
   - `ProtectedRoute.jsx` gates route access based on authentication and likely role.
   - `DashboardLayout.jsx` and `Navbar.jsx` provide the shared authenticated shell.
   - Pages are role-oriented: login/register, citizen complaint submission, citizen dashboard, officer complaints, admin complaint/user management, and a 404 page.

11. **Role-specific UI flows**
   - Citizens use `SubmitComplaint.jsx`, `Dashboard.jsx`, and related history/status views.
   - Officers use `OfficerComplaints.jsx` to inspect assigned work and update complaint status.
   - Admins use `AdminComplaints.jsx`, `ManageCitizens.jsx`, and `ManageOfficers.jsx` to oversee users and assignments.
   - This is a clear three-lane architecture: citizen, officer, admin, each with its own UI entry points and API permissions.

12. **End-to-end request path**
   - Typical flow: user logs in on the React app → receives JWT from `/auth/login` → token is stored in app state/context → protected pages send authenticated requests to complaint/admin/officer endpoints → Express middleware validates the token and role → controller reads/writes MySQL → updated state returns to the UI.

13. **External dependencies that materially affect architecture**
   - MySQL is the system of record.
   - JWT and bcrypt define identity and credential handling.
   - The README also indicates an AI categorization capability via Google/Grok-style API integration, which makes complaint intake partially asynchronous/intelligent rather than purely CRUD.

14. **Diagramming takeaway**
   - The cleanest architecture diagram is: React client at the edge; Express API in the middle with auth/role middleware; MySQL as persistence; optional AI categorization service in the complaint intake path; and three role-based user flows layered over the same API and database.

Main entry points: [`frontend/src/App.jsx`](https://github.com/akashakula327/major_project/blob/master/frontend/src/App.jsx) (App shell), [`backend/routes/authRoutes.js`](https://github.com/akashakula327/major_project/blob/master/backend/routes/authRoutes.js) (API routes), [`frontend/src/config/api.js`](https://github.com/akashakula327/major_project/blob/master/frontend/src/config/api.js) (API config), [`backend/config/db.js`](https://github.com/akashakula327/major_project/blob/master/backend/config/db.js) (MySQL config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_fe_main["main<br/>React entry<br/>[main.jsx]"]
  node_fe_app["App shell<br/>React router<br/>[App.jsx]"]
  node_fe_api["API config<br/>HTTP client config<br/>[api.js]"]
  node_fe_auth_ctx["Auth state<br/>React context<br/>[AuthContext.jsx]"]
  node_fe_complaint_ctx["Complaint state<br/>React context"]
  node_fe_protected["Protected route<br/>Route guard<br/>[ProtectedRoute.jsx]"]
  node_fe_layout["Dashboard layout<br/>Shell component"]
  node_fe_nav["Navbar<br/>UI component<br/>[Navbar.jsx]"]
  node_fe_login["Login<br/>Auth page<br/>[Login.jsx]"]
  node_fe_register["Register<br/>Auth page<br/>[Register.jsx]"]
  node_fe_submit["Submit complaint<br/>Citizen page"]
  node_fe_dashboard["Dashboard<br/>Citizen page<br/>[Dashboard.jsx]"]
  node_fe_officer["Officer queue<br/>Officer page"]
  node_fe_admin["Admin console<br/>Admin page"]
  node_fe_roles["UI constants<br/>Shared vocab<br/>[roles.js]"]
end

subgraph group_backend["Backend"]
  node_be_server["Server<br/>Express entry<br/>[Server.js]"]
  node_be_db[("MySQL config<br/>DB connection<br/>[db.js]")]
  node_be_routes["API routes<br/>HTTP routing<br/>[authRoutes.js]"]
  node_be_auth_mw["Auth middleware<br/>JWT middleware<br/>[authMiddleware.js]"]
  node_be_role_mw["Role middleware<br/>RBAC middleware<br/>[roleMiddleware.js]"]
  node_be_auth_ctrl["Auth controller<br/>Auth logic<br/>[authController.js]"]
  node_be_complaint_ctrl["Complaint controller<br/>Complaint logic"]
  node_be_officer_ctrl["Officer controller<br/>Officer logic"]
  node_be_admin_ctrl["Admin controller<br/>Admin logic<br/>[adminController.js]"]
  node_be_roles["Domain constants<br/>Shared vocab<br/>[roles.js]"]
end

subgraph group_external["External services"]
  node_db_mysql[("MySQL<br/>Persistence")]
  node_svc_jwt{{"JWT<br/>Identity token"}}
  node_svc_bcrypt{{"bcrypt<br/>Credential hashing"}}
  node_svc_ai{{"AI categorizer<br/>Classification service"}}
end

node_fe_main -->|"boots"| node_fe_app
node_fe_app -->|"guards"| node_fe_protected
node_fe_app -->|"uses"| node_fe_layout
node_fe_layout -->|"includes"| node_fe_nav
node_fe_app -->|"routes"| node_fe_login
node_fe_app -->|"routes"| node_fe_register
node_fe_app -->|"routes"| node_fe_submit
node_fe_app -->|"routes"| node_fe_dashboard
node_fe_app -->|"routes"| node_fe_officer
node_fe_app -->|"routes"| node_fe_admin
node_fe_login -->|"calls"| node_fe_api
node_fe_register -->|"calls"| node_fe_api
node_fe_submit -->|"calls"| node_fe_api
node_fe_dashboard -->|"calls"| node_fe_api
node_fe_officer -->|"calls"| node_fe_api
node_fe_admin -->|"calls"| node_fe_api
node_fe_auth_ctx -->|"feeds"| node_fe_protected
node_fe_complaint_ctx -->|"feeds"| node_fe_dashboard
node_be_server -->|"mounts"| node_be_routes
node_be_routes -->|"protects"| node_be_auth_mw
node_be_routes -->|"authorizes"| node_be_role_mw
node_be_routes -->|"delegates"| node_be_auth_ctrl
node_be_routes -->|"delegates"| node_be_complaint_ctrl
node_be_routes -->|"delegates"| node_be_officer_ctrl
node_be_routes -->|"delegates"| node_be_admin_ctrl
node_be_auth_ctrl -->|"reads/writes"| node_be_db
node_be_complaint_ctrl -->|"reads/writes"| node_be_db
node_be_officer_ctrl -->|"reads/writes"| node_be_db
node_be_admin_ctrl -->|"reads/writes"| node_be_db
node_be_auth_ctrl -->|"uses"| node_svc_bcrypt
node_be_auth_ctrl -->|"issues"| node_svc_jwt
node_be_auth_mw -->|"verifies"| node_svc_jwt
node_be_complaint_ctrl -.->|"categorizes"| node_svc_ai
node_be_roles -.->|"mirrors"| node_fe_roles
node_be_db -->|"connects to"| node_db_mysql

click node_fe_main "https://github.com/akashakula327/major_project/blob/master/frontend/src/main.jsx"
click node_fe_app "https://github.com/akashakula327/major_project/blob/master/frontend/src/App.jsx"
click node_fe_api "https://github.com/akashakula327/major_project/blob/master/frontend/src/config/api.js"
click node_fe_auth_ctx "https://github.com/akashakula327/major_project/blob/master/frontend/src/contexts/AuthContext.jsx"
click node_fe_complaint_ctx "https://github.com/akashakula327/major_project/blob/master/frontend/src/contexts/ComplaintContext.jsx"
click node_fe_protected "https://github.com/akashakula327/major_project/blob/master/frontend/src/components/ProtectedRoute.jsx"
click node_fe_layout "https://github.com/akashakula327/major_project/blob/master/frontend/src/components/DashboardLayout.jsx"
click node_fe_nav "https://github.com/akashakula327/major_project/blob/master/frontend/src/components/Navbar.jsx"
click node_fe_login "https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/Login.jsx"
click node_fe_register "https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/Register.jsx"
click node_fe_submit "https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/SubmitComplaint.jsx"
click node_fe_dashboard "https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/Dashboard.jsx"
click node_fe_officer "https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/OfficerComplaints.jsx"
click node_fe_admin "https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/AdminComplaints.jsx"
click node_fe_roles "https://github.com/akashakula327/major_project/blob/master/frontend/src/constants/roles.js"
click node_be_server "https://github.com/akashakula327/major_project/blob/master/backend/Server.js"
click node_be_db "https://github.com/akashakula327/major_project/blob/master/backend/config/db.js"
click node_be_routes "https://github.com/akashakula327/major_project/blob/master/backend/routes/authRoutes.js"
click node_be_auth_mw "https://github.com/akashakula327/major_project/blob/master/backend/middleware/authMiddleware.js"
click node_be_role_mw "https://github.com/akashakula327/major_project/blob/master/backend/middleware/roleMiddleware.js"
click node_be_auth_ctrl "https://github.com/akashakula327/major_project/blob/master/backend/controllers/authController.js"
click node_be_complaint_ctrl "https://github.com/akashakula327/major_project/blob/master/backend/controllers/complaintController.js"
click node_be_officer_ctrl "https://github.com/akashakula327/major_project/blob/master/backend/controllers/officerController.js"
click node_be_admin_ctrl "https://github.com/akashakula327/major_project/blob/master/backend/controllers/adminController.js"
click node_be_roles "https://github.com/akashakula327/major_project/blob/master/backend/constants/roles.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_fe_main,node_fe_app,node_fe_api,node_fe_auth_ctx,node_fe_complaint_ctx,node_fe_protected,node_fe_layout,node_fe_nav,node_fe_login,node_fe_register,node_fe_submit,node_fe_dashboard,node_fe_officer,node_fe_admin,node_fe_roles toneBlue
class node_be_server,node_be_db,node_be_routes,node_be_auth_mw,node_be_role_mw,node_be_auth_ctrl,node_be_complaint_ctrl,node_be_officer_ctrl,node_be_admin_ctrl,node_be_roles toneAmber
class node_db_mysql,node_svc_jwt,node_svc_bcrypt,node_svc_ai toneMint
```

## Components

### Frontend

React client, UI state, and route-level screens.

- [main](https://github.com/akashakula327/major_project/blob/master/frontend/src/main.jsx): React entry · Bootstraps the Vite React application. · `frontend/src/main.jsx`
- [App shell](https://github.com/akashakula327/major_project/blob/master/frontend/src/App.jsx): React router · Top-level app composition and routing. · `frontend/src/App.jsx`
- [API config](https://github.com/akashakula327/major_project/blob/master/frontend/src/config/api.js): HTTP client config · Central backend base URL and request setup. · `frontend/src/config/api.js`
- [Auth state](https://github.com/akashakula327/major_project/blob/master/frontend/src/contexts/AuthContext.jsx): React context · Session, user identity, and auth state. · `frontend/src/contexts/AuthContext.jsx`
- [Complaint state](https://github.com/akashakula327/major_project/blob/master/frontend/src/contexts/ComplaintContext.jsx): React context · Shared complaint data and client-side complaint state. · `frontend/src/contexts/ComplaintContext.jsx`
- [Protected route](https://github.com/akashakula327/major_project/blob/master/frontend/src/components/ProtectedRoute.jsx): Route guard · Blocks access unless the user is authenticated and authorized. · `frontend/src/components/ProtectedRoute.jsx`
- [Dashboard layout](https://github.com/akashakula327/major_project/blob/master/frontend/src/components/DashboardLayout.jsx): Shell component · Shared authenticated layout and navigation frame. · `frontend/src/components/DashboardLayout.jsx`
- [Navbar](https://github.com/akashakula327/major_project/blob/master/frontend/src/components/Navbar.jsx): UI component · Top-level navigation for the app shell. · `frontend/src/components/Navbar.jsx`
- [Login](https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/Login.jsx): Auth page · User sign-in screen. · `frontend/src/pages/Login.jsx`
- [Register](https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/Register.jsx): Auth page · User registration screen. · `frontend/src/pages/Register.jsx`
- [Submit complaint](https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/SubmitComplaint.jsx): Citizen page · Citizen complaint intake form. · `frontend/src/pages/SubmitComplaint.jsx`
- [Dashboard](https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/Dashboard.jsx): Citizen page · Citizen complaint status and history view. · `frontend/src/pages/Dashboard.jsx`
- [Officer queue](https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/OfficerComplaints.jsx): Officer page · Officer complaint list and status update view. · `frontend/src/pages/OfficerComplaints.jsx`
- [Admin console](https://github.com/akashakula327/major_project/blob/master/frontend/src/pages/AdminComplaints.jsx): Admin page · Complaint oversight, citizen management, and officer management entry. · `frontend/src/pages/AdminComplaints.jsx`
- [UI constants](https://github.com/akashakula327/major_project/blob/master/frontend/src/constants/roles.js): Shared vocab · Frontend role, status, and specialization constants. · `frontend/src/constants/roles.js`

### Backend

Express API, security middleware, controllers, and database access.

- [Server](https://github.com/akashakula327/major_project/blob/master/backend/Server.js): Express entry · Node.js/Express application entry point. · `backend/Server.js`
- [MySQL config](https://github.com/akashakula327/major_project/blob/master/backend/config/db.js): DB connection · Central MySQL connection and database access setup. · `backend/config/db.js`
- [API routes](https://github.com/akashakula327/major_project/blob/master/backend/routes/authRoutes.js): HTTP routing · Domain route modules for auth, complaints, officer, and admin. · `backend/routes/authRoutes.js`
- [Auth middleware](https://github.com/akashakula327/major_project/blob/master/backend/middleware/authMiddleware.js): JWT middleware · Verifies authenticated requests using tokens. · `backend/middleware/authMiddleware.js`
- [Role middleware](https://github.com/akashakula327/major_project/blob/master/backend/middleware/roleMiddleware.js): RBAC middleware · Enforces role-based access control. · `backend/middleware/roleMiddleware.js`
- [Auth controller](https://github.com/akashakula327/major_project/blob/master/backend/controllers/authController.js): Auth logic · Registration and login business logic. · `backend/controllers/authController.js`
- [Complaint controller](https://github.com/akashakula327/major_project/blob/master/backend/controllers/complaintController.js): Complaint logic · Complaint submission, retrieval, categorization, and assignment flow. · `backend/controllers/complaintController.js`
- [Officer controller](https://github.com/akashakula327/major_project/blob/master/backend/controllers/officerController.js): Officer logic · Officer-scoped complaint access and status updates. · `backend/controllers/officerController.js`
- [Admin controller](https://github.com/akashakula327/major_project/blob/master/backend/controllers/adminController.js): Admin logic · User management and manual assignment flows. · `backend/controllers/adminController.js`
- [Domain constants](https://github.com/akashakula327/major_project/blob/master/backend/constants/roles.js): Shared vocab · Backend role, status, and specialization constants. · `backend/constants/roles.js`

### External services

Runtime and infrastructure dependencies outside the repository.

- **MySQL**: Persistence · System of record for users, roles, and complaints.
- **JWT**: Identity token · Authentication token mechanism.
- **bcrypt**: Credential hashing · Password hashing and verification.
- **AI categorizer**: Classification service · Complaint categorization and routing assistance in the intake path.

## Connections

- main → App shell: boots · The entry point renders the app shell.
- App shell → Protected route: guards · Protected areas are wrapped by route guards.
- App shell → Dashboard layout: uses · Authenticated screens share a common layout.
- Dashboard layout → Navbar: includes · The dashboard shell includes navigation.
- App shell → Login: routes · Public auth entry points.
- App shell → Register: routes · Public auth entry points.
- App shell → Submit complaint: routes · Citizen complaint intake.
- App shell → Dashboard: routes · Citizen complaint status and history.
- App shell → Officer queue: routes · Officer workflow screen.
- App shell → Admin console: routes · Admin workflow screen.
- Login → API config: calls · Authentication requests use the shared API config.
- Register → API config: calls · Registration requests use the shared API config.
- Submit complaint → API config: calls · Complaint intake posts to the backend API.
- Dashboard → API config: calls · Citizen complaint queries and refreshes.
- Officer queue → API config: calls · Officer complaint retrieval and updates.
- Admin console → API config: calls · Admin management operations.
- Auth state → Protected route: feeds · Route protection depends on auth state.
- Complaint state → Dashboard: feeds · Complaint state powers citizen views.
- Server → API routes: mounts · The Express entry point mounts route modules.
- API routes → Auth middleware: protects · Authenticated routes pass through JWT verification.
- API routes → Role middleware: authorizes · Role checks gate officer/admin/citizen boundaries.
- API routes → Auth controller: delegates · Auth endpoints delegate to auth logic.
- API routes → Complaint controller: delegates · Complaint endpoints delegate to complaint logic.
- API routes → Officer controller: delegates · Officer endpoints delegate to officer logic.
- API routes → Admin controller: delegates · Admin endpoints delegate to admin logic.
- Auth controller → MySQL config: reads/writes · Auth operations access the database.
- Complaint controller → MySQL config: reads/writes · Complaint workflow persists to the database.
- Officer controller → MySQL config: reads/writes · Officer views and updates are database-backed.
- Admin controller → MySQL config: reads/writes · Admin user and assignment management is database-backed.
- Auth controller → bcrypt: uses · Credentials are hashed and verified.
- Auth controller → JWT: issues · Successful login returns JWTs.
- Auth middleware → JWT: verifies · Request authentication depends on JWT validation.
- Complaint controller → AI categorizer: categorizes · Complaint intake may use AI-assisted categorization and assignment.
- Domain constants → UI constants: mirrors · Frontend and backend share the same business vocabulary.
- MySQL config → MySQL: connects to · The backend stores data in MySQL.
