How muliahartawan/movie-nextjs-trpc works
Project Type and Purpose
• This is a Next.js 14 full-stack boilerplate that uses React Server Actions for server-side logic, Prisma ORM for database access, and PostgreSQL as the data store. It targets small-to-medium projects, combining frontend pages/components in the App Router with backend “server actions” and tRPC/API routes in a single codebase.
File Structure and Architectural Patterns
• Frontend (src/app/)
• App Router pages under (public) and (authenticated)
• Shared components in _components/, hooks in _hooks/
• API routes under src/app/api/ (Next.js route handlers)
• Backend (src/server/)
• Domain modules (user, movie, role, screen-schedule, studio, snack)
– actions/: React Server Actions callable from client
– repositories/: Prisma queries to PostgreSQL
– validations/: Zod schema or custom validators
• tRPC context, root, and routers under src/server/trpc/
• Shared Libraries (src/libs/): cross-cutting concerns (auth, attachment handling, middleware, prisma setup, trpc provider)
• Common (src/common/), utils (src/utils/), types (src/types/): enums, types, and helpers
• Infra & DevOps: Dockerfile, docker-compose.yml, GitLab CI config, deploy scripts, Storybook, Jest
Key Components
a. Client Browser
• UI renders Next.js pages/components
• Sends HTTP/HTTPS requests to Next.js server (SSR/data fetching)
b. Next.js Application
• App Router: Page routing under src/app/
• Server Actions: Functions under src/server/.../actions invoked via React Server Actions
• API Routes (/api/*) and tRPC Layer (/api/trpc/[trpc] and src/server/trpc/routers)
• Middleware (src/middleware.ts, src/libs/middleware/*) for auth/permissions
c. Prisma ORM Layer
• src/libs/prisma/prisma.ts & repository classes call database
d. PostgreSQL Database
• Entity tables created via Prisma migrations (prisma/schema.prisma)
e. External Services
• Authentication: NextAuth with Google OAuth, OTP, tokens (src/libs/auth/*, .env variables)
• Error Tracking: Sentry (client, server, edge configs)
• Email/OTP: Resend service (src/libs/resend/*)
• File Attachments: Image handling (src/libs/attachment)
f. DevOps & CI/CD (optional small inset)
• Docker images, docker-compose, GitLab CI, deploy scripts, Vercel deployment
Relationships & Data Flows
• Browser → Next.js App (HTTP)
• Static/SSR pages fetch data via Server Actions or tRPC/API calls
• Next.js App → Server Actions/API/tRPC
• React Server Actions call domain actions → validation → repository → Prisma
• API routes/tRPC routers go through middleware → actions → repositories
• Server → Prisma
• Prisma client executes SQL against PostgreSQL
• Server → External Services
• Auth middleware calls OAuth/token services
• Error events sent to Sentry SDK
• Emails/OTPs sent via Resend API
• CI/CD Pipeline (GitLab → Docker build → Deploy to hosts/Vercel)
Architectural Patterns & Principles
• Domain-Driven Modules: Each resource (user, movie, etc.) has dedicated actions, repos, validations.
• Server Actions vs API/tRPC: Thin server-side layer in Next.js avoiding a separate backend server.
• Repository Pattern: Prisma repositories encapsulate all DB access.
• Middleware Pipeline: Auth & permission checks applied at the router/route level.
• Shared Libraries: Reusable cross-cutting code for auth, attachments, queries, etc.