LemonDrop847/forestguard

Satellite-Powered Environmental Change Detection Platform

โ˜… 1Forks 0TypeScriptGitHub โ†—Compare

Project website โ†—

README

ForestGuard ๐Ÿ›ฐ๏ธ๐ŸŒฒ

ForestGuard is an open-source, full-stack satellite monitoring and environmental change detection platform. It couples high-resolution optical imagery (Sentinel-2) and spectral index analysis with an interactive geospatial dashboard, change vectorization, automated timeline tracking, and AI-assisted environmental impact reporting.


๐ŸŒŸ Features

  • Interactive Geospatial AOI Selection: Draw arbitrary polygon boundaries directly on an interactive MapLibre GL map or load pre-configured benchmark sites (Amazon Rainforest, Elephant Butte Reservoir, Austin Urban Growth).
  • Multi-Temporal Spectral Analysis: Computes pixel-level difference masks across core spectral indices:
    • NDVI (Normalized Difference Vegetation Index) for canopy disturbance and deforestation.
    • MNDWI / NDWI (Normalized Difference Water Index) for drought, reservoir shrinkage, and flood recession.
    • NDBI (Normalized Difference Built-up Index) for urbanization and bare-ground expansion.
  • Vectorized Hotspots & GeoJSON Overlay: Converts pixel change masks into GeoJSON polygons with computed geographic coordinates, centroid locations, and hectare-scale area measurements.
  • Interactive Split Slider: Real-time before/after satellite composite inspection with interactive wipe-slider comparisons.
  • Chronological Change Timeline: Visualizes historical NDVI progression, event severity, and state transitions over the selected observation window.
  • Grounded AI Synthesis: Generates structured executive summaries detailing key findings, critical zones, environmental impact, and verification steps based strictly on calculated metrics.
  • Executive Report Generation: Exports standalone, publication-ready HTML environmental audit reports containing executive summaries, KPI breakdown tables, change catalogs, and verification recommendations.
  • Resilient Fallback Mode: Gracefully transitions to offline benchmark datasets when backend services or satellite APIs are unreachable.

๐Ÿ—๏ธ Architecture & Tech Stack

forestguard/
โ”œโ”€โ”€ src/                     # Frontend (Next.js 16 + React 19 + MapLibre GL)
โ”‚   โ”œโ”€โ”€ app/                 # App Router (Landing, /monitor, /cases)
โ”‚   โ”œโ”€โ”€ components/          # Analysis controls, map viewers, split-screens, reports
โ”‚   โ””โ”€โ”€ lib/                 # API client, domain adapters, context, mocks
โ””โ”€โ”€ backend/                 # Backend (FastAPI + Pydantic v2 + Geospatial Pipeline)
    โ”œโ”€โ”€ app/
    โ”‚   โ”œโ”€โ”€ api/             # REST endpoints (health, analyses, reports)
    โ”‚   โ”œโ”€โ”€ services/        # Spectral indices, change detection, vectorization, AI
    โ”‚   โ””โ”€โ”€ schemas/         # Pydantic DTO models
    โ””โ”€โ”€ tests/               # Pytest suite for API & change detection algorithms

Frontend

  • Framework: Next.js (App Router, Turbopack)
  • Styling: Tailwind CSS
  • Maps: MapLibre GL
  • Icons: Lucide React

Backend

  • Framework: FastAPI (Python 3.10+)
  • Validation: Pydantic v2
  • Geospatial Processing: NumPy, SciPy (ndimage.label), Shapely
  • Satellite Provider: Google Earth Engine (Sentinel-2 SR Harmonized) with built-in offline synthetic provider (MockSatelliteProvider)

๐Ÿš€ Quickstart Guide

Prerequisites

  • Node.js: v18.17+ or v20+
  • Python: v3.10+
  • npm or pnpm / yarn

