# pharelouindou/bam architecture

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

- Interactive diagram: https://gitdiagram.com/pharelouindou/bam
- Repository: https://github.com/pharelouindou/bam
- Video tour (about a minute): https://gitdiagram.com/pharelouindou/bam/video

## Overview

BeninAquaMap (BAM) collects environmental and satellite observations, scores water/soil suitability, and stores site and national-grid results in PostgreSQL. Its main workflows are the site pipeline and a department-oriented grid workflow, which adds commune mapping, terrain/soil/weather enrichment, satellite analysis, and daily history. The repository also includes an API and a Grafana dashboard. Connections below are limited to README statements and source-index references or excerpts; some API and presentation wiring is not shown.

Main entry points: [`main.py`](https://github.com/pharelouindou/bam/blob/main/main.py) (Site pipeline), [`process/enrichir_grille.py`](https://github.com/pharelouindou/bam/blob/main/process/enrichir_grille.py) (Grid enrichment), [`process/analyser_grille.py`](https://github.com/pharelouindou/bam/blob/main/process/analyser_grille.py) (Grid satellite analysis), [`db/connexion.py`](https://github.com/pharelouindou/bam/blob/main/db/connexion.py) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Collection workflows"]
  node_site_pipeline["Site pipeline<br/>[main.py]"]
  node_grid_flow["Department flow<br/>[bam_pipeline.py]"]
  node_grid_enrichment["Grid enrichment<br/>[enrichir_grille.py]"]
  node_grid_satellite["Grid satellite analysis<br/>[analyser_grille.py]"]
end

subgraph group_observations["Environmental observations"]
  node_meteo["Weather data<br/>[meteo.py]"]
  node_soil["Soil data<br/>[sol.py]"]
  node_chirps["CHIRPS rainfall<br/>[chirps.py]"]
  node_noaa["GPM rainfall<br/>[noaa.py]"]
  node_srtm["Elevation data<br/>[srtm.py]"]
  node_nasa["NASA satellite indices<br/>[nasa.py]"]
  node_gee["Sentinel-2 indices<br/>[gee_sentinel.py]"]
end

subgraph group_analysis["Geospatial analysis"]
  node_scoring["Suitability scoring<br/>[scoring.py]"]
  node_boundary["Benin boundaries<br/>[benin_frontiere.py]"]
  node_grid_geometry["Grid generation<br/>[quadrillage.py]"]
  node_commune_enrichment["Commune enrichment"]
end

subgraph group_storage["Persistence and history"]
  node_db_access["Database access<br/>[connexion.py]"]
  node_postgres[("PostgreSQL")]
  node_history["Daily grid history"]
end

subgraph group_presentation["Access and visualization"]
  node_api["HTTP API<br/>[app.py]"]
  node_grafana["Grafana dashboard"]
end

node_operator(("Operator"))
node_gee_service{{"Google Earth Engine"}}

node_operator -->|"runs"| node_site_pipeline
node_operator -->|"runs"| node_grid_flow
node_grid_flow -->|"runs per department"| node_commune_enrichment
node_grid_flow -->|"runs per department"| node_grid_enrichment
node_grid_flow -->|"runs per department"| node_grid_satellite
node_site_pipeline -->|"lists and saves sites"| node_db_access
node_site_pipeline -->|"collects weather"| node_meteo
node_site_pipeline -->|"collects soil"| node_soil
node_site_pipeline -->|"collects rainfall"| node_chirps
node_site_pipeline -->|"fallback rainfall"| node_noaa
node_site_pipeline -->|"collects satellite indices"| node_nasa
node_site_pipeline -->|"collects satellite indices"| node_gee
node_site_pipeline -->|"scores observations"| node_scoring
node_grid_enrichment -->|"collects weather"| node_meteo
node_grid_enrichment -->|"collects soil"| node_soil
node_grid_enrichment -->|"collects rainfall"| node_chirps
node_grid_enrichment -->|"collects elevation"| node_srtm
node_grid_enrichment -->|"scores grid data"| node_scoring
node_grid_enrichment -->|"reads and updates grid"| node_db_access
node_grid_satellite -->|"requests indices"| node_gee
node_grid_satellite -->|"optional fallback"| node_nasa
node_gee -->|"queries imagery"| node_gee_service
node_grid_satellite -->|"updates grid results"| node_db_access
node_grid_satellite -->|"records history"| node_history
node_commune_enrichment -.->|"locates communes"| node_boundary
node_grid_geometry -->|"checks grid points"| node_boundary
node_db_access -->|"reads and writes"| node_postgres
node_api -.->|"accesses data"| node_db_access
node_grafana -->|"visualizes data"| node_postgres

click node_site_pipeline "https://github.com/pharelouindou/bam/blob/main/main.py"
click node_grid_flow "https://github.com/pharelouindou/bam/blob/main/bam_pipeline.py"
click node_grid_enrichment "https://github.com/pharelouindou/bam/blob/main/process/enrichir_grille.py"
click node_grid_satellite "https://github.com/pharelouindou/bam/blob/main/process/analyser_grille.py"
click node_meteo "https://github.com/pharelouindou/bam/blob/main/collect/meteo.py"
click node_soil "https://github.com/pharelouindou/bam/blob/main/collect/sol.py"
click node_chirps "https://github.com/pharelouindou/bam/blob/main/collect/chirps.py"
click node_noaa "https://github.com/pharelouindou/bam/blob/main/collect/noaa.py"
click node_srtm "https://github.com/pharelouindou/bam/blob/main/collect/srtm.py"
click node_nasa "https://github.com/pharelouindou/bam/blob/main/collect/nasa.py"
click node_gee "https://github.com/pharelouindou/bam/blob/main/collect/gee_sentinel.py"
click node_scoring "https://github.com/pharelouindou/bam/blob/main/process/scoring.py"
click node_boundary "https://github.com/pharelouindou/bam/blob/main/process/benin_frontiere.py"
click node_grid_geometry "https://github.com/pharelouindou/bam/blob/main/process/quadrillage.py"
click node_commune_enrichment "https://github.com/pharelouindou/bam/blob/main/process/enrichir_communes_geojson.py"
click node_db_access "https://github.com/pharelouindou/bam/blob/main/db/connexion.py"
click node_history "https://github.com/pharelouindou/bam/blob/main/process/historique_grille.py"
click node_api "https://github.com/pharelouindou/bam/blob/main/api/app.py"
click node_grafana "https://github.com/pharelouindou/bam/blob/main/docker/grafana/dashboards/bam-grille-alibori.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_site_pipeline,node_grid_flow,node_grid_enrichment,node_grid_satellite toneBlue
class node_meteo,node_soil,node_chirps,node_noaa,node_srtm,node_nasa,node_gee toneAmber
class node_scoring,node_boundary,node_grid_geometry,node_commune_enrichment toneMint
class node_db_access,node_postgres,node_history toneRose
class node_api,node_grafana,node_operator,node_gee_service toneIndigo
```

## Components

### Collection workflows

- [Site pipeline](https://github.com/pharelouindou/bam/blob/main/main.py): `main.py`
- [Department flow](https://github.com/pharelouindou/bam/blob/main/bam_pipeline.py): `bam_pipeline.py`
- [Grid enrichment](https://github.com/pharelouindou/bam/blob/main/process/enrichir_grille.py): `process/enrichir_grille.py`
- [Grid satellite analysis](https://github.com/pharelouindou/bam/blob/main/process/analyser_grille.py): `process/analyser_grille.py`

### Environmental observations

- [Weather data](https://github.com/pharelouindou/bam/blob/main/collect/meteo.py): `collect/meteo.py`
- [Soil data](https://github.com/pharelouindou/bam/blob/main/collect/sol.py): `collect/sol.py`
- [CHIRPS rainfall](https://github.com/pharelouindou/bam/blob/main/collect/chirps.py): `collect/chirps.py`
- [GPM rainfall](https://github.com/pharelouindou/bam/blob/main/collect/noaa.py): `collect/noaa.py`
- [Elevation data](https://github.com/pharelouindou/bam/blob/main/collect/srtm.py): `collect/srtm.py`
- [NASA satellite indices](https://github.com/pharelouindou/bam/blob/main/collect/nasa.py): `collect/nasa.py`
- [Sentinel-2 indices](https://github.com/pharelouindou/bam/blob/main/collect/gee_sentinel.py): `collect/gee_sentinel.py`

### Geospatial analysis

- [Suitability scoring](https://github.com/pharelouindou/bam/blob/main/process/scoring.py): `process/scoring.py`
- [Benin boundaries](https://github.com/pharelouindou/bam/blob/main/process/benin_frontiere.py): `process/benin_frontiere.py`
- [Grid generation](https://github.com/pharelouindou/bam/blob/main/process/quadrillage.py): `process/quadrillage.py`
- [Commune enrichment](https://github.com/pharelouindou/bam/blob/main/process/enrichir_communes_geojson.py): `process/enrichir_communes_geojson.py`

### Persistence and history

- [Database access](https://github.com/pharelouindou/bam/blob/main/db/connexion.py): `db/connexion.py`
- **PostgreSQL**
- [Daily grid history](https://github.com/pharelouindou/bam/blob/main/process/historique_grille.py): `process/historique_grille.py`

### Access and visualization

- [HTTP API](https://github.com/pharelouindou/bam/blob/main/api/app.py): `api/app.py`
- [Grafana dashboard](https://github.com/pharelouindou/bam/blob/main/docker/grafana/dashboards/bam-grille-alibori.json): `docker/grafana/dashboards/bam-grille-alibori.json`

### Other components

- **Operator**
- **Google Earth Engine**

## Connections

- Operator → Site pipeline: runs (evidence: `README.md`)
- Operator → Department flow: runs (evidence: `bam_pipeline.py`)
- Department flow → Commune enrichment: runs per department (evidence: `bam_pipeline.py`)
- Department flow → Grid enrichment: runs per department (evidence: `bam_pipeline.py`)
- Department flow → Grid satellite analysis: runs per department (evidence: `bam_pipeline.py`)
- Site pipeline → Database access: lists and saves sites (evidence: `main.py`)
- Site pipeline → Weather data: collects weather (evidence: `main.py`)
- Site pipeline → Soil data: collects soil (evidence: `main.py`)
- Site pipeline → CHIRPS rainfall: collects rainfall (evidence: `main.py`)
- Site pipeline → GPM rainfall: fallback rainfall (evidence: `main.py`)
- Site pipeline → NASA satellite indices: collects satellite indices (evidence: `main.py`)
- Site pipeline → Sentinel-2 indices: collects satellite indices (evidence: `main.py`)
- Site pipeline → Suitability scoring: scores observations (evidence: `main.py`)
- Grid enrichment → Weather data: collects weather (evidence: `process/enrichir_grille.py`)
- Grid enrichment → Soil data: collects soil (evidence: `process/enrichir_grille.py`)
- Grid enrichment → CHIRPS rainfall: collects rainfall (evidence: `process/enrichir_grille.py`)
- Grid enrichment → Elevation data: collects elevation (evidence: `process/enrichir_grille.py`)
- Grid enrichment → Suitability scoring: scores grid data (evidence: `process/enrichir_grille.py`)
- Grid enrichment → Database access: reads and updates grid (evidence: `process/enrichir_grille.py`)
- Grid satellite analysis → Sentinel-2 indices: requests indices (evidence: `process/analyser_grille.py`)
- Grid satellite analysis → NASA satellite indices: optional fallback (evidence: `process/analyser_grille.py`)
- Sentinel-2 indices → Google Earth Engine: queries imagery (evidence: `collect/gee_sentinel.py`)
- Grid satellite analysis → Database access: updates grid results (evidence: `process/analyser_grille.py`)
- Grid satellite analysis → Daily grid history: records history (evidence: `process/analyser_grille.py`)
- Commune enrichment → Benin boundaries: locates communes
- Grid generation → Benin boundaries: checks grid points (evidence: `process/quadrillage.py`)
- Database access → PostgreSQL: reads and writes (evidence: `db/connexion.py`)
- HTTP API → Database access: accesses data
- Grafana dashboard → PostgreSQL: visualizes data (evidence: `README.md`)
