# siddharthsahani/cohesion architecture

> Architecture diagram of the GitHub repository siddharthsahani/cohesion, 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/siddharthsahani/cohesion
- Repository: https://github.com/siddharthsahani/cohesion

## Overview

##### Main Components

a. Frontend Layer:
- Client-side SvelteKit components (src/lib/components)
- UI Components library (src/lib/components/ui)
- Game interface components (Board, BoardCard, BoardCell)
- Authentication components (SignInCard)

b. Backend Layer:
- Server-side SvelteKit routes (src/routes)
- API endpoints (src/routes/api)
- Authentication system (src/auth.js)
- Rate limiting service (src/lib/server/rateLimiter.js)

c. External Services:
- Supabase (Database & Authentication)
- Redis (Upstash for caching/rate limiting)
- AuthJS (Authentication framework)

**Client Tier**

**Application Tier**

**Data Tier**

##### Component Relationships

a. Client Tier:
- UI components to their respective routes
- Interaction between Board components and game logic
- Theme switching and responsive components

b. Application Tier:
- API routes to their handlers
- Authentication flow
- Demonstrate rate limiting middleware
- Game logic processing

c. Data Tier:
- Supabase connections for data storage
- Redis caching layer
- Authentication data flow

##### Specific Implementation Details

- Rectangles: Core components (Board, Game Logic)
- Hexagons: External services (AuthJS)
- Rounded rectangles: UI components

- Blue: Frontend components
- Green: Backend services
- Yellow: External services
- Red: Security/Authentication components

##### Key Flows to Highlight

a. Game Flow:
**User → Board Component → Game API → Redis Cache → Supabase**

b. Authentication Flow:
**User → SignInCard → AuthJS → Supabase Auth → Protected Routes**

c. Game Creation Flow:
**User → Create Route → API Endpoint → Supabase Storage**

##### Additional Elements

Specific features:
- Rate limiting mechanism between API calls
- Redis caching layer for game state
- Supabase real-time updates
- Theme switching functionality
- Profile management system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        UI["UI Components"]
        Board["Game Board"]:::component
        BoardCard["Board Card"]:::component
        BoardCell["Board Cell"]:::component
        BoardHeader["Board Header"]:::component
        TriesLeft["Tries Left"]:::component
        ThemeSwitch["Theme Switch"]:::component
        SignInCard["Sign In Card"]:::component
        Navbar["Navigation Bar"]:::component
    end

    subgraph App["Application Layer"]
        Routes["Core Routes"]
        CreateGame["Create Game"]:::route
        PlayGame["Play Game"]:::route
        Profile["Profile"]:::route
        ErrorHandler["Error Handler"]:::route
        
        subgraph API["API Layer"]
            GameAPI["Game API"]:::api
            ReportAPI["Report API"]:::api
            RateLimiter["Rate Limiter"]:::service
            ServerHooks["Server Hooks"]:::service
        end
        
        subgraph Auth["Authentication System"]
            AuthSystem["Auth Handler"]:::auth
            AuthRoutes["Auth Routes"]:::auth
        end
    end

    subgraph Data["Data Layer"]
        Supabase[(Supabase DB)]:::database
        Redis[(Redis Cache)]:::database
        AuthJS[("AuthJS")]:::external
    end

    %% Component Relationships
    UI --> Board
    Board --> BoardCard
    BoardCard --> BoardCell
    Board --> BoardHeader
    Board --> TriesLeft
    UI --> ThemeSwitch
    UI --> SignInCard
    UI --> Navbar

    %% Route Relationships
    Routes --> CreateGame
    Routes --> PlayGame
    Routes --> Profile
    Routes --> ErrorHandler

    %% API Relationships
    GameAPI --> RateLimiter
    RateLimiter --> Redis
    GameAPI --> Supabase
    ReportAPI --> Supabase
    
    %% Auth Flow
    SignInCard --> AuthSystem
    AuthSystem --> AuthJS
    AuthJS --> Supabase
    AuthRoutes --> AuthSystem

    %% Server Integration
    ServerHooks --> RateLimiter
    ServerHooks --> AuthSystem

    %% Click Events
    click Board "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/Board.svelte"
    click BoardCard "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/BoardCard.svelte"
    click BoardCell "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/BoardCell.svelte"
    click BoardHeader "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/BoardHeader.svelte"
    click TriesLeft "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/TriesLeft.svelte"
    click ThemeSwitch "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/ThemeSwitch.svelte"
    click SignInCard "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/SignInCard.svelte"
    click Navbar "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/components/Navbar.svelte"
    click CreateGame "https://github.com/SiddharthSahani/cohesion/blob/main/src/routes/create/+page.svelte"
    click PlayGame "https://github.com/SiddharthSahani/cohesion/blob/main/src/routes/games/[game_id]/+page.svelte"
    click Profile "https://github.com/SiddharthSahani/cohesion/blob/main/src/routes/profile/+page.svelte"
    click ErrorHandler "https://github.com/SiddharthSahani/cohesion/blob/main/src/routes/+error.svelte"
    click GameAPI "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/gameApi.js"
    click ReportAPI "https://github.com/SiddharthSahani/cohesion/blob/main/src/routes/api/report/+server.js"
    click RateLimiter "https://github.com/SiddharthSahani/cohesion/blob/main/src/lib/server/rateLimiter.js"
    click ServerHooks "https://github.com/SiddharthSahani/cohesion/blob/main/src/hooks.server.js"
    click AuthSystem "https://github.com/SiddharthSahani/cohesion/blob/main/src/auth.js"
    click AuthRoutes "https://github.com/SiddharthSahani/cohesion/blob/main/src/routes/signin/+page.server.js"

    %% Styling
    classDef component fill:#3498db,stroke:#2980b9,color:white
    classDef route fill:#2ecc71,stroke:#27ae60,color:white
    classDef api fill:#e74c3c,stroke:#c0392b,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef auth fill:#e67e22,stroke:#d35400,color:white
```
