# noppanut15/depthviz architecture

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

- Interactive diagram: https://gitdiagram.com/noppanut15/depthviz
- Repository: https://github.com/noppanut15/depthviz

## Overview

##### Project Type and Purpose
- depthviz is a Python-based CLI tool (no GUI/web frontend) that transforms dive-computer or manual dive-log data into depth and time overlay videos.
- Key purpose: parse a variety of input formats (CSV, FIT, XML), smooth/interpolate depth-time data, and render overlay MP4s ready for video editing.

##### File Structure Analysis
- Top level:
- `.github/`, `docs/`, `tests/`, CI/CD and documentation.
- `pyproject.toml` for packaging and dependencies.
- `src/depthviz/` containing the application code.
- `src/depthviz/` modules:
- `__main__.py` / `main.py`: CLI entry point (argument parsing, command dispatch).
- `parsers/`: subpackages for each source format (garmin, suunto, shearwater, apnealizer, manual, generic), implementing a parser Strategy pattern.
- `optimizer/linear_interpolation.py`: smoothing/missing‐data fill.
- `video/`: modules for time/depth overlay video creation (frame generation, logging).
- `assets/`: fonts and static assets for overlay styling.
- `banner.py`, `__version__.py`: branding and metadata.
- Tests mirror structure under `tests/`, verifying parsers, optimizer, video.

##### Main Components
A. CLI Layer
- Parses user flags (`-i`, `-s`, `-o`, `--time`, styling options).
- Invokes Controller in `main.py`.
B. Parser Subsystem
- Parser Factory selects concrete parser based on `--source`.
- Each parser reads raw file (CSV, FIT, XML) → emits standardized time-depth sequences.
C. Optimizer Subsystem
- Receives raw sequence → applies Linear Interpolation → outputs uniform time series.
D. Video Generation Subsystem
- DepthOverlayCreator + TimeOverlayCreator take interpolated data + styling options + font assets → generate video frames (via ffmpeg or moviepy) → assemble MP4.
E. External Services / Artifacts
- Input dive-log files (local FS).
- Output MP4(s).
- Downstream: video editors (Premiere, CapCut) integrate overlays via chroma-key.

##### Relationships & Data Flow
1. User CLI → Controller (main.py)
2. Controller → Parser Factory → Concrete Parser → DataModel (time-depth pairs)
3. DataModel → Optimizer → SmoothedDataModel
4. SmoothedDataModel + Styling → VideoCreator
5. VideoCreator → FFmpeg / MoviePy → Output Videos
6. (Optional) Controller triggers TimeOverlayCreator in parallel for time-only MP4.

##### Architectural Patterns & Principles
- Strategy/Factory: parsers for each source share a common interface.
- Single Responsibility: parsing, optimization, rendering split into separate modules.
- Dependency Injection: styling and font assets injected into video modules.
- Pipeline/Chain of Responsibility: sequential steps (parse → optimize → render).

