# themhv/livetoshi architecture

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

- Interactive diagram: https://gitdiagram.com/themhv/livetoshi
- Repository: https://github.com/themhv/livetoshi

## Overview

##### Main Components

A. Frontend Layer:
- Next.js Application (Main UI)
- Widget Component (for stream integration)
- Profile Components
- Goal Components
- Form Components

B. API Layer:
- Create Invoice Endpoint
- NOSTR Integration Services

C. External Services:
- NOSTR Network
- TTS Service
- Lightning Network (for Zaps)

**┌─────────────────────────────────────────────┐**
- Client Layer                 │
- ┌─────────────┐  ┌─────────────┐          │
- Browser   │  │   Widget    │          │
- ┘  └─────────────┘          │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- Next.js Layer                  │
- ┌─────────────┐  ┌─────────────┐          │
- Pages/App  │  │    API      │          │
- ┘  └─────────────┘          │
- ┌─────────────┐  ┌─────────────┐          │
- Components  │  │    Utils    │          │
- ┘  └─────────────┘          │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- Service Layer                   │
- ┌─────────────┐  ┌─────────────┐          │
- NOSTR    │  │  Lightning  │          │
- Client    │  │  Network    │          │
- ┘  └─────────────┘          │
- ┘

##### Important Details

A. Frontend Components:
- Relationship between pages and components
- Widget system
- NostrProvider component's scope

B. API Integration:
- Create_invoice route
- NOSTR event flow
- Zap handling mechanism

C. Service Integration:
- NOSTR client connections
- Lightning Network payment flow
- TTS service integration

##### Data Flow Indicators

- User interactions → Frontend
- Frontend → API calls
- API → NOSTR Network
- NOSTR Network → Lightning Network
- TTS processing flow

##### Additional Elements

- Component types
- Data flow directions
- External service integration points
- Authentication/Authorization flows

Remember to include configuration elements like environment variables and their impact on different components of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Browser Client"]
        Widget["Widget Component"]:::widget
    end

    subgraph NextApp["Next.js Application"]
        MainApp["Main Application"]:::app
        Profile["Profile System"]:::profile
        Goal["Goal System"]:::goal
        Forms["Form Component"]:::form
        NostrProvider["NOSTR Provider"]:::nostr
        UIComponents["UI Components"]:::ui
        CornerMenu["Corner Menu"]:::ui
    end

    subgraph API["API Layer"]
        InvoiceAPI["Create Invoice API"]:::api
    end

    subgraph Services["Service Layer"]
        NostrClient["NOSTR Client"]:::nostr
        NostrEvents["Events Handler"]:::nostr
        NostrUsers["User Management"]:::nostr
        NostrZaps["Zaps Handler"]:::nostr
        LightningService["Lightning Integration"]:::lightning
        Config["Configuration"]:::config
    end

    subgraph External["External Services"]
        NostrNetwork["NOSTR Network"]:::external
        LightningNetwork["Lightning Network"]:::external
        TTSService["TTS Service"]:::external
    end

    Browser --> MainApp
    Browser --> Widget
    MainApp --> NostrProvider
    NostrProvider --> NostrClient
    Widget --> Profile
    Profile --> Forms
    Forms --> InvoiceAPI
    InvoiceAPI --> LightningService
    NostrClient --> NostrEvents
    NostrClient --> NostrUsers
    NostrClient --> NostrZaps
    NostrEvents --> NostrNetwork
    NostrZaps --> LightningNetwork
    LightningService --> LightningNetwork
    NostrZaps --> TTSService
    Config --> MainApp
    MainApp --> UIComponents
    MainApp --> CornerMenu
    Profile --> Goal

    classDef app fill:#e1f5fe,stroke:#01579b
    classDef widget fill:#e8f5e9,stroke:#2e7d32
    classDef profile fill:#f3e5f5,stroke:#7b1fa2
    classDef goal fill:#fff3e0,stroke:#ef6c00
    classDef form fill:#e8eaf6,stroke:#3f51b5
    classDef api fill:#f1f8e9,stroke:#33691e
    classDef nostr fill:#e0f2f1,stroke:#00695c
    classDef lightning fill:#fce4ec,stroke:#c2185b
    classDef ui fill:#f3e5f5,stroke:#6a1b9a
    classDef config fill:#fffde7,stroke:#f57f17
    classDef external fill:#efebe9,stroke:#4e342e

    click MainApp "https://github.com/TheMhv/Livetoshi/tree/main/src/app/"
    click Widget "https://github.com/TheMhv/Livetoshi/blob/main/src/components/Widget.tsx"
    click Profile "https://github.com/TheMhv/Livetoshi/tree/main/src/app/profile/[npub]/"
    click Goal "https://github.com/TheMhv/Livetoshi/tree/main/src/app/goal/[eventId]/"
    click Forms "https://github.com/TheMhv/Livetoshi/blob/main/src/components/Form.tsx"
    click InvoiceAPI "https://github.com/TheMhv/Livetoshi/blob/main/src/app/api/create_invoice/route.ts"
    click NostrClient "https://github.com/TheMhv/Livetoshi/blob/main/src/lib/nostr/client.ts"
    click NostrEvents "https://github.com/TheMhv/Livetoshi/blob/main/src/lib/nostr/events.ts"
    click NostrUsers "https://github.com/TheMhv/Livetoshi/blob/main/src/lib/nostr/users.ts"
    click NostrZaps "https://github.com/TheMhv/Livetoshi/blob/main/src/lib/nostr/zaps.ts"
    click NostrProvider "https://github.com/TheMhv/Livetoshi/blob/main/src/components/NostrProvider.tsx"
    click LightningService "https://github.com/TheMhv/Livetoshi/blob/main/src/lib/nostr/invoice.ts"
    click UIComponents "https://github.com/TheMhv/Livetoshi/tree/main/src/components/ui/"
    click Widget "https://github.com/TheMhv/Livetoshi/tree/main/src/app/profile/[npub]/widget/"
    click Config "https://github.com/TheMhv/Livetoshi/blob/main/src/lib/config.ts"
    click CornerMenu "https://github.com/TheMhv/Livetoshi/blob/main/src/components/cornerMenu/cornerMenu.tsx"
```
