How ruturaj2005/genai-project works
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: routes Routes · axios.js API client · models Models · report.service.js Report service
Components 25
Client
React/Vite presentation layer
- React app · Browser UI shell and routing
client/src/App.jsx - Auth context · Holds session and role state for the UI
client/src/context/AuthContext.jsx - API client · Centralized HTTP client for backend calls
client/src/api/axios.js - Login · User sign-in screen
client/src/pages/Login.jsx - Register · User and club registration screen
client/src/pages/Register.jsx - Dashboard · Club admin workspace
client/src/pages/ClubDashboard.jsx - Event form · Create and edit event records
client/src/pages/EventForm.jsx - SDW panel · SDW admin review and approval UI
client/src/pages/SDWAdminPanel.jsx - Super panel · Super admin management UI
client/src/pages/SuperAdminPanel.jsx
Server
Express API and backend services
- Routes · HTTP entry points for each domain
server/routes - Auth guard · JWT authentication enforcement
server/middleware/auth.middleware.js - Role guard · Role and approval authorization checks
server/middleware/role.middleware.js - Auth controller · Login and registration flows
server/controllers/auth.controller.js - Event controller · Event creation and update actions
server/controllers/event.controller.js - Report controller · Report review and generation endpoints
server/controllers/report.controller.js - Admin controller · SDW approval and template management
server/controllers/admin.controller.js - Super controller · Super admin coordinator and stats actions
server/controllers/superadmin.controller.js - LLM service · Hugging Face inference integration and fallback logic
server/services/llm.service.js - Report service · Template filling, image embedding, and file output
server/services/report.service.js - Models · User, Club, Event, and Report schemas
server/models - Template DOCX · Institutional Word template for generated reports
server/templates/bccoe_template.docx - Uploads · Transient image storage for event assets
server/uploads - Reports · Generated report output directory
server/reports
External
Databases and third-party services
- MongoDB · Persistent storage for users, clubs, events, and reports
- Hugging Face · Inference service used for AI-generated content
Connections 28
- 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