# elsbrock/hetzner-radar architecture

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

- Interactive diagram: https://gitdiagram.com/elsbrock/hetzner-radar
- Repository: https://github.com/elsbrock/hetzner-radar

## Overview

##### Main Components

A. Frontend Layer:
- SvelteKit application (static site)
- Client-side DuckDB instance
- Components for visualization (LineChart, Radar, ServerPriceChart)
- Filter management system
- User interface elements

B. Backend Services:
- Cloudflare Workers:
- Email Queue Worker (for notifications)
- Rate Limiter Worker
- Authentication system
- Session management
- Alert system

C. Data Processing:
- Python-based data ingestion system
- Database management system
- Data update pipeline

D. External Services:
- Hetzner Auction API (data source)
- Cloudflare Pages (hosting)
- Email service (for alerts)

**[External Data Source]**
- ↓
**[Data Processing Pipeline]**
- ↓
**[Static Assets & Database]**
- ↓
**[Frontend Application] ←→ [Cloudflare Workers]**
- ↓
**[End Users]**

##### Key Interactions to Highlight

a. Data Flow:
- Hourly data fetching from Hetzner
- Database rebuild process
- Static asset deployment
- Client-side querying flow

b. User Interactions:
- Authentication flow
- Alert creation and notification path
- Filtering and analysis operations

##### Important Technical Details

- DuckDB client-side query system
- SvelteKit static site generation
- Cloudflare Workers architecture
- Python data processing pipeline
- Authentication and session management flow

##### Specific Implementation Notes

- The separation between static and dynamic components
- The role of Cloudflare Workers in handling dynamic operations
- The data update pipeline's automation
- The client-side database query system
- The alert system's architecture

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Services"]
        HetznerAPI["Hetzner Auction API"]:::external
        EmailService["Email Service"]:::external
        CFPages["Cloudflare Pages"]:::external
    end

    subgraph Processing["Data Processing Layer"]
        DataPipeline["Python Data Pipeline"]:::processing
        DBSchema["Database Schema"]:::database
        click DataPipeline "https://github.com/elsbrock/hetzner-radar/tree/main/scripts/"
        click DBSchema "https://github.com/elsbrock/hetzner-radar/blob/main/migrations/0001_initial_schema.sql"
    end

    subgraph Frontend["Frontend Layer"]
        SvelteApp["SvelteKit Application"]:::frontend
        DuckDB["Client DuckDB"]:::database
        Viz["Visualization Components"]:::frontend
        FilterSystem["Filter Management"]:::frontend
        FrontendAPI["Frontend API Layer"]:::frontend

        click SvelteApp "https://github.com/elsbrock/hetzner-radar/tree/main/src/routes/"
        click DuckDB "https://github.com/elsbrock/hetzner-radar/blob/main/src/lib/duckdb.ts"
        click Viz "https://github.com/elsbrock/hetzner-radar/tree/main/src/lib/components/"
        click FilterSystem "https://github.com/elsbrock/hetzner-radar/blob/main/src/lib/filter.ts"
        click FrontendAPI "https://github.com/elsbrock/hetzner-radar/tree/main/src/lib/api/frontend/"
    end

    subgraph Workers["Cloudflare Workers"]
        EmailWorker["Email Queue Worker"]:::worker
        RateLimiter["Rate Limiter Worker"]:::worker

        click EmailWorker "https://github.com/elsbrock/hetzner-radar/tree/main/workers/email-queue-worker/"
        click RateLimiter "https://github.com/elsbrock/hetzner-radar/tree/main/workers/rate-limiter/"
    end

    subgraph Auth["Authentication Layer"]
        AuthSystem["Authentication System"]:::auth
        SessionMgmt["Session Management"]:::auth
        AlertSystem["Alert System"]:::auth

        click AuthSystem "https://github.com/elsbrock/hetzner-radar/blob/main/src/lib/api/backend/auth.ts"
        click SessionMgmt "https://github.com/elsbrock/hetzner-radar/blob/main/src/lib/session.ts"
        click AlertSystem "https://github.com/elsbrock/hetzner-radar/tree/main/src/routes/(authed)/alerts/"
    end

    Users["End Users"]:::user

    %% Data Flow Connections
    HetznerAPI --> DataPipeline
    DataPipeline --> DBSchema
    DBSchema --> SvelteApp
    SvelteApp --> DuckDB
    DuckDB --> Viz
    DuckDB --> FilterSystem
    FilterSystem --> FrontendAPI
    
    %% Worker Connections
    AlertSystem --> EmailWorker
    EmailWorker --> EmailService
    RateLimiter --> HetznerAPI
    
    %% Auth Flow
    Users --> SvelteApp
    SvelteApp --> AuthSystem
    AuthSystem --> SessionMgmt
    SessionMgmt --> AlertSystem
    
    %% Deployment
    DBSchema --> CFPages
    SvelteApp --> CFPages
    CFPages --> Users

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef processing fill:#2ecc71,stroke:#27ae60,color:white
    classDef worker fill:#e67e22,stroke:#d35400,color:white
    classDef auth fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#34495e,stroke:#2c3e50,color:white
    classDef user fill:#95a5a6,stroke:#7f8c8d,color:white
```
