# r-curio/iskonek architecture

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

- Interactive diagram: https://gitdiagram.com/r-curio/iskonek
- Repository: https://github.com/r-curio/iskonek

## Overview

##### Main Components

Frontend Layer:
- Next.js Client Application
- Auth Module (src/app/auth)
- Chat Module (src/app/chat)
- Profile Settings Module (src/components/profilesetting)
- UI Components (src/components/ui)
- Sidebar/Navigation (src/components/sidebar)

API Layer:
- Next.js API Routes
- Authentication endpoints (/api/auth)
- Chat endpoints (/api/chat)
- Profile endpoints (/api/profiles)
- Friend management (/api/friend)
- Account management (/api/account)

Backend Services:
- Supabase Integration
- Authentication Service
- Real-time Database
- Storage (for avatars/media)

##### Relationship Flows to Highlight

Data Flow:
- Client-Server Communication
- REST API calls
- Real-time WebSocket connections
- Authentication flows

State Management:
- Custom hooks (src/hooks)
- Client-side state
- Server-side state

##### Architectural Patterns to Emphasize

- Next.js App Router Architecture
- API Route Handler Pattern
- Component-based UI Architecture
- Custom Hook Pattern for State Management

**┌─────────────────────────────────────────────┐**
- Client Layer                 │
- ┌─────────┐ ┌─────────┐ ┌──────────────┐  │
- Auth  │ │  Chat   │ │  Profile     │  │
- ┘ └─────────┘ └──────────────┘  │
- ┬─────────────────────┘

**┌─────────────────────┼─────────────────────┐**
- API Layer                  │
- ┌─────────┐ ┌─────────┐ ┌──────────────┐ │
- Auth API │ │Chat API │ │Profile API   │ │
- ┘ └─────────┘ └──────────────┘ │
- ┬─────────────────────┘

**┌─────────────────────┼─────────────────────┐**
- Supabase Layer               │
- ┌─────────┐ ┌─────────┐ ┌──────────────┐ │
- Auth   │ │Database │ │   Storage    │ │
- ┘ └─────────┘ └──────────────┘ │
- ┘

##### Additional Elements

- WebSocket connections for real-time chat
- Data persistence paths
- Error handling paths
- State management flow

##### Important Details

- Separation between server and client components
- Real-time vs REST API connections
- Public and protected routes
- How the middleware (src/middleware.ts) integrates
- Demonstrate how hooks interact with the system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Auth["Authentication Module"]
        Chat["Chat Module"]
        Profile["Profile Management"]
        Friend["Friend Management"]
        UI["UI Components"]
        Nav["Navigation/Sidebar"]
        StateHooks["State Management Hooks"]
        Account["Account Management"]
    end

    subgraph API
        AuthAPI["Authentication API"]
        ChatAPI["Chat API"]
        ProfileAPI["Profile API"]
        FriendAPI["Friend API"]
        AccountAPI["Account API"]
        MW["Middleware"]
    end

    subgraph Supabase
        SupaAuth["Authentication Service"]
        SupaDB["Real-time Database"]
        SupaStorage["Storage Service"]
        SupaClient["Supabase Client"]
        SupaServer["Supabase Server"]
    end

    %% Client Layer Relationships
    Auth --> AuthAPI
    Chat --> ChatAPI
    Profile --> ProfileAPI
    Friend --> FriendAPI
    Account --> AccountAPI
    StateHooks --> Chat
    StateHooks --> Friend

    %% API Layer Relationships
    AuthAPI --> SupaAuth
    ChatAPI --> SupaDB
    ProfileAPI --> SupaDB
    FriendAPI --> SupaDB
    AccountAPI --> SupaDB
    MW --> AuthAPI

    %% Supabase Layer Relationships
    SupaClient --> SupaDB
    SupaServer --> SupaDB
    SupaAuth --> SupaDB
    SupaDB --> SupaStorage

    %% Click Events
    click Auth "https://github.com/r-curio/iskonek/tree/main/src/app/auth"
    click Chat "https://github.com/r-curio/iskonek/tree/main/src/app/chat"
    click Profile "https://github.com/r-curio/iskonek/tree/main/src/components/profilesetting"
    click Friend "https://github.com/r-curio/iskonek/blob/main/src/components/sidebar/contacts-list.tsx"
    click UI "https://github.com/r-curio/iskonek/tree/main/src/components/ui"
    click Nav "https://github.com/r-curio/iskonek/tree/main/src/components/sidebar"
    click AuthAPI "https://github.com/r-curio/iskonek/tree/main/src/app/api/auth"
    click ChatAPI "https://github.com/r-curio/iskonek/tree/main/src/app/api/chat"
    click ProfileAPI "https://github.com/r-curio/iskonek/tree/main/src/app/api/profiles"
    click FriendAPI "https://github.com/r-curio/iskonek/tree/main/src/app/api/friend"
    click AccountAPI "https://github.com/r-curio/iskonek/tree/main/src/app/api/account"
    click MW "https://github.com/r-curio/iskonek/blob/main/src/middleware.ts"
    click SupaClient "https://github.com/r-curio/iskonek/blob/main/src/utils/supabase/client.ts"
    click SupaServer "https://github.com/r-curio/iskonek/blob/main/src/utils/supabase/server.ts"
    click StateHooks "https://github.com/r-curio/iskonek/blob/main/src/hooks/use-messages.ts"
    click Account "https://github.com/r-curio/iskonek/blob/main/src/components/profilesetting/manage-account.tsx"

    %% Styling
    classDef client fill:#a8d5ff,stroke:#333,stroke-width:2px
    classDef api fill:#98ff98,stroke:#333,stroke-width:2px
    classDef supabase fill:#ffb366,stroke:#333,stroke-width:2px
    
    class Auth,Chat,Profile,Friend,UI,Nav,StateHooks,Account client
    class AuthAPI,ChatAPI,ProfileAPI,FriendAPI,AccountAPI,MW api
    class SupaAuth,SupaDB,SupaStorage,SupaClient,SupaServer supabase
```
