# forkerer/renphogarminsync-cli architecture

> Architecture diagram of the GitHub repository forkerer/renphogarminsync-cli, 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/forkerer/renphogarminsync-cli
- Repository: https://github.com/forkerer/renphogarminsync-cli

## Overview

##### Main Components

a. Core Application Layer:
- Console Application (Entry Point)
- Command Handlers (Sync, Garmin Auth, Renpho Auth)
- FIT File Generator
- Configuration Management

b. Renpho Integration:
- Renpho API Client
- Renpho Authentication Service
- Renpho Data Models

c. Garmin Integration:
- Garmin API Client
- Garmin Authentication Service
- Garmin Data Models

d. Persistence Layer:
- Measurement History Repository
- Auth Token Caches
- FIT File Storage

**┌─────────────────────────────────────────────────────────────┐**
- Console Application                       │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Command Handlers                          │
- ┬─────────────────────┬───────────────────┤
- Sync Handler  │  Garmin Auth Handler│ Renpho Auth Handler│
- ┴─────────────────────┴───────────────────┘
- ↓                    ↓                    ↓
**┌─────────────────┐  ┌─────────────────┐  ┌───────────────────┐**
- Renpho API    │  │   Garmin API    │  │    FIT Generator  │
- Integration  │←→│   Integration   │←→│    & Converter    │
- ┘  └─────────────────┘  └───────────────────┘
- ↓                    ↓                    ↓
**┌─────────────────────────────────────────────────────────────┐**
- Persistence Layer                         │
- ┬─────────────────────┬───────────────────┤
- Auth Caches    │ Measurement History │    FIT Files      │
- ┴─────────────────────┴───────────────────┘

##### Important Relationships to Highlight

- Bidirectional flow between the Command Handlers and their respective API integrations
- Data flow from Renpho API → FIT Generator → Garmin API
- Relationship between authentication services and their respective caches
- Demonstrate how the measurement history repository tracks synced data

##### Additional Elements

- External System Boundaries (Renpho and Garmin services)
- Security Components (AES encryption for stored credentials)
- Configuration Management
- Error Handling Flow

##### Technical Details to Note

- Authentication Flows (including MFA support for Garmin)
- Data Transformation Process (Renpho measurements → FIT format)
- Caching Mechanisms
- File Storage Structure

##### Implementation Notes

- Clear separation between Renpho and Garmin integrations
- The central role of the sync command handler
- The importance of the persistence layer in preventing duplicate syncs
- The modular nature of the authentication systems

Remember to:
- Use consistent notation throughout
- Notes for important implementation details (e.g., encryption, MFA handling)

This system design should provide a clear understanding of how the application coordinates data flow between Renpho and Garmin while maintaining security and preventing duplicate syncs.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Console
        EntryPoint["Console Application"]:::core
        click EntryPoint "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Console/Program.cs"
        
        subgraph CommandHandlers
            SyncHandler["Sync Handler"]:::core
            GarminAuthHandler["Garmin Auth Handler"]:::core
            RenphoAuthHandler["Renpho Auth Handler"]:::core
            click SyncHandler "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Console/RenphoGarminSyncCommandHandler.cs"
            click GarminAuthHandler "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Console/GarminAuthCommandHandler.cs"
            click RenphoAuthHandler "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Console/RenphoAuthCommandHandler.cs"
        end
        
        Config["Configuration Management"]:::core
        click Config "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Console/ConfigurationHelper.cs"
    end
    
    subgraph Integration
        subgraph RenphoInt["Renpho Integration"]
            RenphoAPI["Renpho API Client"]:::renpho
            RenphoAuth["Renpho Auth Service"]:::renpho
            RenphoEncrypt["Renpho Encryption"]:::security
            click RenphoAPI "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Renpho.Api/RenphoApi.cs"
            click RenphoAuth "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Renpho.Auth/RenphoAuthService.cs"
            click RenphoEncrypt "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Renpho.Shared/AesUtility.cs"
        end
        
        FITGen["FIT Generator"]:::core
        click FITGen "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Console/FitGenerator.cs"
        
        subgraph GarminInt["Garmin Integration"]
            GarminAPI["Garmin API Client"]:::garmin
            GarminAuth["Garmin Auth Service"]:::garmin
            GarminEncrypt["Garmin Encryption"]:::security
            click GarminAPI "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Garmin.Api/GarminApi.cs"
            click GarminAuth "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Garmin.Auth/GarminAuthService.cs"
            click GarminEncrypt "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Garmin.Shared/AesUtility.cs"
        end
    end
    
    subgraph Persistence
        MeasurementHistory["Measurement History"]:::storage
        RenphoCache["Renpho Auth Cache"]:::storage
        GarminCache["Garmin Auth Cache"]:::storage
        FITStorage["FIT Files"]:::storage
        click MeasurementHistory "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Console/Persistence/CSVHandledMeasurementsRepository.cs"
        click RenphoCache "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Renpho.Auth/Persistence/RenphoInMemoryAuthCache.cs"
        click GarminCache "https://github.com/forkerer/RenphoGarminSync-CLI/blob/main/RenphoGarminSync.Garmin.Auth/Persistence/GarminFileBasedAuthCache.cs"
    end
    
    EntryPoint --> CommandHandlers
    EntryPoint --> Config
    
    SyncHandler --> RenphoAPI
    SyncHandler --> GarminAPI
    SyncHandler --> FITGen
    
    GarminAuthHandler --> GarminAuth
    RenphoAuthHandler --> RenphoAuth
    
    RenphoAPI <--> FITGen
    FITGen <--> GarminAPI
    
    RenphoAuth <--> RenphoCache
    GarminAuth <--> GarminCache
    
    RenphoAuth --> RenphoEncrypt
    GarminAuth --> GarminEncrypt
    
    SyncHandler --> MeasurementHistory
    FITGen --> FITStorage
    
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef renpho fill:#2ecc71,stroke:#27ae60,color:white
    classDef garmin fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    
    %% Legend
    subgraph Legend
        CoreComponent["Core Component"]:::core
        RenphoComponent["Renpho Component"]:::renpho
        GarminComponent["Garmin Component"]:::garmin
        StorageComponent["Storage Component"]:::storage
        SecurityComponent["Security Component"]:::security
    end
```