Step 1: Start the Backend (FastAPI)

  1. Navigate to the backend directory:

    cd backend
  2. Create and activate a Python virtual environment:

    # Linux / macOS
    python -m venv .venv
    source .venv/bin/activate
    
    # Windows (PowerShell)
    python -m venv .venv
    .venv\Scripts\Activate.ps1
  3. Install backend dependencies:

    pip install -e .
  4. Configure environment variables (optional for local testing; defaults to mock provider):

    # Windows PowerShell:
    Copy-Item .env.example .env
    # Linux / macOS:
    cp .env.example .env
  5. Start the FastAPI development server:

    uvicorn app.main:app --reload --port 8000

    Backend is available at http://localhost:8000 (Interactive Swagger docs: http://localhost:8000/docs)


Step 2: Start the Frontend (Next.js)

  1. Open a new terminal in the repository root:

    # Install dependencies
    npm install
  2. (Optional) Verify frontend environment variable in .env.local:

    NEXT_PUBLIC_API_URL=http://localhost:8000
  3. Start the Next.js development server:

    npm run dev

    Frontend is available at http://localhost:3000


๐Ÿ“– How to Use ForestGuard

1. Launch the Environmental Monitor

  • Open http://localhost:3000 and click "Launch Monitor" or navigate directly to /monitor.

2. Define Area of Interest (AOI)

  • Quick Benchmark: Click one of the benchmark site buttons:
    • ๐ŸŒฒ Amazon (Deforestation in Para, Brazil)
    • ๐Ÿ’ง Reservoir (Elephant Butte water loss, NM)
    • ๐Ÿ—๏ธ Urban (Suburban expansion in Austin, TX)
  • Custom Area: Click "Draw Polygon on Map" and click on the map canvas to construct a custom boundary. Double-click or click the first point to close the polygon.

3. Configure Temporal Comparison Windows

  • Select the Baseline (Before) observation date window (e.g. 2025-03-01 to 2025-03-31).
  • Select the Target Observation (After) date window (e.g. 2026-08-01 to 2026-08-31).

4. Select Detection Classifiers

  • Toggle desired environmental change layers:
    • ๐ŸŒฒ Forest Loss (NDVI anomaly)
    • ๐Ÿ’ง Water Loss (MNDWI reduction)
    • ๐Ÿ—๏ธ Built / Bare (NDBI expansion)
    • ๐Ÿ›ฃ๏ธ Road / Mining (SWIR linear features)

5. Run Analysis

  • Click "Run Environmental Analysis".
  • Watch the live step-by-step pipeline progress:
    1. Acquiring satellite imagery
    2. Removing cloud contamination
    3. Generating spectral indices
    4. Comparing temporal imagery
    5. Classifying environmental changes
    6. Mapping change regions

6. Explore Results

  • Change Hotspots: Click individual polygons on the map or in the change catalog to zoom to the hotspot, inspect change magnitude, and view spectral delta scores.
  • Before / After Slider: Toggle the Split-Screen Comparison tab to drag the interactive wipe-slider over satellite composites.
  • Observation Timeline: Inspect temporal NDVI trajectories and status milestones.
  • AI Summary: Review auto-generated impact assessments, critical vulnerability zones, and validation notes.
  • Export Audit Report: Click "Generate Report" to produce an executive HTML report with summary stats and change tables.

๐Ÿงช Testing & Validation

Run Backend Unit & Integration Tests

cd backend
python -m pytest tests/ -v

Validate Frontend TypeScript & Build

npm run build

โš™๏ธ Environment Variables Reference

Backend (backend/.env)

Variable Default Description
DATABASE_URL postgresql://... Database connection string
SATELLITE_PROVIDER mock mock for local synthetic data, or earthengine
EARTHENGINE_PROJECT "" Google Earth Engine project ID
EARTHENGINE_SERVICE_ACCOUNT "" Service account email for GEE
EARTHENGINE_PRIVATE_KEY "" Service account private key
LLM_API_KEY "" OpenAI / LLM API key for summaries
LLM_BASE_URL https://api.openai.com/v1 LLM endpoint URL
LLM_MODEL gpt-4-turbo LLM model identifier

Frontend (.env.local)

Variable Default Description
NEXT_PUBLIC_API_URL http://localhost:8000 Backend API base URL

๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for details.

Contributors

LemonDrop847

Issues