# rajatabcx/cms architecture

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

- Interactive diagram: https://gitdiagram.com/rajatabcx/cms
- Repository: https://github.com/rajatabcx/cms

## Overview

##### Main Components

a) Frontend Layer:
- Next.js Application (src/app directory structure)
- Client-side Components (src/components)
- State Management (src/store using atoms)
- Client Actions (src/actions)

b) Backend Layer:
- API Routes (src/app/api)
- Authentication System (NextAuth)
- Database Layer (Prisma ORM)

c) External Services:
- Discord Integration
- Notion Integration
- Google Analytics
- Video Storage/CDN (implied by video player components)

##### Key Architectural Elements

a) Core Features to Highlight:
- Course Management System
- Video Player with DRM
- User Authentication & Authorization
- Comment System
- Bookmark System
- Search Functionality
- Admin Dashboard

b) Data Flow Patterns:
- Server Actions (src/actions)
- API Routes (src/app/api)
- Database Interactions (Prisma)

**Client Layer (Browser)**

- ▼
**Frontend Layer (Next.js)**

- ▼
**Backend Layer (API Routes & Server Actions)**

- ▼
**Database Layer (PostgreSQL via Prisma)**

- ▼
**External Services Layer**

##### Important Connections

- User flow through authentication
- Content delivery pipeline
- Admin management workflows
- Integration points with Discord and Notion
- Database relationships (based on Prisma schema)

##### Implementation Details

- Rectangles: Main services
- Hexagons: External services
- Diamonds: Decision points

##### Key Relationships to Emphasize

- User → Authentication → Protected Routes
- Admin → Content Management → Database
- Video Player → Content Delivery → Storage
- Comments/Bookmarks → User Interactions → Database

##### Additional Elements

A section showing:
- Docker container architecture
- Development vs Production environments
- Caching mechanisms
- Error handling flow

- User Interface Layer
- Application Logic Layer
- Data Persistence Layer
- External Integration Layer
- Infrastructure Layer

Remember to:
- Use consistent styling
- Brief descriptions for complex flows
- Both synchronous and asynchronous operations

This system design should capture the full scope of the CMS while maintaining clarity and providing valuable architectural insights for both development and deployment considerations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph Frontend
        NextApp["Next.js Application"]
        Components["Frontend Components"]:::component
        StateManagement["State Management (Atoms)"]:::state
        ClientActions["Client Actions"]:::actions
        VideoPlayer["Video Player"]:::component
        Comments["Comment System"]:::component
        Bookmarks["Bookmark System"]:::component
        Search["Search System"]:::component
        NotionRender["Notion Renderer"]:::component
    end

    subgraph Backend
        APIRoutes["API Routes"]:::api
        Auth["Authentication System"]:::auth
        AdminDash["Admin Dashboard"]:::admin
        CourseManage["Course Management"]:::course
        DBUtils["Database Utilities"]:::db
    end

    subgraph Database
        PostgreSQL[(PostgreSQL)]
        PrismaORM["Prisma ORM"]:::db
    end

    subgraph External
        Discord["Discord Service"]:::external
        Notion["Notion Service"]:::external
        Analytics["Google Analytics"]:::external
        CDN["Video CDN"]:::external
    end

    %% Connections
    Browser --> NextApp
    NextApp --> Components
    NextApp --> StateManagement
    NextApp --> ClientActions
    
    Components --> VideoPlayer
    Components --> Comments
    Components --> Bookmarks
    Components --> Search
    Components --> NotionRender
    
    ClientActions --> APIRoutes
    APIRoutes --> Auth
    APIRoutes --> AdminDash
    APIRoutes --> CourseManage
    
    Auth --> PrismaORM
    AdminDash --> PrismaORM
    CourseManage --> PrismaORM
    DBUtils --> PrismaORM
    
    PrismaORM --> PostgreSQL
    
    APIRoutes --> Discord
    APIRoutes --> Notion
    NextApp --> Analytics
    VideoPlayer --> CDN

    %% Click Events
    click Components "https://github.com/rajatabcx/cms/tree/main/src/components"
    click StateManagement "https://github.com/rajatabcx/cms/tree/main/src/store/atoms"
    click ClientActions "https://github.com/rajatabcx/cms/tree/main/src/actions"
    click APIRoutes "https://github.com/rajatabcx/cms/tree/main/src/app/api"
    click Auth "https://github.com/rajatabcx/cms/blob/main/src/lib/auth.ts"
    click PrismaORM "https://github.com/rajatabcx/cms/tree/main/prisma"
    click VideoPlayer "https://github.com/rajatabcx/cms/blob/main/src/components/VideoPlayer.tsx"
    click Comments "https://github.com/rajatabcx/cms/tree/main/src/components/comment"
    click Bookmarks "https://github.com/rajatabcx/cms/tree/main/src/components/bookmark"
    click Search "https://github.com/rajatabcx/cms/tree/main/src/components/search"
    click AdminDash "https://github.com/rajatabcx/cms/tree/main/src/app/admin"
    click Discord "https://github.com/rajatabcx/cms/tree/main/src/app/api/discord"
    click NotionRender "https://github.com/rajatabcx/cms/blob/main/src/components/NotionRenderer.tsx"
    click CourseManage "https://github.com/rajatabcx/cms/tree/main/src/app/courses"
    click DBUtils "https://github.com/rajatabcx/cms/tree/main/src/db"

    %% Styling
    classDef component fill:#3498db,stroke:#2980b9,color:white
    classDef state fill:#2ecc71,stroke:#27ae60,color:white
    classDef actions fill:#e74c3c,stroke:#c0392b,color:white
    classDef api fill:#9b59b6,stroke:#8e44ad,color:white
    classDef auth fill:#e67e22,stroke:#d35400,color:white
    classDef admin fill:#34495e,stroke:#2c3e50,color:white
    classDef course fill:#16a085,stroke:#138d75,color:white
    classDef db fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
```
