# tecnom1k3/swensen-calculator architecture

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

- Interactive diagram: https://gitdiagram.com/tecnom1k3/swensen-calculator
- Repository: https://github.com/tecnom1k3/swensen-calculator

## Overview

- .env file → Main Controller
- Configuration parameters (funds, tickers, API key, etc.)

- Main Controller → Market Price Service
- Market Price Service → Alpha Vantage API
- Market Price Service → Cache Layer (bidirectional)

- Step-by-step calculation process
- Fund allocation
- Share calculation
- Investment summary generation

##### Specific Elements

a. Configuration Section
- Category funds (DME, FRE, EME, TRE, TBI, PEQ)
- Ticker mappings
- API configuration
- Cache settings

b. Processing Pipeline
- Market price retrieval
- Price adjustment calculation
- Share allocation
- Investment summary generation

c. Output Generation
- Funds summary
- Category details
- Investment calculations
- Warning/Error handling

##### Key Aspects to Highlight

- Cache mechanism for market prices
- Error handling paths
- Configuration validation
- Category processing logic
- Price adjustment calculations

##### Technical Details

- Python 3.9+ requirement
- External dependencies (from requirements.txt)
- Cache TTL setting
- Price increase ratio logic

**[Configuration Layer]**
- ↓
**[Input Processing Layer]**
- ↓
**[Market Data Layer]**
- ↓
**[Calculation Layer]**
- ↓
**[Output Generation Layer]**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        style Legend fill:#f5f5f5,stroke:#333
        L1[Input/Config]:::input
        L2[/Processing/]:::process
        L3[(Storage)]:::storage
        L4([External Service]):::external
        L5>Output]:::output
    end

    subgraph Configuration
        ENV[".env File"]:::input
        ENVS[".env.sample"]:::input
        REQ["requirements.txt"]:::input
        click ENVS "https://github.com/tecnom1k3/swensen-calculator/blob/main/.env.sample"
        click REQ "https://github.com/tecnom1k3/swensen-calculator/blob/main/requirements.txt"
    end

    subgraph "Input Processing"
        MC["Main Controller"]:::process
        click MC "https://github.com/tecnom1k3/swensen-calculator/blob/main/main.py"
    end

    subgraph "Market Data Layer"
        MPS["Market Price Service"]:::process
        CACHE[(Cache)]:::storage
        AV([Alpha Vantage API]):::external
        click MPS "https://github.com/tecnom1k3/swensen-calculator/blob/main/market_price.py"
        click CACHE "https://github.com/tecnom1k3/swensen-calculator/blob/main/.cache"
    end

    subgraph "Calculation Layer"
        FUND[/"Fund Allocation"/]:::process
        SHARE[/"Share Calculation"/]:::process
        ADJUST[/"Price Adjustment"/]:::process
    end

    subgraph "Output Layer"
        SUM>Investment Summary]:::output
        CAT>Category Details]:::output
        WARN>Warnings/Errors]:::output
    end

    %% Relationships
    ENV -->|Config| MC
    ENVS -.->|Template| ENV
    REQ -.->|Dependencies| MC
    MC -->|Request Data| MPS
    MPS -->|Query| AV
    MPS ---|Cache Check| CACHE
    CACHE ---|Store/Retrieve| MPS
    MPS -->|Price Data| FUND
    FUND -->|Allocation| SHARE
    SHARE -->|Calculations| ADJUST
    ADJUST -->|Results| SUM
    ADJUST -->|Details| CAT
    MC -->|Errors| WARN

    classDef input fill:#a8d1ff,stroke:#333
    classDef process fill:#90EE90,stroke:#333
    classDef storage fill:#d3d3d3,stroke:#333
    classDef external fill:#FFE5B4,stroke:#333
    classDef output fill:#ff9999,stroke:#333
```
