How the-sukhsingh/campus-connect works
Project type and purpose
• Campus Connect is a full-stack, PWA (Progressive Web App) built on Next.js (React) that centralizes campus operations (attendance, library, room booking, events, announcements, notes).
• Frontend and backend live in the same Next.js codebase: pages & API routes.
File structure
• Top-level: config files (Next, ESLint, PostCSS), public assets (service workers, Firebase config), scripts.
• src/app: Next.js “app router” routes, sub-directories for API endpoints under src/app/api.
• src/components: reusable React UI components.
• src/config: client & admin Firebase config.
• src/context: React context for Auth, Notifications, Theme.
• src/lib: database connection (dbConnect.js).
• src/models: Mongoose schemas for core domain (User, College, Attendance, Book, etc.).
• src/services: business-logic layer abstracting API and DB operations.
• src/utils: helper functions (fetch wrapper, cache, offline sync, role protection).
Extract insights from README
• Tech stack: Next.js (SSR/SSG), MongoDB Atlas, Firebase Authentication & Cloud Messaging, Azure Blob Storage, Vercel hosting.
• Features: role-based access (Admin, HOD, Faculty, Student), real-time notifications, offline support via service workers and IndexedDB.
• External dependencies: Firebase Auth & FCM, Azure Storage, MongoDB.
Main components & their interactions
a. User Devices (Browsers/Mobile)
• Runs the Next.js PWA client.
• Interacts with the Next.js server (SSR pages & CSR hydration).
• Registers Service Worker for offline support & push notifications.
b. Next.js Server (Vercel Serverless)
• Serves SSR/SSG pages under src/app.
• Exposes API routes under src/app/api via serverless functions.
• Auth middleware (middleware.js) enforces role protection.
c. Business Logic Layer
• src/services: orchestrates data flow between API handlers and data sources.
d. Data Sources
• MongoDB Atlas (via Mongoose models in src/models + dbConnect).
• Azure Blob Storage for file uploads (notes, assignments) via azureStorageService.
• Firebase Admin SDK for server-side messaging and token management.
e. External Services
• Firebase Authentication (client & admin).
• Firebase Cloud Messaging for push.
• IndexedDB (via offlineSync, cacheUtils) for offline data persistence.
Architectural patterns & design principles
• Layered architecture: Presentation (React/Next.js pages & components) → API layer (Next.js routes) → Service layer → Persistence.
• Role-based access control enforced by Next.js middleware & withRoleProtection HOC.
• PWA patterns: Service Worker, manifest.json, offline cache strategy.
• Client-server separation: UI uses fetchWrapper to call API routes.
• Domain-driven modules: one service + model per domain (e.g., attendanceService + Attendance model).