How mda1458/hostel-mern works
Project type and purpose
• This is a full-stack MERN (MongoDB, Express, React, Node.js) application called “Hostel Management System.”
• Purpose: Provide an admin panel and student portal to manage hostel functions—user authentication, attendance tracking, complaints, mess management, invoices, suggestions, and mess-off requests.
File structure
• Top-level directories:
• backend/ – Express API server using MVC structure (controllers, models, routes, utils).
• client/ – React application scaffolded with Vite; Tailwind CSS for styling.
• mongoCollections/ – JSON fixtures for seeding MongoDB.
• backend/ highlights:
• index.js – entry point that initializes Express, connects to MongoDB (via utils/conn.js), wires up auth middleware (utils/auth.js), and mounts route modules.
• controllers/ – per-resource logic (e.g. attendanceController.js).
• routes/ – RESTful endpoints grouped by resource.
• models/ – Mongoose schemas (Student, User, Attendance, etc.) loaded in models/index.js.
• client/ highlights:
• src/ – React components organized by feature: LandingSite, AuthPage, AdminDashboard, StudentDashboard.
• src/utils – helper functions (session verification, API wrappers).
• Tailwind + Vite config, index.html entry.
README for additional insights
• Confirms MERN stack, JWT-based auth (JWT_SECRET).
• Suggests development flow: concurrently runs client and server.
• MongoDB database named “hostel” with collections matching JSON fixtures.
a. Main components:
1. React Frontend (client)
– Landing pages, authentication forms, admin & student dashboards.
– Uses Axios or fetch to call backend endpoints.
2. Node.js/Express Backend (server)
– Route layer (routes/*.js) → Controller layer → Model layer (Mongoose).
– Auth module enforces JWT validation.
3. Database: MongoDB
– Collections: users, students, attendances, complaints, messoffs, invoices, requests, suggestions, hostels.
4. External services & tooling
– JWT identity provider (self-signed secret).
– optional: Email or third-party integrations (if added later).
– Development tools: concurrently, Vite dev server.
b. Relationships & data flow
• User interacts with React UI → sends HTTP(S) request (REST) to Express API → auth middleware verifies JWT → routed to appropriate controller → controller reads/writes to MongoDB via Mongoose models → response flows back to client → UI updates.
• Admin actions (e.g., register student, mark attendance) invoke dedicated adminRoutes → adminController.
• Student actions (view invoice, lodge complaint) use studentRoutes → studentController.
c. Architectural patterns & design principles
• Frontend: Component-based architecture with separation of concerns (LandingSite vs Dashboard vs Common components).
• Backend: MVC-inspired layering (models/controllers/routes), single-page API design (stateless REST).
• Authentication: JWT-based stateless tokens, middleware enforcement.
• Configuration: .env for secrets, central utils for DB connection.
• Data seeding: JSON fixtures for easy environment setup.
d. Key technologies & frameworks
• React, Vite, Tailwind CSS on client.
• Node.js, Express, Mongoose on server.
• MongoDB database.
• JWT for auth.
• Concurrently to run parallel dev servers.
Final advice
• Every major module from your file tree (e.g., studentRoutes.js → StudentController → Student model).
• Shared utilities (e.g., auth.js middleware, conn.js).
• Avoid clutter: group similar controllers or components under logical umbrellas (e.g., “Complaint Management”).