How satyam-chaudhary/alma-mater works
Project Type and Purpose
• This is a full-stack Next.js web application (bootstrapped with create-next-app) that allows users to search for colleges, view details (events, research, network, jobs), and includes protected form routes for administrators to add events, network posts, and research entries.
• The app uses React for UI, Next.js App Router for routing and server-side rendering (SSR/ISR), Prisma as an ORM for database access, and Tailwind CSS for styling.
File Structure Analysis
• Top-level files:
• next.config.mjs, tsconfig.json, tailwind.config.ts, postcss.config.mjs: Build and configuration.
• prisma/schema.prisma: Database schema.
• Directories:
• src/app: Next.js App Router – pages (page.tsx), layout.tsx, loading.tsx, global CSS, and server/API route handlers under app/api.
• src/components & src/app/components: React UI components.
• src/db: Prisma client initialization and DB utilities.
• src/lib: Seed scripts and utility functions.
• util: Static data (collegeData.json).
• API routes under src/app/api/* implement REST endpoints for home, search, events, job details, network, research, and collegeDetails.
• Protected routes under src/app/protected/* for admin forms.
• Middleware (middleware.ts) for route protection and redirects.
Key Architectural Patterns
• Separation of concerns:
• Presentation (React components under src/app and src/components)
• Data access (Prisma client in src/db)
• API layer (Next.js Route Handlers under app/api)
• Next.js App Router for file-based routing, SSR/ISR.
• MVC-like flow within API routes: Route Handler → Data access via Prisma or util → Response.
• Protected route middleware to enforce authentication/authorization.
• Utility scripts (seed, helpers) separate from runtime code.
Main Components & Their Interactions
a. Client Browser (User’s browser)
↔ HTTP(s)
b. Next.js Server (hosted on Vercel or Node.js)
• Frontend (React pages in src/app/*)
• API Route Handlers (src/app/api/*)
• Middleware (middleware.ts)
c. Database
• PostgreSQL/Mysql (configured in prisma/schema.prisma), accessed via Prisma Client (src/db/prisma.ts)
d. Utilities & Seed Scripts (local, run offline)
• src/lib/seed.ts, util/collegeData.ts
e. External Services
• Google Fonts (served via next/font)
• (Optional) Vercel platform for deployment
Data Flow:
1. User requests a page (e.g., /collegeDetails/Stanford) → Next.js routing → React page component (SSR or SSG).
2. Page server component may call fetch to internal API routes (e.g., /api/collegeDetails/Stanford) or directly use Prisma in server components.
3. API route handler executes business logic, uses Prisma to query DB or util JSON, returns JSON.
4. Frontend renders data; client-side interactivity may fetch more data via API endpoints.
5. Protected routes invoke middleware to check session/auth, then render admin forms.