# hxrshll/cms architecture

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

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

## Overview

Based on our analysis of the provided file tree and README, this project is an open-source CMS application that appears to be built as a full-stack solution using Next.js. It serves both as a client-facing application (with marketing pages, user authentication, course content viewing, etc.) and as a backend API (with multiple API routes for admin, authentication, content management, and integrations like Discord and GitHub). The database layer is managed via Prisma with PostgreSQL as the primary datastore. The repository also includes Docker and docker-compose configurations for containerized deployment.

##### Main Components
- Frontend Client / Next.js Application:
- Represented by the src/app directory which splits into sections like (main), (marketing), admin, and also includes pages for courses, certificates, signin, etc.
- UI components from the src/components and subdirectories (for things like video players, course views, form components, etc.).
- API Back-End:
- Represented by the src/app/api directory, with endpoints for different functionalities (admin actions, authentication, course video progress, Discord integrations, GitHub callbacks, etc.).
- Database Layer:
- The prisma folder holds the Prisma schema and numerous migrations. Indicate a PostgreSQL DB that serves as the central datastore.
- External Integrations and Services:
- Integration with third-party services such as Discord, GitHub, Notion, and possibly others (e.g., DRM or external login services under admin/services).
- Caching Layer:
- Caching components because of the existence of src/db/cache and files in src/lib/cache (e.g., in-memory and Redis implementations).
- Containerization/Deployment:
- Dockerfiles, docker-compose.yml, and GitHub workflows suggest containerized builds and CI/CD processes.

##### Component Relationships and Interactions
- User Interaction:
- Users interact with the Frontend client (Next.js pages) through web browsers.
- The client communicates with the backend using REST API endpoints (some being SSR/SSG pages) for content retrieval.
- API and Database Communication:
- API endpoints access the PostgreSQL database via Prisma to perform CRUD operations, data validation, and persist application state.
- External API Calls:
- Caching:
- Deployment & Containerization:

##### Architectural Patterns and Technologies
- Full-stack monorepo using Next.js:
- API Routing:
- API endpoints as separate or “internal” services with well-defined routes.
- MVC or Separation of Concerns:
- Although not explicitly an MVC framework, the separation between the view (UI components in src/components and src/app) and business logic (API routes and action modules in src/actions) should be clear.
- Developer Tools:
- That the project uses pnpm for package management and Prisma for ORM. This can be added as annotations for the technology stack.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global User
    User["User's Browser"]:::user

    %% Frontend Subgraph
    subgraph "Frontend"
        FE["Next.js Frontend"] 
        UI["UI Components"]
    end

    %% Backend (API Endpoints)
    subgraph "Backend (API Endpoints)"
        BE["API Back-End"]
    end

    %% Cache Layer
    subgraph "Cache Layer"
        Cache["In-Memory/Redis Cache"]
        Cache2["Additional Cache Service"]
    end

    %% Database Layer
    DB["Database (PostgreSQL via Prisma)"]

    %% External Integrations Subgraph
    subgraph "External Integrations"
        DiscordAdmin["Discord API (Admin)"]
        Discord["Discord API"]
        GitHub["GitHub Integrations"]
        Notion["Notion Integration"]
        ExternalLogin["External Login Service"]
        DRM["DRM Service"]
        Subtitle["Subtitle Service"]
    end

    %% Deployment/Containerization
    Deploy["Containerization (Docker Environment)"]:::deploy

    %% Connections
    User -->|"accesses"| FE
    FE -->|"renders"| UI
    FE -->|"calls"| BE
    BE -->|"queries/updates"| Cache
    Cache -->|"fallback"| DB
    BE -->|"direct access"| DB
    BE -->|"calls"| DiscordAdmin
    BE -->|"calls"| Discord
    BE -->|"calls"| GitHub
    BE -->|"calls"| Notion
    BE -->|"calls"| ExternalLogin
    BE -->|"calls"| DRM
    BE -->|"calls"| Subtitle
    BE -->|"updates"| Cache2

    %% Deployment ties components together
    Deploy --- FE
    Deploy --- BE
    Deploy --- DB
    Deploy --- Cache
    Deploy --- DiscordAdmin
    Deploy --- Discord
    Deploy --- GitHub
    Deploy --- Notion
    Deploy --- ExternalLogin
    Deploy --- DRM
    Deploy --- Subtitle

    %% Styles
    classDef frontend fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#e6f7ff,stroke:#005f99,stroke-width:2px;
    classDef database fill:#e6ffe6,stroke:#008000,stroke-width:2px;
    classDef external fill:#fff2cc,stroke:#b38f00,stroke-width:2px;
    classDef cache fill:#f9e6ff,stroke:#990099,stroke-width:2px;
    classDef deploy fill:#e6e6ff,stroke:#6666ff,stroke-width:2px;
    classDef user fill:#e6e6e6,stroke:#999999,stroke-width:2px;

    class FE,UI frontend;
    class BE backend;
    class DB database;
    class Cache,Cache2 cache;
    class DiscordAdmin,Discord,GitHub,Notion,ExternalLogin,DRM,Subtitle external;
    class Deploy deploy;
    class User user;

    %% Click Events for Component Mapping
    click FE "https://github.com/hxrshll/cms/tree/main/src/app"
    click UI "https://github.com/hxrshll/cms/tree/main/src/components"
    click BE "https://github.com/hxrshll/cms/tree/main/src/app/api"
    click DB "https://github.com/hxrshll/cms/tree/main/prisma"
    click DiscordAdmin "https://github.com/hxrshll/cms/tree/main/src/app/api/admin/discord"
    click Discord "https://github.com/hxrshll/cms/tree/main/src/app/api/discord"
    click GitHub "https://github.com/hxrshll/cms/tree/main/src/app/api/github"
    click Notion "https://github.com/hxrshll/cms/tree/main/src/app/api/notion"
    click ExternalLogin "https://github.com/hxrshll/cms/tree/main/src/app/api/admin/services/externalLogin"
    click DRM "https://github.com/hxrshll/cms/tree/main/src/app/api/admin/drm"
    click Subtitle "https://github.com/hxrshll/cms/tree/main/src/app/api/admin/services/subtitle"
    click Cache "https://github.com/hxrshll/cms/tree/main/src/lib/cache"
    click Cache2 "https://github.com/hxrshll/cms/blob/main/src/db/Cache.ts"
    click Deploy "https://github.com/hxrshll/cms/tree/main/Dockerfile"
    click Deploy "https://github.com/hxrshll/cms/blob/main/Dockerfile.dev"
    click Deploy "https://github.com/hxrshll/cms/blob/main/Dockerfile.prod"
    click Deploy "https://github.com/hxrshll/cms/blob/main/docker-compose.yml"
    click Deploy "https://github.com/hxrshll/cms/tree/main/.github/workflows"
```
