# krausefx/fxlifesheet architecture

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

- Interactive diagram: https://gitdiagram.com/krausefx/fxlifesheet
- Repository: https://github.com/krausefx/fxlifesheet

## Overview

##### Main Components

a) Data Collection Layer:
- Telegram Bot (worker.ts/worker.js)
- Manual Input System
- Various Data Importers (ruby_importers/)
- Apple Health
- RescueTime
- Spotify
- Swarm
- Weather
- etc.

b) Data Storage Layer:
- PostgreSQL Database
- Database Schema (from db/create_tables.sql)

c) Configuration Layer:
- lifesheet.json (question configurations)
- Environment Variables
- Config Management (classes/config.ts)

d) Visualization Layer:
- Web Frontend (visual_playground/)
- Data Processing APIs
- Graph Generation Systems

**[User Interaction Layer]**

- Telegram Bot ────┐
- Manual Input ────┤
- Data Importers ──┘

- [Data Processing Layer]

- [PostgreSQL Database]

- [Visualization Layer]

- [Web Frontend (howisFelix.today)]

##### Key Elements to Highlight

a) Data Flow:
- How data moves from input sources to storage
- How data is processed for visualization
- Scheduled tasks and automation points

b) Integration Points:
- External APIs (Telegram, weather services, etc.)
- Data import mechanisms
- Database connections

c) Component Relationships:
- Blue: User interaction components
- Green: Data processing components
- Yellow: Storage components
- Purple: Visualization components

##### Implementation Details

Use these symbols and conventions:
- Rectangles: Main components
- Double lines: API boundaries
- Clouds: External services

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef external fill:#e6e6e6,stroke:#666
    classDef frontend fill:#d9e7ff,stroke:#4a6da7
    classDef backend fill:#d9ead3,stroke:#37844b
    classDef database fill:#fff2cc,stroke:#bf9000
    classDef config fill:#f4cccc,stroke:#990000
    classDef api fill:#ead1dc,stroke:#674ea7
    classDef importer fill:#cfe2f3,stroke:#0b5394

    %% Legend
    subgraph Legend
        E1[External Services]:::external
        F1[Frontend Components]:::frontend
        B1[Backend Components]:::backend
        D1[Database]:::database
        C1[Configuration]:::config
        A1[API Components]:::api
        I1[Data Importers]:::importer
    end

    %% User Interaction Layer
    subgraph "User Interaction"
        TG[Telegram Bot]:::backend
        MI["Manual Input Interface"]:::frontend
        WF["Web Frontend"]:::frontend
        MGI["Manual Graph Interface"]:::frontend
    end

    %% External Services
    subgraph "External Services"
        ES1[Telegram API]:::external
        ES2[Weather Services]:::external
        ES3[Spotify]:::external
        ES4[RescueTime]:::external
        ES5[Swarm]:::external
    end

    %% Data Collection Layer
    subgraph "Data Collection"
        WK[Worker Process]:::backend
        TS[Task Scheduler]:::backend
        
        subgraph "Data Importers"
            AH[Apple Health Importer]:::importer
            RT[RescueTime Importer]:::importer
            SP[Spotify Importer]:::importer
            SW[Swarm Importer]:::importer
            WI[Weather Importer]:::importer
        end
    end

    %% Configuration Layer
    subgraph "Configuration"
        CM[Config Management]:::config
        QC[Question Configurations]:::config
        ENV[Environment Variables]:::config
    end

    %% Data Storage Layer
    DB[(PostgreSQL Database)]:::database
    DBH[Database Handler]:::backend
    DBS[Database Schema]:::config

    %% API and Processing Layer
    subgraph "API Layer"
        WS[Web Server]:::api
        API[Data Processing API]:::api
    end

    %% Relationships
    ES1 --> TG
    ES2 --> WI
    ES3 --> SP
    ES4 --> RT
    ES5 --> SW

    TG --> WK
    MI --> WS
    WF --> WS
    MGI --> WS

    WK --> DBH
    TS --> WK

    AH --> DBH
    RT --> DBH
    SP --> DBH
    SW --> DBH
    WI --> DBH

    CM --> WK
    QC --> CM
    ENV --> CM

    DBH --> DB
    DBS --> DB

    WS --> API
    API --> DBH

    %% Click events
    click TG "https://github.com/KrauseFx/FxLifeSheet/blob/master/classes/telegram.ts"
    click DBH "https://github.com/KrauseFx/FxLifeSheet/blob/master/classes/postgres.ts"
    click CM "https://github.com/KrauseFx/FxLifeSheet/blob/master/classes/config.ts"
    click DBS "https://github.com/KrauseFx/FxLifeSheet/blob/master/db/create_tables.sql"
    click QC "https://github.com/KrauseFx/FxLifeSheet/blob/master/lifesheet.json"
    click WK "https://github.com/KrauseFx/FxLifeSheet/blob/master/worker.ts"
    click WF "https://github.com/KrauseFx/FxLifeSheet/blob/master/visual_playground/frontend/frontend.html"
    click API "https://github.com/KrauseFx/FxLifeSheet/blob/master/visual_playground/api.rb"
    click AH "https://github.com/KrauseFx/FxLifeSheet/blob/master/ruby_importers/importers/apple_health/apple_health.rb"
    click RT "https://github.com/KrauseFx/FxLifeSheet/blob/master/ruby_importers/importers/rescuetime/rescuetime.rb"
    click SP "https://github.com/KrauseFx/FxLifeSheet/blob/master/ruby_importers/importers/spotify/spotify.rb"
    click SW "https://github.com/KrauseFx/FxLifeSheet/blob/master/ruby_importers/importers/swarm/swarm.rb"
    click WI "https://github.com/KrauseFx/FxLifeSheet/blob/master/ruby_importers/importers/weather/backfill_weather.rb"
    click TS "https://github.com/KrauseFx/FxLifeSheet/blob/master/scheduler.js"
    click WS "https://github.com/KrauseFx/FxLifeSheet/blob/master/web.ts"
    click MGI "https://github.com/KrauseFx/FxLifeSheet/blob/master/manual_graph/frontend.html"
```
