# changetechlab/agri_monitor architecture

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

- Interactive diagram: https://gitdiagram.com/changetechlab/agri_monitor
- Repository: https://github.com/changetechlab/agri_monitor

## Overview

AgriMonitor is an offline-capable GIS and field-monitoring web app for agriculture, climate resilience, rural planning, and carbon projects. Field staff use the dashboard to select locations, view spatial and farmer data, and collect records; separate climate-activity and MRV workflows track interventions and calculate carbon results for local storage and reporting. The README documents mapping, farmer management, analytics, and PWA behavior; sampled code confirms bootstrap, MRV, satellite, and offline details. Other capability links reflect README documentation, not inspected call sites.

Main entry points: [`js/app.js`](https://github.com/changetechlab/agri_monitor/blob/main/js/app.js) (App coordinator), [`js/mrv/mrv.js`](https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/mrv.js) (MRV workflow), [`index.html`](https://github.com/changetechlab/agri_monitor/blob/main/index.html) (GIS dashboard), [`api/gee-tiles.js`](https://github.com/changetechlab/agri_monitor/blob/main/api/gee-tiles.js) (Earth Engine tile API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard and GIS"]
  node_dashboard_ui["GIS dashboard<br/>[index.html]"]
  node_coordinator["App coordinator<br/>[app.js]"]
  node_map["Interactive map<br/>[map.js]"]
  node_layers["Spatial layers<br/>[layers.js]"]
  node_boundaries["Village boundaries"]
  node_village_data["Village directory<br/>[lgd_villages.js]"]
  node_analytics["Charts and reports<br/>[charts.js]"]
end

subgraph group_field["Field Data"]
  node_farmer_mgmt["Farmer management<br/>[farmers.js]"]
end

subgraph group_climate["Climate and Carbon"]
  node_climate_ui["Climate activities"]
  node_climate_module["Activity tracking<br/>[climate.js]"]
  node_mrv_ui["Carbon MRV<br/>[mrv.html]"]
  node_mrv_controller["MRV workflow<br/>[mrv.js]"]
  node_carbon_calc["Carbon calculator<br/>[calculator.js]"]
  node_mrv_storage[("MRV records<br/>[storage.js]")]
  node_mrv_pdf["PDF reports<br/>[pdf.js]"]
end

subgraph group_platform["Platform Services"]
  node_offline["Offline records<br/>[offline.js]"]
  node_service_worker["PWA caching<br/>[sw.js]"]
  node_supabase_auth["Authentication<br/>[auth.js]"]
  node_supabase_db[("Supabase<br/>[schema.sql]")]
end

subgraph group_satellite["Satellite Analysis"]
  node_satellite_engine["Satellite indices"]
  node_tile_api["Earth Engine tile API<br/>[gee-tiles.js]"]
  node_gee_auth["GEE authentication<br/>[_gee-auth.js]"]
end

node_staff(("Field staff"))
node_earth_engine["Google Earth Engine"]

node_staff -->|"uses"| node_dashboard_ui
node_dashboard_ui -->|"loads"| node_coordinator
node_coordinator -->|"initializes"| node_map
node_coordinator -->|"initializes"| node_layers
node_layers -->|"reads"| node_boundaries
node_coordinator -->|"initializes"| node_farmer_mgmt
node_farmer_mgmt -->|"uses"| node_village_data
node_coordinator -->|"initializes"| node_offline
node_service_worker -->|"caches"| node_dashboard_ui
node_staff -->|"records activity"| node_climate_ui
node_climate_ui -->|"loads"| node_climate_module
node_staff -->|"starts MRV"| node_mrv_ui
node_mrv_ui -->|"loads"| node_mrv_controller
node_mrv_controller -->|"calculates"| node_carbon_calc
node_mrv_controller -->|"saves records"| node_mrv_storage
node_mrv_controller -->|"exports report"| node_mrv_pdf
node_staff -->|"views analytics"| node_dashboard_ui
node_coordinator -->|"initializes"| node_analytics
node_map -.->|"requests indices"| node_satellite_engine
node_satellite_engine -->|"fetches tiles"| node_tile_api
node_tile_api -->|"authenticates"| node_gee_auth
node_tile_api -->|"requests imagery"| node_earth_engine
node_supabase_auth -.->|"authenticates"| node_supabase_db
node_offline -.->|"syncs records"| node_supabase_db
node_mrv_storage -.->|"cloud adapter"| node_supabase_db

click node_dashboard_ui "https://github.com/changetechlab/agri_monitor/blob/main/index.html"
click node_coordinator "https://github.com/changetechlab/agri_monitor/blob/main/js/app.js"
click node_map "https://github.com/changetechlab/agri_monitor/blob/main/js/map.js"
click node_layers "https://github.com/changetechlab/agri_monitor/blob/main/js/layers.js"
click node_boundaries "https://github.com/changetechlab/agri_monitor/tree/main/data/gp_boundaries"
click node_village_data "https://github.com/changetechlab/agri_monitor/blob/main/data/lgd_villages.js"
click node_farmer_mgmt "https://github.com/changetechlab/agri_monitor/blob/main/js/farmers.js"
click node_offline "https://github.com/changetechlab/agri_monitor/blob/main/js/offline.js"
click node_service_worker "https://github.com/changetechlab/agri_monitor/blob/main/sw.js"
click node_supabase_auth "https://github.com/changetechlab/agri_monitor/blob/main/js/auth.js"
click node_supabase_db "https://github.com/changetechlab/agri_monitor/blob/main/supabase/schema.sql"
click node_climate_ui "https://github.com/changetechlab/agri_monitor/blob/main/climate-activities.html"
click node_climate_module "https://github.com/changetechlab/agri_monitor/blob/main/js/modules/climate.js"
click node_mrv_ui "https://github.com/changetechlab/agri_monitor/blob/main/mrv.html"
click node_mrv_controller "https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/mrv.js"
click node_carbon_calc "https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/calculator.js"
click node_mrv_storage "https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/storage.js"
click node_mrv_pdf "https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/pdf.js"
click node_analytics "https://github.com/changetechlab/agri_monitor/blob/main/js/charts.js"
click node_satellite_engine "https://github.com/changetechlab/agri_monitor/blob/main/js/satellite-engine.js"
click node_tile_api "https://github.com/changetechlab/agri_monitor/blob/main/api/gee-tiles.js"
click node_gee_auth "https://github.com/changetechlab/agri_monitor/blob/main/api/_gee-auth.js"

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_dashboard_ui,node_coordinator,node_map,node_layers,node_boundaries,node_village_data,node_analytics toneBlue
class node_farmer_mgmt toneAmber
class node_climate_ui,node_climate_module,node_mrv_ui,node_mrv_controller,node_carbon_calc,node_mrv_storage,node_mrv_pdf toneMint
class node_offline,node_service_worker,node_supabase_auth,node_supabase_db toneRose
class node_satellite_engine,node_tile_api,node_gee_auth,node_staff,node_earth_engine toneIndigo
```

## Components

### Dashboard and GIS

- [GIS dashboard](https://github.com/changetechlab/agri_monitor/blob/main/index.html): `index.html`
- [App coordinator](https://github.com/changetechlab/agri_monitor/blob/main/js/app.js): `js/app.js`
- [Interactive map](https://github.com/changetechlab/agri_monitor/blob/main/js/map.js): `js/map.js`
- [Spatial layers](https://github.com/changetechlab/agri_monitor/blob/main/js/layers.js): `js/layers.js`
- [Village boundaries](https://github.com/changetechlab/agri_monitor/tree/main/data/gp_boundaries): `data/gp_boundaries`
- [Village directory](https://github.com/changetechlab/agri_monitor/blob/main/data/lgd_villages.js): `data/lgd_villages.js`
- [Charts and reports](https://github.com/changetechlab/agri_monitor/blob/main/js/charts.js): `js/charts.js`

### Field Data

- [Farmer management](https://github.com/changetechlab/agri_monitor/blob/main/js/farmers.js): `js/farmers.js`

### Climate and Carbon

- [Climate activities](https://github.com/changetechlab/agri_monitor/blob/main/climate-activities.html): `climate-activities.html`
- [Activity tracking](https://github.com/changetechlab/agri_monitor/blob/main/js/modules/climate.js): `js/modules/climate.js`
- [Carbon MRV](https://github.com/changetechlab/agri_monitor/blob/main/mrv.html): `mrv.html`
- [MRV workflow](https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/mrv.js): `js/mrv/mrv.js`
- [Carbon calculator](https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/calculator.js): `js/mrv/calculator.js`
- [MRV records](https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/storage.js): `js/mrv/storage.js`
- [PDF reports](https://github.com/changetechlab/agri_monitor/blob/main/js/mrv/pdf.js): `js/mrv/pdf.js`

### Platform Services

- [Offline records](https://github.com/changetechlab/agri_monitor/blob/main/js/offline.js): `js/offline.js`
- [PWA caching](https://github.com/changetechlab/agri_monitor/blob/main/sw.js): `sw.js`
- [Authentication](https://github.com/changetechlab/agri_monitor/blob/main/js/auth.js): `js/auth.js`
- [Supabase](https://github.com/changetechlab/agri_monitor/blob/main/supabase/schema.sql): `supabase/schema.sql`

### Satellite Analysis

- [Satellite indices](https://github.com/changetechlab/agri_monitor/blob/main/js/satellite-engine.js): `js/satellite-engine.js`
- [Earth Engine tile API](https://github.com/changetechlab/agri_monitor/blob/main/api/gee-tiles.js): `api/gee-tiles.js`
- [GEE authentication](https://github.com/changetechlab/agri_monitor/blob/main/api/_gee-auth.js): `api/_gee-auth.js`

### Other components

- **Field staff**
- **Google Earth Engine**

## Connections

- Field staff → GIS dashboard: uses
- GIS dashboard → App coordinator: loads
- App coordinator → Interactive map: initializes
- App coordinator → Spatial layers: initializes
- Spatial layers → Village boundaries: reads
- App coordinator → Farmer management: initializes
- Farmer management → Village directory: uses
- App coordinator → Offline records: initializes
- PWA caching → GIS dashboard: caches
- Field staff → Climate activities: records activity
- Climate activities → Activity tracking: loads
- Field staff → Carbon MRV: starts MRV
- Carbon MRV → MRV workflow: loads
- MRV workflow → Carbon calculator: calculates
- MRV workflow → MRV records: saves records
- MRV workflow → PDF reports: exports report
- Field staff → GIS dashboard: views analytics
- App coordinator → Charts and reports: initializes
- Interactive map → Satellite indices: requests indices
- Satellite indices → Earth Engine tile API: fetches tiles
- Earth Engine tile API → GEE authentication: authenticates
- Earth Engine tile API → Google Earth Engine: requests imagery
- Authentication → Supabase: authenticates
- Offline records → Supabase: syncs records
- MRV records → Supabase: cloud adapter
