# pheralb/slug architecture

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

- Interactive diagram: https://gitdiagram.com/pheralb/slug
- Repository: https://github.com/pheralb/slug

## Overview

##### Main Components
- Frontend Client – Represented by the browser and Next.js pages (in the src/app directory). This includes the main public-facing routes (home, dashboard, auth, error handling, etc.) and UI components (found in src/components and src/ui).
- Authentication System – Incorporate Auth.js v5 integration (configured in src/auth.ts and under src/app/api/auth) and support for social providers (GitHub, Google), which involve extra external communication.
- External Services – Highlight external OAuth providers (GitHub and Google) and any third-party authentication token services. Optionally, include links to Turso CLI and other external dependencies mentioned in the README.
- Configuration & Deployment – Note the presence of configuration files (next.config.mjs, tailwind.config.ts, etc.) and Vercel deployment (the vercel.json file) indicating that the deployment is done in a Vercel-like environment.

##### Relationships and Data Flow
- Within the Backend Server, separate components such as “Server Actions & Middleware” (located in src/server) process business logic and interact with the database.

##### Architectural Patterns and Technologies
- Full-stack nature of the app with a clean separation between the UI (React/Next.js components) and server logic (API endpoints, server actions, middleware).
- Use of Server Actions in Next.js, which is key to how asynchronous server-side functions are executed.
- Typesafe patterns by labeling components that utilize TypeScript and Prisma integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    Client["Client (Web Browser)"]:::frontend

    %% Frontend Layer
    subgraph "Frontend Layer"
        F1["Next.js Pages (src/app)"]:::frontend
        F2["UI Components (src/components)"]:::frontend
        F3["UI Elements (src/ui)"]:::frontend
        F4["Dashboard Page"]:::frontend
        F5["Auth/Landing Page"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1["API Endpoints (src/app/api)"]:::backend
        B2["Server Actions & Middleware (src/server)"]:::backend
        B3["Actions (src/server/actions)"]:::backend
        B4["Middleware (src/server/middleware)"]:::backend
        B5["Queries (src/server/queries)"]:::backend
        B6["Utils (src/server/utils)"]:::backend
    end

    %% Authentication Module
    subgraph "Authentication Module"
        A1["Auth Core (src/auth.ts)"]:::auth
        A2["Auth Config (src/auth.config.ts)"]:::auth
        A3["Auth API (src/app/api/auth)"]:::auth
        A4["Auth Components (src/components/auth)"]:::auth
        A5["Client Auth Pages (src/app/auth)"]:::auth
    end

    %% External OAuth Providers
    EOP["External OAuth Providers (GitHub,Google)"]:::external

    %% Database Layer
    DB["Prisma ORM & Turso/SQLite"]:::database

    %% Configuration & Deployment
    subgraph "Configuration & Deployment"
        C1["next.config.mjs"]:::config
        C2["tailwind.config.ts"]:::config
        C3["vercel.json"]:::config
    end

    %% Connections

    %% Client -> Frontend
    Client -->|"Loads UI"| F1

    %% Frontend Navigation
    F1 -->|"NavigatesTo"| F4
    F1 -->|"NavigatesTo"| F5

    %% Frontend to Backend
    F1 -->|"API_Call"| B1

    %% Backend Internal Structure
    B2 --> B3
    B2 --> B4
    B2 --> B5
    B2 --> B6

    %% Backend to Database
    B1 -->|"DB_Query"| DB
    B2 -->|"DB_Operation"| DB

    %% Frontend to Authentication
    F5 -->|"Auth_Request"| A5
    F1 -->|"Auth_Request"| A5

    %% Authentication Internal Flow
    A1 --> A3
    A2 --> A3
    A3 -->|"OAuth_Exchange"| EOP

    %% Styling Classes
    classDef frontend fill:#ACE1AF,stroke:#333,stroke-width:2px;
    classDef backend fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef auth fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef database fill:#B0E0E6,stroke:#333,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend Layer
    click F1 "https://github.com/pheralb/slug/tree/main/src/app"
    click F2 "https://github.com/pheralb/slug/tree/main/src/components"
    click F3 "https://github.com/pheralb/slug/tree/main/src/ui"

    %% Click Events for Backend Layer
    click B1 "https://github.com/pheralb/slug/tree/main/src/app/api"
    click B2 "https://github.com/pheralb/slug/tree/main/src/server"
    click B3 "https://github.com/pheralb/slug/tree/main/src/server/actions"
    click B4 "https://github.com/pheralb/slug/tree/main/src/server/middleware"
    click B5 "https://github.com/pheralb/slug/tree/main/src/server/queries"
    click B6 "https://github.com/pheralb/slug/tree/main/src/server/utils"

    %% Click Events for Authentication Module
    click A1 "https://github.com/pheralb/slug/blob/main/src/auth.ts"
    click A2 "https://github.com/pheralb/slug/blob/main/src/auth.config.ts"
    click A3 "https://github.com/pheralb/slug/tree/main/src/app/api/auth"
    click A4 "https://github.com/pheralb/slug/tree/main/src/components/auth"
    click A5 "https://github.com/pheralb/slug/tree/main/src/app/auth"

    %% Click Event for Database
    click DB "https://github.com/pheralb/slug/blob/main/prisma/schema.prisma"

    %% Click Events for Configuration & Deployment
    click C1 "https://github.com/pheralb/slug/blob/main/next.config.mjs"
    click C2 "https://github.com/pheralb/slug/blob/main/tailwind.config.ts"
    click C3 "https://github.com/pheralb/slug/blob/main/vercel.json"
```
