# moscart/cinematch architecture

> Architecture diagram of the GitHub repository moscart/cinematch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moscart/cinematch
- Repository: https://github.com/moscart/cinematch

## Overview

##### Main Components

a) Frontend Layer:
- Split into two main routes with different layouts:
- User Interface ((user) route)
- Movie listings (now-playing, upcoming, popular)
- Movie details
- Actor profiles
- Search functionality
- Admin Interface ((admin) route)
- Dashboard
- Content management
- Authentication

b) API Layer:
- REST API endpoints (/api routes)
- Movie-related endpoints
- Authentication endpoints
- Search functionality
- Pagination handling

c) Database Layer:
- Prisma ORM
- Database tables (based on migrations):
- Movies
- Users/Admin
- Authentication data

##### Component Relationships

- Frontend → API Layer: RESTful API calls
- API Layer → Database: Prisma client operations
- Authentication flow: Auth.js integration
- External services integration (if any)

##### Architectural Patterns to Highlight

- Next.js App Router architecture
- Route grouping pattern ((user) and (admin))
- API route handling
- Server-side vs Client-side components
- Authentication flow with Auth.js

##### Specific Implementation Details

**┌─────────────────────────────────────────────────────┐**
- Client Layer                       │
- ┬─────────────────────────────┤
- User Interface     │     Admin Interface         │
- Movie listings     │  - Dashboard                │
- Search             │  - Content Management       │
- Movie details      │  - User Management          │
- ┬────────────┴──────────────┬─────────────┘

- ▼                           ▼
**┌─────────────────────────────────────────────────────┐**
- API Layer                         │
- /api/movie/*                                    │
- /api/auth/*                                     │
- /api/now-playing, /popular, /upcoming           │
- ┬────────────────────────────┘

- ▼
**┌─────────────────────────────────────────────────────┐**
- Database Layer (Prisma)               │
- Movie data                                      │
- User/Admin data                                 │
- Authentication records                          │
- ┘

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        direction TB
        subgraph UserInterface["User Interface"]
            direction TB
            MovieListings["Movie Listings"]:::frontend
            MovieDetails["Movie Details"]:::frontend
            ActorProfiles["Actor Profiles"]:::frontend
            Search["Search"]:::frontend
        end

        subgraph AdminInterface["Admin Interface"]
            direction TB
            Dashboard["Dashboard"]:::frontend
            ContentMgmt["Content Management"]:::frontend
            AuthUI["Authentication"]:::frontend
        end
    end

    subgraph APILayer["API Layer"]
        direction TB
        MovieAPI["Movie Endpoints"]:::api
        AuthAPI["Auth Endpoints"]:::api
        ListingsAPI["Listings API"]:::api
        SearchAPI["Search API"]:::api
    end

    subgraph DBLayer["Database Layer"]
        direction TB
        PrismaORM["Prisma ORM"]:::database
        MovieDB[("Movie Data")]:::database
        UserDB[("User/Admin Data")]:::database
        AuthDB[("Auth Records")]:::database
    end

    subgraph Auth["Authentication"]
        direction TB
        AuthConfig["Auth Config"]:::auth
        AuthImpl["Auth Implementation"]:::auth
        Middleware["Middleware"]:::auth
    end

    %% Connections
    UserInterface --> APILayer
    AdminInterface --> APILayer
    APILayer --> PrismaORM
    PrismaORM --> MovieDB
    PrismaORM --> UserDB
    PrismaORM --> AuthDB
    AuthUI --> AuthAPI
    AuthAPI --> Auth
    Auth --> UserDB

    %% Click Events
    click MovieListings "https://github.com/Moscart/cinematch/tree/main/app/(user)/components"
    click MovieDetails "https://github.com/Moscart/cinematch/blob/main/app/(user)/detail/[id]/page.tsx"
    click ActorProfiles "https://github.com/Moscart/cinematch/blob/main/app/(user)/aktor/[id]/page.tsx"
    click Dashboard "https://github.com/Moscart/cinematch/blob/main/app/(admin)/admin/dashboard/dashboard.tsx"
    click ContentMgmt "https://github.com/Moscart/cinematch/blob/main/app/(admin)/admin/tambah/tambah.tsx"
    click AuthUI "https://github.com/Moscart/cinematch/tree/main/app/(admin)/auth/login"
    click MovieAPI "https://github.com/Moscart/cinematch/tree/main/app/api/movie"
    click AuthAPI "https://github.com/Moscart/cinematch/blob/main/app/api/auth/[...nextauth]"
    click SearchAPI "https://github.com/Moscart/cinematch/blob/main/app/api/movie/search/[query]/[page]/route.ts"
    click PrismaORM "https://github.com/Moscart/cinematch/blob/main/prisma/schema.prisma"
    click AuthConfig "https://github.com/Moscart/cinematch/blob/main/auth.config.ts"
    click AuthImpl "https://github.com/Moscart/cinematch/blob/main/auth.ts"
    click Middleware "https://github.com/Moscart/cinematch/blob/main/middleware.ts"

    %% Styles
    classDef frontend fill:#2196F3,color:white
    classDef api fill:#4CAF50,color:white
    classDef database fill:#FFC107,color:black
    classDef auth fill:#F44336,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        API["API Component"]:::api
        Database["Database Component"]:::database
        AuthComp["Auth Component"]:::auth
    end
```
