# muliahartawan/movie-nextjs-trpc architecture

> Architecture diagram of the GitHub repository muliahartawan/movie-nextjs-trpc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muliahartawan/movie-nextjs-trpc
- Repository: https://github.com/muliahartawan/movie-nextjs-trpc

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Client Browser"]:::frontend

    %% Next.js Application
    subgraph "Next.js Application"
        direction TB
        subgraph "App Router (UI Components)"
            direction TB
            AppRouter["App Router"]:::frontend
            PublicPages["Public Pages"]:::frontend
            AuthPages["Authenticated Pages"]:::frontend
            SharedComponents["Shared UI Components"]:::frontend
            SharedHooks["Shared Hooks"]:::frontend
        end

        subgraph "Server Layer"
            direction TB
            Middleware["Middleware Pipeline"]:::backend
            LibMiddleware["Middleware Helpers"]:::backend
            APIRoutes["API Routes (/api/*)"]:::backend
            TRPCEndpoint["tRPC Endpoint"]:::backend
            TRPCRouters["tRPC Context & Routers"]:::backend
            subgraph "Domain Modules"
                direction TB
                subgraph MovieModule["Movie Module"]
                    direction TB
                    SAMovie["Movie Server Action"]:::backend
                    ValMovie["Movie Validation"]:::backend
                    RepoMovie["Movie Repository"]:::backend
                end
                subgraph Others["Other Modules (User, Role, Screen-Schedule, Studio, Snack)"]
                    direction TB
                    SAUser["User Server Action"]:::backend
                    SARole["Role Server Action"]:::backend
                    SAScreenSchedule["Screen-Schedule Server Action"]:::backend
                    SAStudio["Studio Server Action"]:::backend
                    SASnack["Snack Server Action"]:::backend
                    ValUser["User Validation"]:::backend
                    ValRole["Role Validation"]:::backend
                    ValScreenSchedule["Screen-Schedule Validation"]:::backend
                    ValStudio["Studio Validation"]:::backend
                    ValSnack["Snack Validation"]:::backend
                    RepoUser["User Repository"]:::backend
                    RepoRole["Role Repository"]:::backend
                    RepoScreenSchedule["Screen-Schedule Repository"]:::backend
                    RepoStudio["Studio Repository"]:::backend
                    RepoSnack["Snack Repository"]:::backend
                end
            end
        end
    end

    %% Prisma Layer
    subgraph "Prisma ORM"
        direction TB
        PrismaClient["Prisma Client Setup"]:::backend
        PrismaSchema["Prisma Schema Definition"]:::backend
        Seeders["Prisma Seeders"]:::backend
    end

    %% Database
    Postgres[(PostgreSQL Database)]:::db

    %% External Services
    subgraph "External Services"
        direction TB
        AuthService["Authentication (NextAuth, OAuth)"]:::external
        Sentry["Sentry Error Tracking"]:::external
        Resend["Resend Email/OTP"]:::external
        AttachmentLib["Attachment Handling"]:::external
        MovieAttachment["Movie Attachment"]:::external
    end

    %% Flows
    Browser -->|HTTP| AppRouter
    AppRouter -->|renders| PublicPages
    AppRouter -->|renders| AuthPages
    PublicPages -->|use| SharedComponents
    AuthPages -->|use| SharedComponents
    PublicPages -->|use| SharedHooks
    AuthPages -->|use| SharedHooks

    AppRouter -->|API call| APIRoutes
    AppRouter -->|tRPC call| TRPCEndpoint
    AppRouter -->|React Server Action| SAMovie

    APIRoutes -->|middleware| Middleware
    TRPCEndpoint -->|middleware| Middleware
    Middleware -->|helpers| LibMiddleware

    APIRoutes -->|"Invoke"| SAMovie
    TRPCEndpoint -->|"Invoke"| SAMovie

    SAMovie -->|"validate"| ValMovie
    ValMovie -->|"db access"| RepoMovie
    RepoMovie -->|"Prisma Client"| PrismaClient
    PrismaClient -->|SQL| Postgres

    %% Others modules follow same pattern
    SAUser -->|validate| ValUser -->|db| RepoUser -->|Prisma| PrismaClient
    SARole -->|validate| ValRole -->|db| RepoRole -->|Prisma| PrismaClient
    SAScreenSchedule -->|validate| ValScreenSchedule -->|db| RepoScreenSchedule -->|Prisma| PrismaClient
    SAStudio -->|validate| ValStudio -->|db| RepoStudio -->|Prisma| PrismaClient
    SASnack -->|validate| ValSnack -->|db| RepoSnack -->|Prisma| PrismaClient

    PrismaClient -->|migrations| PrismaSchema
    PrismaClient -->|seed| Seeders

    %% Server to External
    Middleware -->|auth calls| AuthService
    Middleware -->|error events| Sentry
    SAMovie -->|send email| Resend
    SAMovie -->|handle file| MovieAttachment
    AttachmentLib -->|image processing| MovieAttachment

    %% Click Events
    click AppRouter "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/app/"
    click PublicPages "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/app/(public)"
    click AuthPages "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/app/(authenticated)"
    click SharedComponents "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/app/_components"
    click SharedHooks "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/app/_hooks"
    click APIRoutes "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/app/api/"
    click TRPCEndpoint "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/app/api/trpc/[trpc]/route.ts"
    click Middleware "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/middleware.ts"
    click LibMiddleware "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/libs/middleware/"
    click SAMovie "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/movie/actions/movie.action.ts"
    click SAUser "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/user/actions/user.action.ts"
    click SARole "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/role/actions/role.action.ts"
    click SAScreenSchedule "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/screen-schedule/actions/screen-schedule.action.ts"
    click SAStudio "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/studio/actions/studio.action.ts"
    click SASnack "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/snack/actions/snack.action.ts"
    click ValMovie "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/movie/validations/*.validation.ts"
    click ValUser "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/user/validations/*.validation.ts"
    click ValRole "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/role/validations/*.validation.ts"
    click ValScreenSchedule "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/screen-schedule/validations/*.validation.ts"
    click ValStudio "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/studio/validations/*.validation.ts"
    click ValSnack "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/snack/validations/*.validation.ts"
    click RepoMovie "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/movie/repositories/movie.repository.ts"
    click RepoUser "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/user/repositories/user.repository.ts"
    click RepoRole "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/role/repositories/role.repository.ts"
    click RepoScreenSchedule "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/screen-schedule/repositories/screen-schedule.repository.ts"
    click RepoStudio "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/studio/repositories/studio.repository.ts"
    click RepoSnack "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/snack/repositories/snack.repository.ts"
    click TRPCRouters "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/server/trpc/"
    click PrismaClient "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/libs/prisma/prisma.ts"
    click PrismaSchema "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/prisma/schema.prisma"
    click Seeders "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/prisma/seeders/"
    click AuthService "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/libs/auth/"
    click AttachmentLib "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/libs/attachment/image.ts"
    click MovieAttachment "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/src/server/movie/attachments/movie.attachment.ts"
    click Resend "https://github.com/muliahartawan/movie-nextjs-trpc/tree/development/src/libs/resend/"
    click Sentry "https://github.com/muliahartawan/movie-nextjs-trpc/blob/development/sentry.client.config.ts"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#90CAF9
    classDef backend fill:#E8F5E9,stroke:#A5D6A7
    classDef db fill:#FFF3E0,stroke:#FFCC80
    classDef external fill:#F3E5F5,stroke:#CE93D8
```
