How mrrobot0412/campus_connect works
1. Overall shape
- This repo is split into two deployable applications: a Node/Express backend and a React/Vite frontend.
- The backend exposes a JSON API under /api/v1, while the frontend is a single-page app that consumes that API.
2. Primary runtime boundaries
- Backend entrypoint: backend/index.js starts the server and wires the Express app, MongoDB connection, and routes.
- Frontend entrypoint: testauto-main/src/main.jsx bootstraps the React app, with App.jsx handling page routing/component selection.
- There is also a backend/back/ tree that looks like an older/duplicate backend structure; the main architecture is centered on backend/src.
3. Backend layering
- The backend is organized into clear layers: config, middlewares, models, routes, utils, and queues.
- Request handling flows from Express routes to middleware checks, then into Mongoose models and utility helpers, with MongoDB as the system of record.
4. Authentication and identity flow
- Student onboarding uses a two-step OTP flow separate from normal login.
- otpRoutes handle OTP generation and verification; successful verification returns a JWT with a verified claim used to permit student registration.
- Login routes issue standard JWTs for student or teacher sessions, and authMiddleware protects authenticated endpoints.
5. OTP delivery and verification subsystem
- OTP records are stored in MongoDB via the EmailOtp model with a TTL-style expiry.
- OTP email delivery is handled by otpHelper.js, using Gmail SMTP per the README.
- The presence of otpQueue.js and otpWorker.js plus redis-config.js indicates the OTP process is also designed around an async queue/worker boundary, likely to offload email sending and add resilience.
6. Core data model
- The main persisted entities are students, teachers, email OTPs, and likely password resets and slots.
- Teacher documents carry profile data plus embedded arrays for specializations, research papers, and slots.
- Slot state is therefore mostly managed inside teacher records, while student bookings are retrieved through slot queries.
7. Appointment and availability flow
- slotsRoutes cover the lifecycle of availability and booking: adding slots, booking them, canceling them, and retrieving booked slots for a student.
- This is the core transactional boundary of the system: a student reserves a teacher’s availability, and the teacher can later manage or cancel that availability.
- The README notes this area currently has a concurrency risk because booking is non-atomic.
8. Teacher discovery and profile management
- teachersRoutes expose teacher lookup by ID and search/filter paths for name, department, specialization, paper, and availability.
- Authenticated teacher endpoints allow updating contact details and managing specialization/paper lists.
- A seed script suggests teacher data can be preloaded into MongoDB for initial discoverability.
9. Frontend application structure
- The frontend is a Vite-built React app with Tailwind styling.
- Components are organized by user flow: login, signup/OTP, password recovery screens, and dashboards for students and teachers.
- src/api.js is the API integration point, and the backend URL is environment-driven through VITE_API_URL.
10. User-facing flows represented in UI
- Student flow: sign up → OTP verify → register → login → browse/search teachers → book slots.
- Teacher flow: login → manage profile/availability → inspect booked appointments.
- The frontend also includes older components like DashBoard.jsx, which the README flags as stale relative to the current route set.
11. Infrastructure and external services
- MongoDB is the primary persistent datastore via Mongoose.
- JWT and bcryptjs provide authentication and password hashing.
- Gmail SMTP is the external email service used for OTP delivery.
- Redis appears in the backend config and queue files as supporting infrastructure for queued OTP processing.
12. Deployment boundary
- The project is intended to be deployed as two separate targets: backend API and frontend static app.
- Backend deployment depends on MongoDB, JWT secret, Gmail credentials, frontend origin allowlist, and possibly Redis.
- Frontend deployment is build-time configured to point at the backend API URL.
13. Notable architectural caveats
- Some endpoints are intentionally or accidentally unauthenticated, including teacher creation and slot update paths.
- There are duplicate/legacy route definitions in the backend, and a missing delete-slot endpoint referenced by the frontend.
- These do not change the main architecture, but they matter when diagramming trust boundaries and data flow risk.
Main entry points: v1/index.js v1 API · otpRoutes.js OTP flow · backend/index.js Server entry · loginRoutes.js Login
Components 26
Backend API
Node/Express service with MongoDB persistence, auth, OTP, and booking flows.
- Server entry · Starts the API server and wires configuration, database, and routes.
backend/index.js - Config · Loads server, database, and Redis settings.
backend/src/config/index.js - Route root · Mounts versioned API routes under the backend service.
backend/src/routes/index.js - v1 API · Primary JSON API namespace for login, OTP, slots, and teachers.
backend/src/routes/v1/index.js - Auth guard · Protects authenticated endpoints with JWT-based session checks.
backend/src/middlewares/authMiddleware.js - OTP guard · Validates OTP-related access and verification state.
backend/src/middlewares/otpMiddleware.js - Login · Student and teacher login, JWT issuance, and password recovery entry points.
backend/src/routes/v1/loginRoutes.js - OTP flow · Generates and verifies student OTPs for onboarding.
backend/src/routes/v1/otpRoutes.js - Teachers · Teacher lookup, search/filter, and profile management endpoints.
backend/src/routes/v1/teachersRoutes.js - Slots · Availability creation, booking, cancellation, and booked-slot retrieval.
backend/src/routes/v1/slotsRoutes.js - Student · Stores student identity and account data.
backend/src/models/student.js - Teacher · Stores teacher profiles, specializations, research papers, and slot data.
backend/src/models/teachers.js - Email OTP · Persists verification codes with expiry semantics.
backend/src/models/EmailOtp.js - Slot · Represents teacher availability and booking state.
backend/src/models/Slots.js - OTP mailer · Sends OTP email via Gmail SMTP.
backend/src/utils/otpHelper.js - OTP queue · Queues OTP work for asynchronous processing.
backend/src/queues/otpQueue.js - OTP worker · Consumes queued OTP jobs and performs delivery work.
backend/src/queues/otpWorker.js
Frontend SPA
React/Vite client for student and teacher user flows.
- React entry · Bootstraps the frontend application.
testauto-main/src/main.jsx - App shell · Selects pages and route-level screens for the SPA.
testauto-main/src/App.jsx - API client · Central integration point for backend requests, driven by environment config.
testauto-main/src/api.js - Student UI · Login, signup, OTP verification, password recovery, search, and booking screens.
testauto-main/src/components/Sign.jsx - Teacher UI · Teacher login and dashboard for profile and availability management.
testauto-main/src/components/DashTeacher.jsx
Infrastructure
External services and shared runtime dependencies used by the app.
- MongoDB · Primary system of record for users, OTPs, and bookings.
- Redis · Supporting infrastructure for queued OTP processing.
- JWT · Token format used for API session and verification claims.
- Gmail SMTP · External mail delivery service used for OTP messages.
Connections 35
- Server entry → Config: loads · Server startup consumes runtime configuration.
- Server entry → Route root: mounts · Express app attaches the API router tree.
- Route root → v1 API: delegates · Routes are organized under the v1 namespace.
- v1 API → Login: exposes · Login and recovery endpoints.
- v1 API → OTP flow: exposes · OTP generation and verification endpoints.
- v1 API → Teachers: exposes · Teacher search and profile endpoints.
- v1 API → Slots: exposes · Availability and booking endpoints.
- Login → Auth guard: uses · Authenticated login/session endpoints rely on JWT checks.
- OTP flow → OTP guard: uses · OTP onboarding flow enforces verification state.
- Teachers → Auth guard: uses · Teacher profile updates are protected by auth middleware.
- Slots → Auth guard: uses · Booking and management actions rely on authenticated access.
- Login → Student: reads/writes · Creates and validates student accounts.
- Login → Teacher: reads/writes · Authenticates teacher sessions.
- OTP flow → Email OTP: persists · Stores and verifies email OTP records.
- Teachers → Teacher: queries · Searches and updates teacher profiles.
- Slots → Slot: manages · Creates, books, cancels, and lists slots.
- Slots → Teacher: updates · Availability is embedded in teacher records as well as slot queries.
- OTP mailer → Gmail SMTP: sends via · Delivery uses Gmail SMTP.
- OTP flow → OTP mailer: calls · OTP generation triggers email delivery.
- OTP flow → OTP queue: enqueues · OTP work may be offloaded for asynchronous processing.
- OTP queue → Redis: backs onto · Queueing is supported by Redis.
- OTP worker → OTP queue: consumes · Background worker processes queued OTP jobs.
- OTP worker → OTP mailer: dispatches · Worker performs the actual email send.
- Server entry → MongoDB: connects · API server connects to MongoDB.
- Student → MongoDB: stores in · Student documents live in MongoDB.
- Teacher → MongoDB: stores in · Teacher documents live in MongoDB.
- Email OTP → MongoDB: stores in · OTP records live in MongoDB.
- Slot → MongoDB: stores in · Slot documents live in MongoDB.
- Server entry → JWT: issues/validates · Backend signs and verifies access and verification tokens.
- React entry → App shell: boots · React entry mounts the app shell.
- App shell → Student UI: renders · Student-facing flows are selected by the app shell.
- App shell → Teacher UI: renders · Teacher-facing flows are selected by the app shell.
- App shell → API client: calls · UI screens use the shared API client.
- API client → v1 API: requests · Client talks to the versioned backend API.
- API client → JWT: carries · Requests include authentication tokens when present.