How lachsfilet/quizzly works
Project Type and Purpose
• Full-stack web application built with Next.js (App Router).
• Core features: user registration/login via NextAuth, quiz creation, quiz discovery & playing, password reset, email verification.
• Uses Prisma ORM for database access, Tailwind CSS for UI, server actions for form handling, and a mail service to send tokens.
File Structure
• Top-level “app/” directory: Next.js routes and React Server/Client Components.
• “actions/” folder: Next.js server actions handling form submissions (register, login, reset, etc.).
• “app/api/auth/…[...nextauth]”: NextAuth endpoint for session management.
• “components/”: hundreds of React components (UI primitives, quiz cards, forms, modals).
• “lib/”: shared utilities (db connection, token logic, mailer).
• “prisma/schema.prisma”: data model for users, quizzes, tokens.
• Config files: next.config.js, tailwind.config.ts, tsconfig.json.
README (empty here)
• No extra architecture section; deduce from code and conventions.
Main Components & Relationships
A. User’s Browser (Client)
– React Client Components (hooks, form UI, quiz viewer)
– Static assets from “public/”
B. Next.js Server (App Router)
– React Server Components under “app/”
– API Routes /auth endpoints (NextAuth)
– Server Actions in “actions/” for POST handling (register.ts, login.ts, reset.ts, etc.)
C. Authentication Layer
– NextAuth middleware/adapter calling Prisma for session storage
– auth.config.ts + “/app/api/auth” route
D. Business Logic & Utilities
– lib/db.ts establishes connection to Postgres via Prisma Client
– lib/tokens.ts handles JWT or random token generation
– lib/mail.ts sends emails via external SMTP/SendGrid
E. Database
– Postgres (or another SQL) storing Users, Quizzes, Questions, Options, Tokens
– Prisma ORM as the single point of access
F. External Services
– Email provider (SMTP)
– Optional OAuth providers (if configured in NextAuth)
Interactions & Data Flow
1) User opens UI → Browser fetches SSR HTML/JSON from Next.js.
2) Client Component invokes server action (e.g. register) → HTTP POST to Next.js server action → lib/db and lib/mail → database write + email send → response.
3) User logs in → NextAuth endpoint → validates credentials via Prisma → issues session cookie/JWT → browser stores cookie.
4) Authenticated requests (quiz creation, fetch user) → Next.js Server Components read session via NextAuth → fetch data from DB via Prisma → render pages.
5) Public routes (discover quizzes) → data fetch from DB without session.
6) Password reset flow: user requests reset → server action writes token in DB → lib/mail sends reset email → user clicks link → server action verifies token → updates password.
Architectural Patterns & Principles
• 3-Tier architecture: Presentation (React), Application (Next.js + server actions + NextAuth), Data (Prisma + DB).
• Server-Client Component split (Next.js App Router) for SSR & hydration.
• Single source of truth for config in “prisma/schema.prisma” and NextAuth config.
• Separation of concerns: UI (“components/”), logic (“lib/”), data models (“prisma/” & “schemas/”), configuration.
• Utilize server-side actions and edge functions for auth flows.
Final Checklist
– Separate Frontend vs. Backend zones.
– Identify all Next.js subsystems (App Router, Server Actions, API routes, Middleware).
– Highlight Prisma-DB interactions.
– Show external email service.
– Annotate technology stacks (TypeScript, Tailwind, NextAuth).