# vcroles/dashboard-vcroles architecture

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

- Interactive diagram: https://gitdiagram.com/vcroles/dashboard-vcroles
- Repository: https://github.com/vcroles/dashboard-vcroles

## Overview

##### Main Components
- Frontend UI:
- Pages: Under src/pages (including public pages like index.tsx, 404.tsx, and client-side pages such as the dashboard and documentation).
- Components: Found in src/components and src/components/docs with reusable UI elements (e.g., NavBar, Footer, CTASection, docs navigations).
- Layouts: Custom layouts in src/layouts (Dashboard.tsx, Docs.tsx) indicating a separation of business views.
- API / Backend Services:
- Server API endpoints: Located in src/pages/api (which includes endpoints for invite, og image generation, support, and a tRPC endpoint).
- tRPC Router & Context: In src/server/trpc which clearly encapsulates backend business logic and API interactions.
- Databases & External Data Sources:
- Prisma: The prisma folder contains the database schema (prisma/schema.prisma and possibly others for authentication). The README mentions a PostgreSQL instance for bot data, Planetscale MySQL for authentication, and Upstash Redis for caching.
- Third-Party Integrations & Tools:
- Authentication: Integration with Clerk Auth.
- Documentation: Markdoc in markdoc/ folder and markdown-based docs in src/pages/docs, which are compiled to HTML.
- Styling & Utility: Tailwind CSS (tailwind.config.cjs and src/styles) ensures the UI is styled correctly.
- Others: Next.js configuration files (next.config.mjs, next-sitemap.config.mjs), ESLint, Prettier, and deployment on Vercel.

##### Relationships and Interactions
- The client (browser) loads pages rendered by Next.js (both static and server-side rendered) and uses components from the src/components directory.
- The frontend interacts with the backend via API endpoints (located under src/pages/api) and tRPC endpoints, with clear data flow between the UI and backend services.
- The backend layer communicates with multiple databases:
- Bot data: Queries via Prisma using PostgreSQL.
- Authentication data: Managed through MySQL (by Planetscale) and integrated with Clerk Auth.
- Caching: Redis (via Upstash) for Discord data caching.
- A Markdoc process likely processes documentation content at build time to produce static HTML pages.

##### Architectural Patterns and Design Principles
- Modular separation: The clear separation between UI components, API endpoints, and backend services.
- Hybrid rendering: Next.js supports both client-side and server-side rendering (evident from pages like _app.tsx and _document.tsx).
- API abstraction: tRPC is used to create a typesafe API layer, streamlining communication between client and server.
- Use of environment configuration: Files like .env.example denote configurable and deployable environments.
- Integration of modern tooling: With ESLint, Prettier, and a robust configuration for deployment and building the app.

##### Technologies and Their Roles
- Next.js: Framework for the full-stack application, handling SSR and routing.
- Prismas: For database interfacing with PostgreSQL and MySQL.
- tRPC: To provide a typesafe and efficient RPC layer between the frontend and backend.
- Tailwind CSS: For styling the UI.
- Clerk Auth: For user authentication.
- Markdoc: For documentation generation.
- Upstash Redis: For caching purposes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Browser["Browser (Client)"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        Pages["Next.js Pages"]:::frontend
        UIComponents["UI Components"]:::frontend
        DocsComponents["Docs Components"]:::frontend
        Layouts["Layouts"]:::frontend
        Styles["Tailwind & Styles"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        API["API Endpoints"]:::backend
        TRPC["tRPC Router & Context"]:::backend
        PrismaDB["Prisma (Database)"]:::db
        Markdoc["Markdoc Docs Generation"]:::backend
        subgraph "External Services"
            Clerk["Clerk Auth"]:::external
            Redis["Upstash Redis"]:::external
            Vercel["Vercel Deployment"]:::external
        end
    end

    %% Connections
    Browser -->|"loads"| Pages
    Pages -->|"uses"| UIComponents
    Pages -->|"renders"| DocsComponents
    Pages -->|"applies"| Layouts
    Pages -->|"styled_by"| Styles
    Pages -->|"calls"| API

    API -->|"delegates_to"| TRPC
    TRPC -->|"queries"| PrismaDB
    TRPC -->|"auth_via"| Clerk
    TRPC -->|"caches_with"| Redis

    Markdoc -->|"compiles_to"| DocsComponents
    API -->|"includes"| Markdoc

    %% Deployment Connections
    Pages -->|"deployed_on"| Vercel
    API -->|"deployed_on"| Vercel

    %% Click Events
    click Pages "https://github.com/vcroles/dashboard-vcroles/tree/main/src/pages"
    click UIComponents "https://github.com/vcroles/dashboard-vcroles/tree/main/src/components"
    click DocsComponents "https://github.com/vcroles/dashboard-vcroles/tree/main/src/components/docs"
    click Layouts "https://github.com/vcroles/dashboard-vcroles/tree/main/src/layouts"
    click API "https://github.com/vcroles/dashboard-vcroles/tree/main/src/pages/api"
    click TRPC "https://github.com/vcroles/dashboard-vcroles/tree/main/src/server/trpc"
    click PrismaDB "https://github.com/vcroles/dashboard-vcroles/blob/main/prisma/schema.prisma"
    click Markdoc "https://github.com/vcroles/dashboard-vcroles/tree/main/markdoc"
    click Styles "https://github.com/vcroles/dashboard-vcroles/blob/main/tailwind.config.cjs"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#F7D6AE,stroke:#333,stroke-width:2px;
    classDef db fill:#C2F0C2,stroke:#333,stroke-width:2px;
    classDef external fill:#F9D6FF,stroke:#333,stroke-width:2px;
```
