How moltivie/the-t3-stack works
Project type and purpose
• This is a full-stack Next.js (T3) CRUD web application.
• Users land on a public list/detail view (read-only). Authenticated users with role >1 can create/update/delete.
File structure
• Top-level frameworks & config: next.config.mjs, tsconfig.json, Tailwind, ESLint, Prettier, Prisma schema.
• Frontend UI under src/pages: React pages, dynamic routes, Tailwind CSS in src/styles.
• API layer under src/pages/api: NextAuth routes under /auth, TRPC endpoint under /trpc, miscellaneous example/restricted endpoints.
• Backend business logic under src/server:
• common/ – shared helpers (e.g. auth session)
• db/ – Prisma client setup
• trpc/ – context builder and routers for auth, users, moderator, and main app router.
• Utilities in src/utils and environment schemas in src/env.
Extract architecture insights from the README
• NextAuth + GitHub OAuth for authentication.
• tRPC for type-safe frontend↔backend RPC.
• Prisma ORM backed by PlanetScale (MySQL) for persistence.
• Mock data service (mockAPI) used for initial example data.
• Role-based access control enforced in router resolvers.
Main components and their interactions
a. Client (Browser)
• Renders Next.js pages (React)
• Calls tRPC client hooks for data operations
• Redirects for OAuth login via NextAuth
b. Next.js Server
• Serves pages (SSR/SSG/CSR)
• Hosts API routes:
– /api/auth/[...nextauth] → NextAuth handlers → GitHub OAuth
– /api/trpc/[trpc] → tRPC request handler
– /api/examples, /api/restricted → miscellaneous endpoints (e.g. mockAPI proxy)
c. tRPC Layer
• Client-side generated hooks call RPC endpoints
• Server-side context injects session (from NextAuth) and Prisma client
• Routers implement CRUD operations, enforce role checks
d. ORM Layer (Prisma)
• Translates tRPC resolver calls into SQL queries
• Connects to PlanetScale database via DATABASE_URL
e. Database (PlanetScale/MySQL)
• Stores User model (with role field) and other domain data
f. External Services
• GitHub OAuth provider (for login)
• mockAPI endpoint for seeded example data
Architectural patterns & design principles
• Hybrid rendering: static generation for public pages, server-side rendering for protected routes.
• RPC pattern: tRPC provides type-safe function calls instead of REST.
• Single codebase separation:
• UI (src/pages, src/styles)
• API handlers (src/pages/api)
• Business logic & data access (src/server)
• Role-based access control enforced at the resolver level.
• Environment-based configuration via src/env and .env files.