# dongjin2008/astrolink architecture

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

- Interactive diagram: https://gitdiagram.com/dongjin2008/astrolink
- Repository: https://github.com/dongjin2008/astrolink

## Overview

##### Main Components

A. Frontend Layer:
- Next.js App Router (app directory structure)
- Client Components (/components directory)
- Theme Provider
- UI Components
- Client-side Utils

B. Backend Layer:
- Next.js Server Components
- API Routes
- Middleware
- Server-side Utils

C. External Services:
- Supabase Integration
- Database (part of Supabase)

**┌─────────────────────────────────────────────────────┐**
- Client Browser                      │
- ┘
- ↕
**┌─────────────────────────────────────────────────────┐**
- Next.js Application                 │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  │
- Pages    │  │Components   │  │    Utils    │  │
- /        │  │- UI         │  │- Supabase   │  │
- /chat    │  │- Theme      │  │  Client     │  │
- /[slug]  │  │- Forms      │  │- Store      │  │
- ┘  └─────────────┘  └─────────────┘  │
- ┘
- ↕
**┌─────────────────────────────────────────────────────┐**
- Middleware                       │
- ┘
- ↕
**┌─────────────────────────────────────────────────────┐**
- Supabase                         │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  │
- Auth       │  │  Database   │  │  Real-time  │  │
- ┘  └─────────────┘  └─────────────┘  │
- ┘

##### Important Elements to Highlight

A. App Router Structure:
- Dynamic routing with [slug]
- Server vs. client components

B. Data Flow:
- Client-server communication
- Supabase interactions
- Middleware intercepting requests

C. State Management:
- Store.ts integration
- Theme provider context

##### Technical Details

- Next.js 13+ App Router architecture
- Supabase client/server utilities
- Authentication flow
- Real-time chat capabilities
- Theme switching mechanism

##### Relationships to Emphasize

- How the middleware interacts with Supabase
- Component hierarchy and composition
- Data flow between client and server
- State management patterns

Remember to:
- Use consistent notation
- A clear title
- Timestamps and version numbers
- Document any assumptions
- Performance-critical paths

This structure will give other developers a clear understanding of the application's architecture while highlighting the key technical decisions and patterns used in the project.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Browser"]
        UI[User Interface]
    end

    subgraph NextApp["Next.js Application"]
        subgraph Pages["Pages Layer"]
            MainPage["Main Page"]
            ChatPage["Chat Page"]
            Layout["App Layout"]
        end

        subgraph Components["Components Layer"]
            ThemeProvider["Theme Provider"]
            UIComponents["UI Components"]
            Forms["Form Components"]
        end

        subgraph Utils["Utilities Layer"]
            ClientUtils["Client Utilities"]
            ServerUtils["Server Utilities"]
            Store["State Management"]
        end
    end

    subgraph MW["Middleware Layer"]
        Middleware["Request Middleware"]
        SupabaseMiddleware["Supabase Middleware"]
    end

    subgraph Supabase["Supabase Services"]
        Auth["Authentication"]
        DB[(Database)]
        Realtime["Real-time Service"]
    end

    %% Relationships
    UI <--> NextApp
    NextApp <--> MW
    MW <--> Supabase

    %% Internal relationships
    MainPage --> Layout
    ChatPage --> Layout
    ThemeProvider --> Layout
    UIComponents --> Forms
    ClientUtils --> Store
    ServerUtils --> Store

    %% Click events
    click MainPage "https://github.com/dongjin2008/astrolink/blob/main/app/page.tsx"
    click ChatPage "https://github.com/dongjin2008/astrolink/tree/main/app/chat/[slug]"
    click Layout "https://github.com/dongjin2008/astrolink/blob/main/app/layout.tsx"
    click ThemeProvider "https://github.com/dongjin2008/astrolink/blob/main/components/theme-provider.tsx"
    click UIComponents "https://github.com/dongjin2008/astrolink/tree/main/components/ui"
    click Forms "https://github.com/dongjin2008/astrolink/blob/main/components/ui/form.tsx"
    click ClientUtils "https://github.com/dongjin2008/astrolink/blob/main/lib/utils.ts"
    click Store "https://github.com/dongjin2008/astrolink/blob/main/lib/store.ts"
    click Middleware "https://github.com/dongjin2008/astrolink/blob/main/app/middleware.ts"
    click SupabaseMiddleware "https://github.com/dongjin2008/astrolink/blob/main/app/utils/supabase/middleware.ts"

    %% Styling
    classDef client fill:#2196F3,color:white
    classDef server fill:#4CAF50,color:white
    classDef external fill:#FF9800,color:white
    classDef middleware fill:#9E9E9E,color:white

    class UI,MainPage,ChatPage,Layout,ThemeProvider,UIComponents,Forms,ClientUtils,Store client
    class ServerUtils,Middleware,SupabaseMiddleware server
    class Auth,DB,Realtime external
    class MW middleware

    %% Legend
    subgraph Legend
        ClientNode["Client-side"]:::client
        ServerNode["Server-side"]:::server
        ExternalNode["External Services"]:::external
        MiddlewareNode["Middleware"]:::middleware
    end
```
