# ruturaj2005/genai-project architecture

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

- Interactive diagram: https://gitdiagram.com/ruturaj2005/genai-project
- Repository: https://github.com/ruturaj2005/genai-project

## Overview

1. **Overall shape**
   - ClubReport is a two-tier full-stack app: a **React/Vite client** in `client/` and an **Express/MongoDB API** in `server/`.
   - The backend owns all persistent data, role enforcement, AI calls, and DOCX generation; the frontend is a thin UI layer that talks to it over HTTP.

2. **Frontend boundary**
   - The client is organized by **pages, reusable components, API wrapper, and auth context**.
   - `AuthContext` likely holds the current user/token and drives role-based navigation.
   - `axios.js` centralizes API calls to the backend base URL from environment config.
   - Main UI surfaces are `Login`, `Register`, `ClubDashboard`, `EventForm`, `SDWAdminPanel`, and `SuperAdminPanel`.

3. **Backend API boundary**
   - The server is structured around **routes → controllers → models/services**.
   - Each domain has its own route and controller layer: `auth`, `club`, `event`, `report`, `admin`, and `superadmin`.
   - Cross-cutting enforcement lives in `auth.middleware.js` and `role.middleware.js`, which gate endpoints by JWT identity and role.

4. **Core data model**
   - MongoDB stores four primary entities: **User, Club, Event, and Report**.
   - The user model supports the role hierarchy used by the app: `super_admin`, `sdw_admin`, and `club_admin`.
   - Clubs and events are the main business objects; reports are generated artifacts linked back to events.

5. **Authentication and authorization flow**
   - Authentication uses **JWT + bcryptjs**.
   - Users register/login through the auth routes; successful login returns identity/role data used by the frontend.
   - Authorization is not just login-based: event/report/admin actions are restricted by role and, for clubs, by approval status.

6. **Club administration workflow**
   - Club admins can self-register, but their operational access is limited until an **SDW coordinator approves the club**.
   - The SDW admin panel is the control point for approving clubs and reviewing club/report data.
   - This creates a clear governance boundary: club content is created locally by clubs, but organizational approval is centralized.

7. **Event lifecycle**
   - Club admins create and edit event records through the event form/dashboard.
   - Events can include uploaded images and structured metadata such as title, date, duration, timeline, type, and guest details.
   - There is an AI-assisted step for generating event objectives/content via the backend `llm.service.js`.

8. **AI-assisted report content**
   - The backend integrates with the **Hugging Face Inference API** using model settings from `.env`.
   - `llm.service.js` and `report.service.js` handle fallback behavior if generation is slow or fails.
   - The AI is used for narrative content, while the rest of the report structure remains deterministic and template-driven.

9. **DOCX report generation pipeline**
   - Final reports are produced from a fixed institutional Word template in `server/templates/bccoe_template.docx`.
   - The report service fills placeholders with event data, AI-generated text, and embedded event images using **docxtemplater + pizzip + image module**.
   - Generated files are written to `server/reports/`, and uploaded images are cleaned up after generation to keep storage transient.

10. **Admin and super-admin responsibilities**
   - `sdw_admin` endpoints support club approval, report review/filtering, and template management.
   - `super_admin` endpoints manage SDW coordinators and provide system stats.
   - A seed script creates the initial super admin account, establishing the root of the role hierarchy.

11. **Operational dependencies**
   - The app depends on **MongoDB**, a **Hugging Face API key**, and a locally stored DOCX template.
   - `server/uploads/` and `server/reports/` are filesystem-based working areas rather than external object storage.
   - The architecture is therefore centered on a local Node process, a MongoDB database, and an external AI inference service.

12. **Key architectural boundary for a diagram**
   - The most important data flow is: **React UI → Express API → MongoDB / Hugging Face / DOCX template engine → downloadable report**.
   - The main trust boundary is enforced on the server: UI state is convenient, but permissions and report generation all happen in backend controllers and services.

