# gursheyss/streamerstocks architecture

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

- Interactive diagram: https://gitdiagram.com/gursheyss/streamerstocks
- Repository: https://github.com/gursheyss/streamerstocks

## Overview

##### Project type and purpose
- This is a full-stack, real-time stock prediction/trading dashboard built with SvelteKit.
- Frontend: Svelte components under src/lib/components and page routes under src/routes.
- Backend/API: SvelteKit “+server.ts” endpoints handling predictions, trading, auth callbacks, Twitch EventSub, etc.
- Data and state layers: Supabase for persistent storage and auth; Redis for caching/updating stock snapshots.
- Sidecar microservice: A Python “stocks-script” that fetches and analyzes data (Reddit, Twitch, custom logic) and pushes updates via webhooks or cron.

##### File structure
- Top-level config: package.json, tsconfig.json, svelte.config.js, tailwind.config.js — sets up SvelteKit/TypeScript/Tailwind.
- src/lib/server: redis.ts, supabase.ts, updatestocks.ts — wrappers for external services and a stock-update scheduler.
- src/routes/api: /predict and /trade endpoints.
- src/routes/auth and eventsub: OAuth and Twitch EventSub webhook handlers.
- static/: public assets.
- stocks-script/: independent Python service in its own Docker container (Dockerfile) with analyzers and webhook.py to push data to the SvelteKit backend.

##### Elements
- Clear labels: “Browser (SvelteKit UI)”, “SvelteKit Server”, “Supabase DB & Auth”, “Redis Cache/PubSub”, “Python stocks-script Service”, “Twitch EventSub”, “Reddit API”.
- User → server → DB/cache → user.
- Python service → webhook → server → Redis/DB.
- External services → Python service or server endpoints.
- Client components (e.g., blue rectangles),
- Backend components (e.g., green),
- External services (e.g., orange clouds),

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        Browser["Browser (SvelteKit UI)"]:::client
        UIComp["UI Components"]:::client
        PageRoutes["Page Routes"]:::client
    end

    subgraph "Server Layer"
        SKServer["SvelteKit Server"]:::server
        Hooks["Hooks"]:::server
        subgraph "Routes & Endpoints"
            Predict["/api/predict"]:::api
            Trade["/api/trade"]:::api
            AuthCB["Auth Callback"]:::server
            TempAuth["Temp Auth"]:::server
            EventSub["Twitch EventSub"]:::server
        end
        subgraph "Server Utilities"
            SupaClient["Supabase Wrapper"]:::data
            RedisClient["Redis Wrapper"]:::data
            Updater["Stock Scheduler"]:::server
        end
    end

    subgraph "Data Layer"
        Supabase["Supabase\n(PostgreSQL + Auth)"]:::db
        Redis["Redis\n(Cache & PubSub)"]:::cache
    end

    subgraph "Python Microservice"
        PService["stocks-script"]:::micro
        Dockerfile["Dockerfile"]:::microfile
        Analyzers["analyzers/"]:::microfile
        RedditA["reddit.py"]:::microfile
        TwitchA["twitch.py"]:::microfile
        Analyze["analyze.py"]:::microfile
        WebhookP["webhook.py"]:::micro
        Run["run.py"]:::micro
    end

    subgraph "External Services"
        Twitch["Twitch EventSub"]:::ext
        RedditAPI["Reddit API"]:::ext
        TwitchAPI["Twitch API"]:::ext
    end

    %% Connections
    Browser -->|HTTP/HTTPS| SKServer
    Browser -->|fetch| Predict
    Browser -->|fetch| Trade
    SKServer -->|reads/writes| Supabase
    SKServer -->|cache/pubsub| Redis
    SKServer -->|triggers| Updater
    Updater -->|uses| RedisClient
    Updater -->|uses| SupaClient
    SupaClient -->|connects| Supabase
    RedisClient -->|connects| Redis
    PService -->|push webhook| SKServer
    PService -->|pull data| RedditAPI
    PService -->|pull data| TwitchAPI
    Twitch -->|webhook| EventSub
    SKServer -->|pubsub update| Redis
    Redis -->|live updates| Browser

    %% Click Events
    click UIComp "https://github.com/gursheyss/streamerstocks/tree/main/src/lib/components"
    click PageRoutes "https://github.com/gursheyss/streamerstocks/tree/main/src/routes"
    click Predict "https://github.com/gursheyss/streamerstocks/blob/main/src/routes/api/predict/+server.ts"
    click Trade "https://github.com/gursheyss/streamerstocks/blob/main/src/routes/api/trade/+server.ts"
    click AuthCB "https://github.com/gursheyss/streamerstocks/blob/main/src/routes/auth/callback/+server.ts"
    click TempAuth "https://github.com/gursheyss/streamerstocks/blob/main/src/routes/tempAuth/+server.ts"
    click EventSub "https://github.com/gursheyss/streamerstocks/blob/main/src/routes/eventsub/+server.ts"
    click SupaClient "https://github.com/gursheyss/streamerstocks/blob/main/src/lib/server/supabase.ts"
    click RedisClient "https://github.com/gursheyss/streamerstocks/blob/main/src/lib/server/redis.ts"
    click Updater "https://github.com/gursheyss/streamerstocks/blob/main/src/lib/server/updatestocks.ts"
    click Hooks "https://github.com/gursheyss/streamerstocks/blob/main/src/hooks.server.ts"
    click PService "https://github.com/gursheyss/streamerstocks/tree/main/stocks-script/"
    click Dockerfile "https://github.com/gursheyss/streamerstocks/tree/main/stocks-script/Dockerfile"
    click Analyzers "https://github.com/gursheyss/streamerstocks/tree/main/stocks-script/analyzers/"
    click RedditA "https://github.com/gursheyss/streamerstocks/blob/main/stocks-script/analyzers/reddit.py"
    click TwitchA "https://github.com/gursheyss/streamerstocks/blob/main/stocks-script/analyzers/twitch.py"
    click Analyze "https://github.com/gursheyss/streamerstocks/blob/main/stocks-script/analyzers/analyze.py"
    click WebhookP "https://github.com/gursheyss/streamerstocks/blob/main/stocks-script/webhook.py"
    click Run "https://github.com/gursheyss/streamerstocks/blob/main/stocks-script/run.py"

    %% Styles
    classDef client fill:#D6EFFF,stroke:#0288D1
    classDef server fill:#D5F5E3,stroke:#27AE60
    classDef data fill:#FEF9E7,stroke:#F1C40F
    classDef db fill:#FDEBD0,stroke:#D35400,stroke-width:2px
    classDef cache fill:#FCF3CF,stroke:#B7950B,stroke-width:2px
    classDef micro fill:#E8DAEF,stroke:#8E44AD
    classDef microfile fill:#F4ECF7,stroke:#BB8FCE,stroke-dasharray: 5 5
    classDef ext fill:#FADBD8,stroke:#C0392B
    classDef api fill:#AED6F1,stroke:#2471A3,stroke-width:2px
```
