How siddhi2321/citizen_grivevance_system works
Project Type and Purpose
– This is a full-stack, role-based grievance redressal portal (“Citizens Grievance System”) with a React/Vite single-page application frontend and an Express/Node.js backend.
– It uses MongoDB for persistent storage, Cloudinary for file uploads, and an email service for notifications.
Main Architectural Layers
a. Client Layer (Frontend)
• React SPA built with Vite in frontend/src/…
• Components, pages (citizen/admin/officer), context (AuthContext), and hooks (useSession)
• API service abstraction in frontend/src/services/api.js
b. API Layer (Backend)
• Express.js server in backend/index.js
• Route definitions in backend/routes/*.js (auth, complaints, admin, officer, session, logout)
• Controllers in backend/controllers/*.js encapsulate business logic
• Middleware in backend/middleware/*.js enforces sessions and role-based access
c. Data Layer
• MongoDB collections via Mongoose models in backend/models/*.js (User, Officer, Admin, Complaint, OTP)
• DB connection boilerplate in backend/connection/db.js
d. Supporting Services
• File storage: Cloudinary integration in backend/utils/cloudinary.js (images are stored remotely)
• Email notifications: backend/utils/sendEmail.js
• Session persistence (via Express-session or JWT, implied by session controllers/middleware)
Component Interactions
– Browser/React → HTTP(S) requests → Express Routes → Controllers → Models → MongoDB
– Controllers handling file attachments call Cloudinary SDK, then store URLs in MongoDB
– Controllers triggering emails call sendEmail.js → external SMTP provider
– Session middleware validates tokens/cookies on each request
Architectural Patterns
– Layered (Presentation → API → Business Logic → Data)
– MVC-style split (Routes → Controllers → Models)
– RESTful resource design (e.g., POST /api/complaints, GET /api/complaints/:id)
– Role-based access control via middleware (requireSession, requireAdminSession, requireOfficer)