Main entry points: [`server/routes`](https://github.com/ruturaj2005/genai-project/tree/main/server/routes) (Routes), [`client/src/api/axios.js`](https://github.com/ruturaj2005/genai-project/blob/main/client/src/api/axios.js) (API client), [`server/models`](https://github.com/ruturaj2005/genai-project/tree/main/server/models) (Models), [`server/services/report.service.js`](https://github.com/ruturaj2005/genai-project/blob/main/server/services/report.service.js) (Report service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_app["React app<br/>Vite SPA<br/>[App.jsx]"]
  node_client_auth(("Auth context<br/>state<br/>[AuthContext.jsx]"))
  node_client_api["API client<br/>axios wrapper<br/>[axios.js]"]
  node_client_login["Login<br/>page<br/>[Login.jsx]"]
  node_client_register["Register<br/>page<br/>[Register.jsx]"]
  node_client_dashboard["Dashboard<br/>page<br/>[ClubDashboard.jsx]"]
  node_client_eventform["Event form<br/>page<br/>[EventForm.jsx]"]
  node_client_sdw["SDW panel<br/>page<br/>[SDWAdminPanel.jsx]"]
  node_client_super["Super panel<br/>page"]
end

subgraph group_server["Server"]
  node_server_routes["Routes"]
  node_server_authmw{{"Auth guard<br/>middleware<br/>[auth.middleware.js]"}}
  node_server_rolemw{{"Role guard<br/>middleware<br/>[role.middleware.js]"}}
  node_server_authc["Auth controller<br/>[auth.controller.js]"]
  node_server_eventc["Event controller"]
  node_server_reportc["Report controller"]
  node_server_adminc["Admin controller"]
  node_server_superc["Super controller"]
  node_server_llm["LLM service<br/>AI service<br/>[llm.service.js]"]
  node_server_reportsvc["Report service<br/>DOCX pipeline<br/>[report.service.js]"]
  node_server_models[("Models")]
  node_server_template["Template DOCX<br/>file asset"]
  node_server_uploads[("Uploads<br/>filesystem")]
  node_server_reports[("Reports<br/>filesystem")]
end

subgraph group_external["External"]
  node_mongodb[("MongoDB<br/>database")]
  node_huggingface(("Hugging Face<br/>external API"))
end

node_client_app -->|"session state"| node_client_auth
node_client_app -->|"HTTP"| node_client_api
node_client_login -->|"auth calls"| node_client_api
node_client_register -->|"signup calls"| node_client_api
node_client_dashboard -->|"club data"| node_client_api
node_client_eventform -->|"event data"| node_client_api
node_client_sdw -->|"admin data"| node_client_api
node_client_super -->|"system data"| node_client_api
node_server_routes -->|"protects"| node_server_authmw
node_server_routes -->|"restricts"| node_server_rolemw
node_server_routes -->|"auth"| node_server_authc
node_server_routes -->|"events"| node_server_eventc
node_server_routes -->|"reports"| node_server_reportc
node_server_routes -->|"sdw admin"| node_server_adminc
node_server_routes -->|"super admin"| node_server_superc
node_server_authc -->|"users"| node_server_models
node_server_eventc -->|"events"| node_server_models
node_server_reportc -->|"reports"| node_server_models
node_server_adminc -->|"clubs"| node_server_models
node_server_superc -->|"admins"| node_server_models
node_server_reportc -->|"generate text"| node_server_llm
node_server_reportc -->|"build docx"| node_server_reportsvc
node_server_reportsvc -->|"template"| node_server_template
node_server_reportsvc -->|"images"| node_server_uploads
node_server_reportsvc -->|"output"| node_server_reports
node_server_models -->|"persist"| node_mongodb
node_server_llm -->|"inference"| node_huggingface
node_server_reportsvc -.->|"fallback dependency"| node_huggingface

click node_client_app "https://github.com/ruturaj2005/genai-project/blob/main/client/src/App.jsx"
click node_client_auth "https://github.com/ruturaj2005/genai-project/blob/main/client/src/context/AuthContext.jsx"
click node_client_api "https://github.com/ruturaj2005/genai-project/blob/main/client/src/api/axios.js"
click node_client_login "https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/Login.jsx"
click node_client_register "https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/Register.jsx"
click node_client_dashboard "https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/ClubDashboard.jsx"
click node_client_eventform "https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/EventForm.jsx"
click node_client_sdw "https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/SDWAdminPanel.jsx"
click node_client_super "https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/SuperAdminPanel.jsx"
click node_server_routes "https://github.com/ruturaj2005/genai-project/tree/main/server/routes"
click node_server_authmw "https://github.com/ruturaj2005/genai-project/blob/main/server/middleware/auth.middleware.js"
click node_server_rolemw "https://github.com/ruturaj2005/genai-project/blob/main/server/middleware/role.middleware.js"
click node_server_authc "https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/auth.controller.js"
click node_server_eventc "https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/event.controller.js"
click node_server_reportc "https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/report.controller.js"
click node_server_adminc "https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/admin.controller.js"
click node_server_superc "https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/superadmin.controller.js"
click node_server_llm "https://github.com/ruturaj2005/genai-project/blob/main/server/services/llm.service.js"
click node_server_reportsvc "https://github.com/ruturaj2005/genai-project/blob/main/server/services/report.service.js"
click node_server_models "https://github.com/ruturaj2005/genai-project/tree/main/server/models"
click node_server_template "https://github.com/ruturaj2005/genai-project/blob/main/server/templates/bccoe_template.docx"
click node_server_uploads "https://github.com/ruturaj2005/genai-project/tree/main/server/uploads"
click node_server_reports "https://github.com/ruturaj2005/genai-project/tree/main/server/reports"

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_auth,node_client_api,node_client_login,node_client_register,node_client_dashboard,node_client_eventform,node_client_sdw,node_client_super toneBlue
class node_server_routes,node_server_authmw,node_server_rolemw,node_server_authc,node_server_eventc,node_server_reportc,node_server_adminc,node_server_superc,node_server_llm,node_server_reportsvc,node_server_models,node_server_template,node_server_uploads,node_server_reports toneAmber
class node_mongodb,node_huggingface toneMint
```

## Components

### Client

React/Vite presentation layer

- [React app](https://github.com/ruturaj2005/genai-project/blob/main/client/src/App.jsx): Vite SPA · Browser UI shell and routing · `client/src/App.jsx`
- [Auth context](https://github.com/ruturaj2005/genai-project/blob/main/client/src/context/AuthContext.jsx): state · Holds session and role state for the UI · `client/src/context/AuthContext.jsx`
- [API client](https://github.com/ruturaj2005/genai-project/blob/main/client/src/api/axios.js): axios wrapper · Centralized HTTP client for backend calls · `client/src/api/axios.js`
- [Login](https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/Login.jsx): page · User sign-in screen · `client/src/pages/Login.jsx`
- [Register](https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/Register.jsx): page · User and club registration screen · `client/src/pages/Register.jsx`
- [Dashboard](https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/ClubDashboard.jsx): page · Club admin workspace · `client/src/pages/ClubDashboard.jsx`
- [Event form](https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/EventForm.jsx): page · Create and edit event records · `client/src/pages/EventForm.jsx`
- [SDW panel](https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/SDWAdminPanel.jsx): page · SDW admin review and approval UI · `client/src/pages/SDWAdminPanel.jsx`
- [Super panel](https://github.com/ruturaj2005/genai-project/blob/main/client/src/pages/SuperAdminPanel.jsx): page · Super admin management UI · `client/src/pages/SuperAdminPanel.jsx`

### Server

Express API and backend services

- [Routes](https://github.com/ruturaj2005/genai-project/tree/main/server/routes): Express routes · HTTP entry points for each domain · `server/routes`
- [Auth guard](https://github.com/ruturaj2005/genai-project/blob/main/server/middleware/auth.middleware.js): middleware · JWT authentication enforcement · `server/middleware/auth.middleware.js`
- [Role guard](https://github.com/ruturaj2005/genai-project/blob/main/server/middleware/role.middleware.js): middleware · Role and approval authorization checks · `server/middleware/role.middleware.js`
- [Auth controller](https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/auth.controller.js): controller · Login and registration flows · `server/controllers/auth.controller.js`
- [Event controller](https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/event.controller.js): controller · Event creation and update actions · `server/controllers/event.controller.js`
- [Report controller](https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/report.controller.js): controller · Report review and generation endpoints · `server/controllers/report.controller.js`
- [Admin controller](https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/admin.controller.js): controller · SDW approval and template management · `server/controllers/admin.controller.js`
- [Super controller](https://github.com/ruturaj2005/genai-project/blob/main/server/controllers/superadmin.controller.js): controller · Super admin coordinator and stats actions · `server/controllers/superadmin.controller.js`
- [LLM service](https://github.com/ruturaj2005/genai-project/blob/main/server/services/llm.service.js): AI service · Hugging Face inference integration and fallback logic · `server/services/llm.service.js`
- [Report service](https://github.com/ruturaj2005/genai-project/blob/main/server/services/report.service.js): DOCX pipeline · Template filling, image embedding, and file output · `server/services/report.service.js`
- [Models](https://github.com/ruturaj2005/genai-project/tree/main/server/models): Mongo models · User, Club, Event, and Report schemas · `server/models`
- [Template DOCX](https://github.com/ruturaj2005/genai-project/blob/main/server/templates/bccoe_template.docx): file asset · Institutional Word template for generated reports · `server/templates/bccoe_template.docx`
- [Uploads](https://github.com/ruturaj2005/genai-project/tree/main/server/uploads): filesystem · Transient image storage for event assets · `server/uploads`
- [Reports](https://github.com/ruturaj2005/genai-project/tree/main/server/reports): filesystem · Generated report output directory · `server/reports`

### External

Databases and third-party services

- **MongoDB**: database · Persistent storage for users, clubs, events, and reports
- **Hugging Face**: external API · Inference service used for AI-generated content

## Connections

- React app → Auth context: session state · UI reads identity and role information
- React app → API client: HTTP · Pages call the shared backend client
- Login → API client: auth calls · Submits login requests
- Register → API client: signup calls · Submits registration requests
- Dashboard → API client: club data · Loads and updates club-related data
- Event form → API client: event data · Creates and edits event records
- SDW panel → API client: admin data · Approves clubs and reviews reports
- Super panel → API client: system data · Manages coordinators and stats
- Routes → Auth guard: protects · Routes apply JWT authentication where required
- Routes → Role guard: restricts · Routes apply role and approval checks
- Routes → Auth controller: auth · Auth routes dispatch to controller actions
- Routes → Event controller: events · Event routes dispatch to controller actions
- Routes → Report controller: reports · Report routes dispatch to controller actions
- Routes → Admin controller: sdw admin · Admin routes dispatch to controller actions
- Routes → Super controller: super admin · Superadmin routes dispatch to controller actions
- Auth controller → Models: users · Authenticates and persists user records
- Event controller → Models: events · Reads and writes event records
- Report controller → Models: reports · Reads event and report data
- Admin controller → Models: clubs · Approves clubs and reviews related data
- Super controller → Models: admins · Manages coordinator accounts and stats
- Report controller → LLM service: generate text · Uses AI for narrative sections
- Report controller → Report service: build docx · Hands off final report assembly
- Report service → Template DOCX: template · Fills placeholders in the institutional DOCX
- Report service → Uploads: images · Consumes uploaded event images
- Report service → Reports: output · Writes generated report files
- Models → MongoDB: persist · MongoDB stores the primary domain entities
- LLM service → Hugging Face: inference · Calls external model endpoint
- Report service → Hugging Face: fallback dependency · Report pipeline depends on AI content generation path
