# caecur/bakka architecture

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

- Interactive diagram: https://gitdiagram.com/caecur/bakka
- Repository: https://github.com/caecur/bakka

## Overview

##### Main components
- Frontend Client Application:
– Built with Next.js (see the pages, components, styles, store, and utils directories).
– Uses React/TypeScript for the UI and Tailwind CSS for styling.
– Organizes API routes under pages/api which are used to handle HTTP requests (e.g., auth, post, discover, profile, search).

- Backend Content & Data Management (Sanity):
– Found in the "bakka-backend" directory with its own config, schemas, and plugins.
– Contains schema definitions (in schemas/) for entities like posts, comments, users, etc.
– Incorporates Sanity-specific configurations (sanity.json and config folder with Sanity presets).

- Authentication & External Services Integration:
– Google OAuth is integrated via the API endpoint (pages/api/auth.ts) for user authentication.

##### Sketching their relationships and interactions
– Client Layer representing the frontend application.
– Backend/Content Layer representing the Sanity-based backend.

– The Browser/Client (user) interacting with the Next.js pages and components.
– UI Components (e.g., VideoCard, Navbar) making API calls to backend API routes (auth, post, etc.).
– API endpoints communicating with the Sanity backend for content retrieval, updates, and storage.
– API endpoints handling authentication flow (Google OAuth integration).

##### Important architectural patterns & design principles
- The MVC-like separation in the frontend where:
– Pages enforce routing and API endpoints manage business logic.
– Components focus on rendering the UI.
- The headless CMS approach on the backend using Sanity:
– Schemas define the data model.
– Configurations guide the CMS and its data aspects.
- Clear separation of concerns between UI rendering, API routing, and content management.
- Integration pattern for OAuth authentication (an external service interacting through API endpoints).

##### Relevant technologies and frameworks
- Next.js & React (for the frontend)
- TypeScript throughout the project for strict type checking
- Tailwind CSS (for styling)
- Sanity (for backend content management)
- Google OAuth (for authentication)
- Node.js environment (implied by npm scripts and package.json)

##### Elements
- From Client → API Routes (data submissions, authentication requests).
- From API Routes → Sanity Backend (data queries and modifications).
- From API Routes → Google OAuth (for auth verification).
- Notes on architectural patterns:
- “Headless CMS architecture” near the Sanity block.
- “Separation of concerns (UI vs. API vs. Backend)” as high-level annotations.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    subgraph "Client Layer"
        A("User Browser"):::browser
        B("Next.js Client"):::client
        B1("Pages (/pages)"):::component
        B2("Components (/components)"):::component
        B3("Styles (/styles)"):::component
        B4("Store (/store)"):::component
        B5("Utils (/utils)"):::component
    end

    A -->|"Interacts"| B
    B -->|"contains"| B1
    B -->|"contains"| B2
    B -->|"contains"| B3
    B -->|"contains"| B4
    B -->|"contains"| B5

    %% Server Layer
    subgraph "Server Layer"
        subgraph "API Routes"
            C("Base API (/pages/api)"):::api
            F("Auth Endpoint (/pages/api/auth.ts)"):::api
            C -->|"includes"| F
        end
        subgraph "Sanity Backend"
            D("Sanity CMS"):::backend
            D1("Configurations (/bakka-backend/config)"):::backend
            D2("Schemas (/bakka-backend/schemas)"):::backend
            D3("Settings (/bakka-backend/sanity.json)"):::backend
            D -->|"has"| D1
            D -->|"has"| D2
            D -->|"has"| D3
        end
        E("Google OAuth"):::external
    end

    %% Data Flow Connections
    B -->|"APIcalls"| C
    C -->|"OAuth"| E
    C -->|"Dataqueries"| D

    %% Click Events for Frontend Components
    click B1 "https://github.com/caecur/bakka/tree/main//pages"
    click B2 "https://github.com/caecur/bakka/tree/main//components"
    click B3 "https://github.com/caecur/bakka/tree/main//styles"
    click B4 "https://github.com/caecur/bakka/tree/main//store"
    click B5 "https://github.com/caecur/bakka/tree/main//utils"

    %% Click Events for API Routes
    click C "https://github.com/caecur/bakka/tree/main//pages/api"
    click F "https://github.com/caecur/bakka/blob/main//pages/api/auth.ts"

    %% Click Events for Sanity Backend
    click D1 "https://github.com/caecur/bakka/tree/main//bakka-backend/config"
    click D2 "https://github.com/caecur/bakka/tree/main//bakka-backend/schemas"
    click D3 "https://github.com/caecur/bakka/blob/main//bakka-backend/sanity.json"

    %% Styles
    classDef browser fill:#ffefc1,stroke:#b58900,stroke-width:2px;
    classDef client fill:#cce8ff,stroke:#268bd2,stroke-width:2px;
    classDef component fill:#e0f7fa,stroke:#00695c,stroke-width:2px;
    classDef api fill:#ffccd5,stroke:#d81b60,stroke-width:2px;
    classDef backend fill:#dcedc1,stroke:#7cb342,stroke-width:2px;
    classDef external fill:#ffe0b2,stroke:#f57c00,stroke-width:2px;
```
