# sh2aliyev/spywitch architecture

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

- Interactive diagram: https://gitdiagram.com/sh2aliyev/spywitch
- Repository: https://github.com/sh2aliyev/spywitch

## Overview

##### Project type and purpose
- SpyWitch is a full-stack/edge-enabled Next.js web application whose sole purpose is to track and display live Twitch.tv chat events (messages, subs, cheers, etc.) for moderation. It is open-source, built with React/Next.js (using the new app/ directory), Tailwind CSS, TypeScript, and hosted via GitHub Actions (deploy.yml) and tested via tests.yml.

##### File structure
├── .github/workflows/*.yml
│   • CI/CD pipelines (tests + deploy)
├── public/
├── src/app/
│   • Next.js route handlers & layouts (root, monitor, setup pages)
├── src/components/
├── src/features/
│   • Feature-scoped components organized by domain (monitor, setup, status, navigation)
├── src/lib/
│   • Business-logic layers (Twitch adapters, action transforms to-save/to-show, utils)
├── src/system/
│   • Global constants, type definitions, page-routes, and a centralized state store (likely Zustand)
├── config files (ESLint, Prettier, Tailwind, Next.js, TS)

##### README insights
- Confirms “live data tracker for Twitch.tv,” for channel moderation
- No custom backend; uses Next.js edge functions or client-side requests to Twitch

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    UserBrowser["User Browser / Web Client"]:::ui

    %% Next.js Application
    subgraph "Next.js Application"
        direction TB

        subgraph "Routing Layer"
            direction TB
            RL1["(root)/layout.tsx"] 
            RL2["(root)/page.tsx"]
            RL3["monitor/page.tsx"]
            RL4["setup/page.tsx"]
            RL5["app/layout.tsx"]
            RL6["app/page.tsx"]
        end

        subgraph "Presentation Layer"
            direction TB
            subgraph "Reusable UI Components"
                Btn["button.tsx"]
                Icons["icons folder"]
                PageArea["page-area.tsx"]
                Section["section.tsx"]
            end
            subgraph "Feature-Scoped Components"
                Logs["logs.tsx"]
                LogItem["log-item.tsx"]
                ItemTabs["item-tabs.tsx"]
                LogsInfo["logs-info.tsx"]
                NavBar["navbar.tsx"]
                MobileNav["mobile-navbar.tsx"]
                SetupFeat["setup/components folder"]
                StatusFeat["status/components folder"]
            end
        end

        subgraph "Business Logic Layer"
            direction TB
            Adapter["adapter.ts"] 
            SpyAction["spy.ts"]
            ToSave["to-save.ts"]
            ToShow["to-show.ts"]
            Utils["utils.ts"]
            InputDefs["input-definitions.ts"]
        end

        subgraph "State Management"
            direction TB
            Store["store.ts"]
            Consts["consts.ts"]
            Types["types.ts"]
            PagesSys["pages.ts"]
        end
    end

    %% External Services & Assets
    TwitchAPI["Twitch API (EventSub/Webhooks)"]:::external
    CDN["Static Assets & CDN"]:::external

    %% CI/CD & Config
    CI["GitHub Actions CI/CD"]:::ci
    Config["Deployment & Configuration Files"]:::config

    %% Data Flows
    UserBrowser -->|"HTTP/HTTPS"| RL1
    RL1 -->|"route handling"| Adapter
    Adapter -->|"fetch/events"| TwitchAPI
    TwitchAPI -->|"events"| ToShow
    ToShow -->|"normalize"| Store
    Store -->|"state update"| Logs
    Logs -->|"render UI"| UserBrowser

    RL1 -->|"serve static"| CDN
    CI -->|"deploy"| CDN

    CI -->|"runs tests + deploy"| RL1
    Config -.-> RL1

    %% Click Events
    click RL1 "https://github.com/sh2aliyev/spywitch/blob/main/src/app/(root)/layout.tsx"
    click RL2 "https://github.com/sh2aliyev/spywitch/blob/main/src/app/(root)/page.tsx"
    click RL3 "https://github.com/sh2aliyev/spywitch/blob/main/src/app/(root)/monitor/page.tsx"
    click RL4 "https://github.com/sh2aliyev/spywitch/blob/main/src/app/(root)/setup/page.tsx"
    click RL5 "https://github.com/sh2aliyev/spywitch/blob/main/src/app/layout.tsx"
    click RL6 "https://github.com/sh2aliyev/spywitch/blob/main/src/app/page.tsx"

    click Btn "https://github.com/sh2aliyev/spywitch/blob/main/src/components/blocks/button.tsx"
    click Icons "https://github.com/sh2aliyev/spywitch/tree/main/src/components/icons/"
    click PageArea "https://github.com/sh2aliyev/spywitch/blob/main/src/components/layout/page-area.tsx"
    click Section "https://github.com/sh2aliyev/spywitch/blob/main/src/components/layout/section.tsx"

    click Logs "https://github.com/sh2aliyev/spywitch/blob/main/src/features/monitor/logs.tsx"
    click LogItem "https://github.com/sh2aliyev/spywitch/blob/main/src/features/monitor/log-item.tsx"
    click ItemTabs "https://github.com/sh2aliyev/spywitch/blob/main/src/features/monitor/item-tabs.tsx"
    click LogsInfo "https://github.com/sh2aliyev/spywitch/blob/main/src/features/monitor/logs-info.tsx"
    click NavBar "https://github.com/sh2aliyev/spywitch/blob/main/src/features/navigation/navbar.tsx"
    click MobileNav "https://github.com/sh2aliyev/spywitch/blob/main/src/features/navigation/mobile-navbar.tsx"
    click SetupFeat "https://github.com/sh2aliyev/spywitch/tree/main/src/features/setup/components/"
    click StatusFeat "https://github.com/sh2aliyev/spywitch/tree/main/src/features/status/components/"

    click Adapter "https://github.com/sh2aliyev/spywitch/blob/main/src/lib/action/adapter.ts"
    click SpyAction "https://github.com/sh2aliyev/spywitch/blob/main/src/lib/action/spy.ts"
    click ToSave "https://github.com/sh2aliyev/spywitch/blob/main/src/lib/action/to-save.ts"
    click ToShow "https://github.com/sh2aliyev/spywitch/blob/main/src/lib/action/to-show.ts"
    click Utils "https://github.com/sh2aliyev/spywitch/blob/main/src/lib/utils.ts"
    click InputDefs "https://github.com/sh2aliyev/spywitch/blob/main/src/lib/input-definitions.ts"

    click Store "https://github.com/sh2aliyev/spywitch/blob/main/src/system/store.ts"
    click Consts "https://github.com/sh2aliyev/spywitch/blob/main/src/system/consts.ts"
    click Types "https://github.com/sh2aliyev/spywitch/blob/main/src/system/types.ts"
    click PagesSys "https://github.com/sh2aliyev/spywitch/blob/main/src/system/pages.ts"

    click CDN "https://github.com/sh2aliyev/spywitch/tree/main/public/"
    click CI "https://github.com/sh2aliyev/spywitch/tree/main/.github/workflows/"
    click Config "https://github.com/sh2aliyev/spywitch/blob/main/next.config.ts"

    %% Styles
    classDef ui fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef routing fill:#e3f2fd,stroke:#1565c0,color:#1565c0
    classDef logic fill:#c8e6c9,stroke:#2e7d32,color:#2e7d32
    classDef external fill:#ffe0b2,stroke:#ef6c00,color:#e65100
    classDef ci fill:#e0e0e0,stroke:#424242,color:#424242
    classDef config fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c

    class RL1,RL2,RL3,RL4,RL5,RL6 routing
    class Adapter,SpyAction,ToSave,ToShow,Utils,InputDefs,Store,Consts,Types,PagesSys logic
    class CI,Config ci
    class TwitchAPI,CDN external
    class Btn,Icons,PageArea,Section,Logs,LogItem,ItemTabs,LogsInfo,NavBar,MobileNav,SetupFeat,StatusFeat ui
```
