# hibrahimboz/leafvision architecture

> Architecture diagram of the GitHub repository hibrahimboz/leafvision, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hibrahimboz/leafvision
- Repository: https://github.com/hibrahimboz/leafvision

## Overview

LeafVision is a single-image leaf-boundary segmentation application: a user uploads an image through the web interface, the FastAPI endpoint passes it to the C++ OpenCV pipeline, and the interface receives the seven visualized stages. The graph preserves the documented processing stages and API/UI flow. Source excerpts do not show the HTML’s request handling, so that connection is based on the README; unimplemented roadmap capabilities are excluded.

Main entry points: [`src/api/server.py`](https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py) (FastAPI service), [`src/api/static/index.html`](https://github.com/hibrahimboz/leafvision/blob/master/src/api/static/index.html) (Upload interface), [`src/core/leaf_boundary.cpp`](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp) (Python binding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_web["Upload interface<br/>[index.html]"]
end

subgraph group_service["API service"]
  node_api["FastAPI service<br/>[server.py]"]
  node_decode["Image decoding<br/>[server.py]"]
  node_temp["Temporary image<br/>[server.py]"]
  node_encode["JPEG encoding<br/>[server.py]"]
  node_response["Pipeline response<br/>[server.py]"]
end

subgraph group_vision["Segmentation engine"]
  node_binding["Python binding<br/>[leaf_boundary.cpp]"]
  node_original["Original image<br/>[leaf_boundary.cpp]"]
  node_color["Color mask<br/>[leaf_boundary.cpp]"]
  node_clean["Cleaned mask<br/>[leaf_boundary.cpp]"]
  node_distance["Distance map<br/>[leaf_boundary.cpp]"]
  node_seeds["Foreground seeds<br/>[leaf_boundary.cpp]"]
  node_markers["Watershed markers<br/>[leaf_boundary.cpp]"]
  node_edges["Final boundaries<br/>[leaf_boundary.cpp]"]
end

node_user(("Image user"))

node_user -->|"selects image"| node_web
node_web -->|"uploads image"| node_api
node_api -->|"reads upload"| node_decode
node_decode -->|"writes JPEG"| node_temp
node_api -->|"calls process_leaf"| node_binding
node_binding -->|"reads image"| node_original
node_original -->|"extracts color"| node_color
node_color -->|"thresholds and cleans"| node_clean
node_clean -->|"computes distance"| node_distance
node_distance -->|"derives foreground"| node_seeds
node_seeds -->|"builds markers"| node_markers
node_markers -->|"runs watershed"| node_edges
node_api -->|"encodes pipeline"| node_encode
node_encode -->|"builds response"| node_response
node_api -->|"returns JSON"| node_response
node_response -->|"displays stages"| node_web

click node_web "https://github.com/hibrahimboz/leafvision/blob/master/src/api/static/index.html"
click node_api "https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py"
click node_decode "https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py"
click node_temp "https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py"
click node_binding "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_original "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_color "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_clean "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_distance "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_seeds "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_markers "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_edges "https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp"
click node_encode "https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py"
click node_response "https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_user toneBlue
class node_api,node_decode,node_temp,node_encode,node_response toneAmber
class node_binding,node_original,node_color,node_clean,node_distance,node_seeds,node_markers,node_edges toneMint
```

## Components

### Web client

- [Upload interface](https://github.com/hibrahimboz/leafvision/blob/master/src/api/static/index.html): `src/api/static/index.html`

### API service

- [FastAPI service](https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py): `src/api/server.py`
- [Image decoding](https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py): `src/api/server.py`
- [Temporary image](https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py): `src/api/server.py`
- [JPEG encoding](https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py): `src/api/server.py`
- [Pipeline response](https://github.com/hibrahimboz/leafvision/blob/master/src/api/server.py): `src/api/server.py`

### Segmentation engine

- [Python binding](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`
- [Original image](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`
- [Color mask](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`
- [Cleaned mask](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`
- [Distance map](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`
- [Foreground seeds](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`
- [Watershed markers](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`
- [Final boundaries](https://github.com/hibrahimboz/leafvision/blob/master/src/core/leaf_boundary.cpp): `src/core/leaf_boundary.cpp`

### Other components

- **Image user**

## Connections

- Image user → Upload interface: selects image
- Upload interface → FastAPI service: uploads image
- FastAPI service → Image decoding: reads upload
- Image decoding → Temporary image: writes JPEG
- FastAPI service → Python binding: calls process_leaf
- Python binding → Original image: reads image
- Original image → Color mask: extracts color
- Color mask → Cleaned mask: thresholds and cleans
- Cleaned mask → Distance map: computes distance
- Distance map → Foreground seeds: derives foreground
- Foreground seeds → Watershed markers: builds markers
- Watershed markers → Final boundaries: runs watershed
- FastAPI service → JPEG encoding: encodes pipeline
- JPEG encoding → Pipeline response: builds response
- FastAPI service → Pipeline response: returns JSON
- Pipeline response → Upload interface: displays stages