- All major modules (`main.py`, `parsers/`, `optimizer/`, `video/`, `assets/`) shown.
- Parser submodules grouped or called out individually if needed.
- Styling options and assets shown as configuration inputs.
- Output artifacts (depth video, time video) clearly indicated.
- CI/CD (`.github/workflows/deploy.yaml`) and packaging (`pyproject.toml`) can be shown as secondary artifacts if documenting deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External I/O
    Input["Dive-log Files<br/>(CSV, FIT, XML)"]:::external
    OutputDepth["Depth Overlay MP4"]:::external
    OutputTime["Time Overlay MP4"]:::external

    %% CLI Layer
    subgraph "CLI Layer"
        CLI_Main["__main__.py<br/>(Entry Point)"]:::cli
        CLI_Controller["main.py<br/>(Controller)"]:::cli
        CLI_Version["__version__.py"]:::cli
        CLI_Banner["banner.py"]:::cli
    end

    %% Parser Layer
    subgraph "Parser Layer"
        ParserFactory["parsers/__init__.py<br/>(Factory)"]:::parser
        PCR_Apnealizer["Apnealizer CSV Parser"]:::parser
        PCR_Garmin["Garmin FIT Parser"]:::parser
        PCR_Suunto["Suunto FIT Parser"]:::parser
        PCR_Shearwater["Shearwater XML Parser"]:::parser
        PCR_Manual["Manual CSV Parser"]:::parser
        PCR_GenericDive["Generic DIVELOG Parser"]:::parser
        PCR_GenericCSV["Generic CSV Parser"]:::parser
        PCR_GenericFIT["Generic FIT Parser"]:::parser
        PCR_GenericXML["Generic XML Parser"]:::parser
    end

    %% Optimizer Layer
    subgraph "Optimizer Layer"
        Optimizer["linear_interpolation.py"]:::optimizer
    end

    %% Renderer Layer
    subgraph "Video Renderer Layer"
        VideoCreator["video_creator.py<br/>(Core Creator)"]:::renderer
        DepthOverlay["depth.py<br/>(DepthOverlayCreator)"]:::renderer
        TimeOverlay["time.py<br/>(TimeOverlayCreator)"]:::renderer
        VideoLogger["logger.py"]:::renderer
    end

    %% Assets
    Assets["fonts Open_Sans<br/>(Assets)"]:::assets

    %% Packaging & CI/CD
    subgraph "Config & CI/CD"
        Pyproject["pyproject.toml"]:::config
        CICD[".github/workflows/deploy.yaml"]:::config
    end

    %% Data Flow
    Input -->|"raw file"| CLI_Main
    CLI_Main -->|parses flags| CLI_Controller
    CLI_Controller -->|"select parser"| ParserFactory
    ParserFactory -->|apnealizer| PCR_Apnealizer
    ParserFactory -->|garmin| PCR_Garmin
    ParserFactory -->|suunto| PCR_Suunto
    ParserFactory -->|shearwater| PCR_Shearwater
    ParserFactory -->|manual| PCR_Manual
    ParserFactory -->|generic dive| PCR_GenericDive
    ParserFactory -->|generic csv| PCR_GenericCSV
    ParserFactory -->|generic fit| PCR_GenericFIT
    ParserFactory -->|generic xml| PCR_GenericXML
    PCR_Apnealizer -->|"time-depth array"| Optimizer
    PCR_Garmin -->|"time-depth array"| Optimizer
    PCR_Suunto -->|"time-depth array"| Optimizer
    PCR_Shearwater -->|"time-depth array"| Optimizer
    PCR_Manual -->|"time-depth array"| Optimizer
    PCR_GenericDive -->|"time-depth array"| Optimizer
    PCR_GenericCSV -->|"time-depth array"| Optimizer
    PCR_GenericFIT -->|"time-depth array"| Optimizer
    PCR_GenericXML -->|"time-depth array"| Optimizer
    Optimizer -->|"smoothed data"| VideoCreator
    VideoCreator -->|uses| DepthOverlay
    VideoCreator -->|uses| TimeOverlay
    VideoCreator -->|logs| VideoLogger
    Assets -->|fonts & styles| DepthOverlay
    Assets -->|fonts & styles| TimeOverlay
    VideoCreator -->|"assemble MP4"| OutputDepth
    TimeOverlay -->|"assemble MP4"| OutputTime

    %% Click Events
    click CLI_Main "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/__main__.py"
    click CLI_Controller "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/main.py"
    click CLI_Version "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/__version__.py"
    click CLI_Banner "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/banner.py"
    click ParserFactory "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/__init__.py"
    click PCR_Apnealizer "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/apnealizer/csv_parser.py"
    click PCR_Garmin "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/garmin/fit_parser.py"
    click PCR_Suunto "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/suunto/fit_parser.py"
    click PCR_Shearwater "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/shearwater/shearwater_xml_parser.py"
    click PCR_Manual "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/manual/csv_parser.py"
    click PCR_GenericDive "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/generic/generic_divelog_parser.py"
    click PCR_GenericCSV "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/generic/csv/csv_parser.py"
    click PCR_GenericFIT "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/generic/fit/fit_parser.py"
    click PCR_GenericXML "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/parsers/generic/xml/xml_parser.py"
    click Optimizer "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/optimizer/linear_interpolation.py"
    click VideoCreator "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/video/video_creator.py"
    click DepthOverlay "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/video/depth.py"
    click TimeOverlay "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/video/time.py"
    click VideoLogger "https://github.com/noppanut15/depthviz/blob/main/src/depthviz/video/logger.py"
    click Assets "https://github.com/noppanut15/depthviz/tree/main/src/depthviz/assets/fonts/Open_Sans/"
    click Pyproject "https://github.com/noppanut15/depthviz/blob/main/pyproject.toml"
    click CICD "https://github.com/noppanut15/depthviz/blob/main/.github/workflows/deploy.yaml"

    %% Styles
    classDef cli fill:#dafbe1,stroke:#34c575,stroke-width:2px
    classDef parser fill:#d0e7ff,stroke:#1e70bf,stroke-width:2px
    classDef optimizer fill:#ffe4b3,stroke:#e69500,stroke-width:2px
    classDef renderer fill:#f3dfff,stroke:#b14da0,stroke-width:2px
    classDef external fill:#e2e2e2,stroke:#8c8c8c,stroke-width:2px
    classDef assets fill:#f0f4c3,stroke:#9e9d24,stroke-width:2px
    classDef config fill:#ffdede,stroke:#d32f2f,stroke-width:2px
```
