# anish-75/ndvi-anomaly-api architecture

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

- Interactive diagram: https://gitdiagram.com/anish-75/ndvi-anomaly-api
- Repository: https://github.com/anish-75/ndvi-anomaly-api

## Overview

This prototype accepts 12-week NDVI windows through a FastAPI service, validates them, and flags anomalies when autoencoder reconstruction error exceeds a configured threshold. It also supports online retraining and a separate offline workflow for generating synthetic series, training the autoencoder, and calibrating the threshold. The graph reflects the documented offline stages, but the referenced data files and model weights are not present in the supplied tree; their runtime details are therefore not expanded.

Main entry points: [`app/main.py`](https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/main.py) (API routes), [`app/inference.py`](https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/inference.py) (Inference operations), [`models`](https://github.com/anish-75/ndvi-anomaly-api/tree/main/models) (Model artifacts), [`training/evaluate_threshold.py`](https://github.com/anish-75/ndvi-anomaly-api/blob/main/training/evaluate_threshold.py) (Threshold evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_service["API service"]
  node_api["API routes<br/>[main.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
end

subgraph group_inference["Inference and training"]
  node_inference_engine["Inference operations<br/>[inference.py]"]
  node_autoencoder["NDVI autoencoder<br/>[model.py]"]
  node_online_training["Online retraining<br/>[inference.py]"]
end

subgraph group_offline["Offline model workflow"]
  node_simulator["Synthetic NDVI generator<br/>[simulate_ndvi.py]"]
  node_offline_trainer["Offline trainer"]
  node_threshold_eval["Threshold evaluation"]
end

subgraph group_artifacts["Model artifacts"]
  node_model_artifacts["Model artifacts"]
  node_threshold_config["Threshold configuration<br/>[threshold.json]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_api
node_api -->|"validates with"| node_schemas
node_api -->|"loads at startup"| node_inference_engine
node_api -->|"computes error"| node_inference_engine
node_api -->|"retrain request"| node_inference_engine
node_inference_engine -->|"runs model"| node_autoencoder
node_inference_engine -->|"loads and saves weights"| node_model_artifacts
node_inference_engine -->|"reads and writes"| node_threshold_config
node_api -->|"dispatches retraining"| node_online_training
node_online_training -->|"updates weights"| node_autoencoder
node_simulator -->|"generates training data for"| node_offline_trainer
node_offline_trainer -->|"saves weights"| node_model_artifacts
node_threshold_eval -->|"loads weights"| node_model_artifacts
node_threshold_eval -->|"writes threshold"| node_threshold_config

click node_api "https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/main.py"
click node_schemas "https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/schemas.py"
click node_inference_engine "https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/inference.py"
click node_autoencoder "https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/model.py"
click node_online_training "https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/inference.py"
click node_simulator "https://github.com/anish-75/ndvi-anomaly-api/blob/main/training/simulate_ndvi.py"
click node_offline_trainer "https://github.com/anish-75/ndvi-anomaly-api/blob/main/training/train_autoencoder.py"
click node_threshold_eval "https://github.com/anish-75/ndvi-anomaly-api/blob/main/training/evaluate_threshold.py"
click node_model_artifacts "https://github.com/anish-75/ndvi-anomaly-api/tree/main/models"
click node_threshold_config "https://github.com/anish-75/ndvi-anomaly-api/blob/main/models/threshold.json"

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_api,node_schemas,node_client toneBlue
class node_inference_engine,node_autoencoder,node_online_training toneAmber
class node_simulator,node_offline_trainer,node_threshold_eval toneMint
class node_model_artifacts,node_threshold_config toneRose
```

## Components

### API service

- [API routes](https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/main.py): `app/main.py`
- [Request schemas](https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/schemas.py): `app/schemas.py`

### Inference and training

- [Inference operations](https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/inference.py): `app/inference.py`
- [NDVI autoencoder](https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/model.py): `app/model.py`
- [Online retraining](https://github.com/anish-75/ndvi-anomaly-api/blob/main/app/inference.py): `app/inference.py`

### Offline model workflow

- [Synthetic NDVI generator](https://github.com/anish-75/ndvi-anomaly-api/blob/main/training/simulate_ndvi.py): `training/simulate_ndvi.py`
- [Offline trainer](https://github.com/anish-75/ndvi-anomaly-api/blob/main/training/train_autoencoder.py): `training/train_autoencoder.py`
- [Threshold evaluation](https://github.com/anish-75/ndvi-anomaly-api/blob/main/training/evaluate_threshold.py): `training/evaluate_threshold.py`

### Model artifacts

- [Model artifacts](https://github.com/anish-75/ndvi-anomaly-api/tree/main/models): `models`
- [Threshold configuration](https://github.com/anish-75/ndvi-anomaly-api/blob/main/models/threshold.json): `models/threshold.json`

### Other components

- **API client**

## Connections

- API client → API routes: sends requests
- API routes → Request schemas: validates with
- API routes → Inference operations: loads at startup
- API routes → Inference operations: computes error
- API routes → Inference operations: retrain request
- Inference operations → NDVI autoencoder: runs model
- Inference operations → Model artifacts: loads and saves weights
- Inference operations → Threshold configuration: reads and writes
- API routes → Online retraining: dispatches retraining
- Online retraining → NDVI autoencoder: updates weights
- Synthetic NDVI generator → Offline trainer: generates training data for
- Offline trainer → Model artifacts: saves weights
- Threshold evaluation → Model artifacts: loads weights
- Threshold evaluation → Threshold configuration: writes threshold
