How codercastor/chat-app works
Project Type and Purpose
• Full-stack web application for authenticated group chats and a user dashboard.
• Frontend: Next.js 13 (app directory), React components, NextAuth.js for authentication.
• Backend: Node.js with Express‐style routing, Prisma ORM, migrations for Users and ChatGroups.
File Structure
Top‐Level Directories:
• front/ – Next.js app, assets, UI components, API routes under app/api/auth.
• server/ – REST API, Prisma migrations, controllers, middleware, database config.
Key Patterns and Configs:
• front/app – React pages (page.tsx), layout, global styles, dashboard under app/dashboard.
• front/components – Organized by feature (auth, dashboard, groupChat) and UI primitives.
• server/src/controllers & routes – MVC‐style controllers for Auth and ChatGroup.
• server/src/Middlewares – JWT/session auth enforcement.
• server/prisma/schema.prisma + migrations → relational DB (e.g., PostgreSQL).
README for Additional Context
• The README is minimal (“codercastor”), implying the architecture isn’t documented yet. Use the file layout to infer responsibilities.
Main Components & Their Interactions
a. Frontend (Next.js App)
– Pages: Landing, Login (via NextAuth), Dashboard, GroupChat management.
– Components: UI library (buttons, dialogs), feature components (CreateChat, GroupChatCard).
– API Routes: /api/auth/[...nextauth] → NextAuth adapter for session tokens.
b. Backend (Express‐style API)
– AuthController → login, signup, token issuance.
– ChatGroupController → CRUD endpoints for chat groups.
– Middlewares → Securing routes, parsing JWT or session.
c. Database
– Managed via Prisma ORM; schema defines User and ChatGroup tables.
– Migrations folder documents evolution of schema.
d. External Services
– OAuth providers (GitHub/Google) proxied through NextAuth.
– Potential hosting/CDN for static assets (Vercel/Netlify).
Relationships & Data Flows
• Browser ↔ Next.js Server (SSR/data fetching on page load).
• Frontend API calls (fetch/groupFetch.ts) → Backend REST endpoints (e.g., POST /chatgroups).
• Backend ORM (Prisma) → Database for reads/writes.
• NextAuth session cookie or JWT stored in browser, passed with each request to secure routes.
Architectural Patterns & Design Principles
• Separation of Concerns: UI, business logic (controllers), and data layer (Prisma).
• MVC‐style on backend; feature‐based component organization on frontend.
• API Layer: clear boundary between frontend and backend via REST.
Detail
• Don’t omit the API‐layer or Prisma sub‐layer.
• Middleware as part of the request pipeline.
• Environment/config files (e.g., .env for DB credentials, next.config.ts).
• SSR/data‐fetch path in Next.js (page.tsx → getServerSideProps or fetch in React).