# azavo/bugfinder architecture

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

- Interactive diagram: https://gitdiagram.com/azavo/bugfinder
- Repository: https://github.com/azavo/bugfinder

## Overview

BugFinder predicts insect species for a selected northeastern or midwestern US location and date. Users set location on the map, optionally enter an iNaturalist username and order filter, and submit a request; the backend assembles environmental and temporal features, scores species with a loaded model, applies optional filters, and returns ranked results for display. The README documents the product’s regional focus; sampled source shows the prediction and unseen-species workflow. Model assets are fetched from GitHub when absent. Other README-level capabilities were not specified.

Main entry points: [`root/backend/main.py`](https://github.com/azavo/bugfinder/blob/main/root/backend/main.py) (FastAPI endpoints), [`root/frontend/src/App.jsx`](https://github.com/azavo/bugfinder/blob/main/root/frontend/src/App.jsx) (Prediction form), [`root/frontend/src/MapPicker.jsx`](https://github.com/azavo/bugfinder/blob/main/root/frontend/src/MapPicker.jsx) (Location map), [`root/backend/model_loader.py`](https://github.com/azavo/bugfinder/blob/main/root/backend/model_loader.py) (Model and metadata loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User interface"]
  node_app["Prediction form<br/>[App.jsx]"]
  node_map["Location map<br/>[MapPicker.jsx]"]
end

subgraph group_api["Prediction API"]
  node_api["FastAPI endpoints<br/>[main.py]"]
end

subgraph group_context["Environmental context"]
  node_features["Location and time features<br/>[features.py]"]
  node_weather["Weather lookup<br/>[weather.py]"]
  node_inat["Seen-species lookup<br/>[inat.py]"]
end

subgraph group_prediction["Species prediction"]
  node_loader["Model and metadata loader<br/>[model_loader.py]"]
  node_artifacts["Model and geo assets"]
  node_classifier["Species classifier<br/>[model_loader.py]"]
end

node_user(("BugFinder user"))
node_tiles["OpenStreetMap tiles"]
node_openmeteo["Open-Meteo"]
node_inatservice["iNaturalist API"]
node_releases["GitHub releases"]

node_user -->|"sets inputs"| node_app
node_app -->|"selects location"| node_map
node_map -->|"reports coordinates"| node_app
node_map -->|"loads tiles"| node_tiles
node_app -->|"requests predictions"| node_api
node_api -->|"returns predictions"| node_app
node_api -->|"computes features"| node_features
node_api -->|"gets weather"| node_weather
node_weather -->|"fetches conditions"| node_openmeteo
node_api -->|"uses model assets"| node_loader
node_loader -->|"loads assets"| node_artifacts
node_loader -->|"downloads missing assets"| node_releases
node_api -->|"scores features"| node_classifier
node_api -->|"filters seen species"| node_inat
node_inat -->|"fetches observations"| node_inatservice

click node_app "https://github.com/azavo/bugfinder/blob/main/root/frontend/src/App.jsx"
click node_map "https://github.com/azavo/bugfinder/blob/main/root/frontend/src/MapPicker.jsx"
click node_api "https://github.com/azavo/bugfinder/blob/main/root/backend/main.py"
click node_features "https://github.com/azavo/bugfinder/blob/main/root/backend/features.py"
click node_weather "https://github.com/azavo/bugfinder/blob/main/root/backend/weather.py"
click node_inat "https://github.com/azavo/bugfinder/blob/main/root/backend/inat.py"
click node_loader "https://github.com/azavo/bugfinder/blob/main/root/backend/model_loader.py"
click node_classifier "https://github.com/azavo/bugfinder/blob/main/root/backend/model_loader.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_app,node_map,node_user toneBlue
class node_api toneAmber
class node_features,node_weather,node_inat,node_inatservice toneMint
class node_loader,node_artifacts,node_classifier toneRose
class node_tiles,node_openmeteo,node_releases toneIndigo
```

## Components

### User interface

- [Prediction form](https://github.com/azavo/bugfinder/blob/main/root/frontend/src/App.jsx): `root/frontend/src/App.jsx`
- [Location map](https://github.com/azavo/bugfinder/blob/main/root/frontend/src/MapPicker.jsx): `root/frontend/src/MapPicker.jsx`

### Prediction API

- [FastAPI endpoints](https://github.com/azavo/bugfinder/blob/main/root/backend/main.py): `root/backend/main.py`

### Environmental context

- [Location and time features](https://github.com/azavo/bugfinder/blob/main/root/backend/features.py): `root/backend/features.py`
- [Weather lookup](https://github.com/azavo/bugfinder/blob/main/root/backend/weather.py): `root/backend/weather.py`
- [Seen-species lookup](https://github.com/azavo/bugfinder/blob/main/root/backend/inat.py): `root/backend/inat.py`

### Species prediction

- [Model and metadata loader](https://github.com/azavo/bugfinder/blob/main/root/backend/model_loader.py): `root/backend/model_loader.py`
- **Model and geo assets**
- [Species classifier](https://github.com/azavo/bugfinder/blob/main/root/backend/model_loader.py): `root/backend/model_loader.py`

### Other components

- **BugFinder user**
- **OpenStreetMap tiles**
- **Open-Meteo**
- **iNaturalist API**
- **GitHub releases**

## Connections

- BugFinder user → Prediction form: sets inputs (evidence: `root/frontend/src/App.jsx`)
- Prediction form → Location map: selects location (evidence: `root/frontend/src/App.jsx`)
- Location map → Prediction form: reports coordinates (evidence: `root/frontend/src/MapPicker.jsx`)
- Location map → OpenStreetMap tiles: loads tiles (evidence: `root/frontend/src/MapPicker.jsx`)
- Prediction form → FastAPI endpoints: requests predictions (evidence: `root/frontend/src/App.jsx`)
- FastAPI endpoints → Prediction form: returns predictions (evidence: `root/backend/main.py`)
- FastAPI endpoints → Location and time features: computes features (evidence: `root/backend/main.py`)
- FastAPI endpoints → Weather lookup: gets weather (evidence: `root/backend/main.py`)
- Weather lookup → Open-Meteo: fetches conditions (evidence: `root/backend/weather.py`)
- FastAPI endpoints → Model and metadata loader: uses model assets (evidence: `root/backend/main.py`)
- Model and metadata loader → Model and geo assets: loads assets (evidence: `root/backend/model_loader.py`)
- Model and metadata loader → GitHub releases: downloads missing assets (evidence: `root/backend/model_loader.py`)
- FastAPI endpoints → Species classifier: scores features (evidence: `root/backend/main.py`)
- FastAPI endpoints → Seen-species lookup: filters seen species (evidence: `root/backend/main.py`)
- Seen-species lookup → iNaturalist API: fetches observations (evidence: `root/backend/inat.py`)
