Starter scaffold for TerraPulse: Flask backend + React frontend, Postgres, Redis, Docker Compose.
Quick start (requires Docker):
- Copy
.env.exampleto.envand set values. - From project root run:
# TerraPulse — Climate Intelligence Dashboard
Flask backend · React frontend · PostGIS · Redis · OpenAI (optional)
License: MIT
Overview
--------
TerraPulse is a starter climate intelligence dashboard that ingests sensor and satellite observations, stores region geometries in PostGIS, simulates policy impacts using OpenAI (optional), and provides a real-time alerts stream via Server-Sent Events (SSE). It ships as a containerized full-stack app (Docker Compose) and includes a lightweight React + Leaflet frontend.
Demo
----
A small static demo map is included in `frontend/public/demo-map.svg` to illustrate the UI. For a live demo, run the stack locally and open the frontend at http://localhost:3000.
Quick start (Docker)
--------------------
1. Copy `.env.example` to `.env` and set values (use `OPENAI_MOCK=1` for local dev).
2. From project root:
```powershell
copy .env.example .env
docker-compose up --build -d- Run migrations and seed a sample region (inside backend container):
docker-compose run --rm backend alembic upgrade head
docker-compose run --rm backend python manage.py seed_region- Visit the frontend: http://localhost:3000 and the API at http://localhost:5000
- Ingest API:
POST /ingeststores sensor payloads per-region (DB-backed or Redis list fallback). - Regions API:
GET /regions/<region>returns recent ingest items;GET /regions/<region>/geojsonreturns region geometry as GeoJSON. - Policy simulator:
POST /simulate-policy— optional OpenAI integration with robust fallback and mock mode. - Alerts:
POST /alerts,GET /alerts, andGET /stream/alerts(SSE realtime alerts). - PostGIS migrations and seeded sample region for polygon rendering.
- Ingest
- Clients POST region data to
/ingest. When a database is configured, data is persisted toregions_ingest. Otherwise it is stored in a Redis/in-memory list.
- Clients POST region data to
- Regions & GeoJSON
- Region geometries live in the
regionsPostGIS table. The backend exposes GeoJSON viaST_AsGeoJSONor a demo polygon fallback.
- Region geometries live in the
- Simulator
- The simulator calls OpenAI when
OPENAI_API_KEYis present, with retries/timeouts and a mock mode (OPENAI_MOCK=1) for offline use.
- The simulator calls OpenAI when
- Alerts & Streaming
- Alerts are pushed to a Redis list and optionally published to a channel. Clients can subscribe to
/stream/alertsto receive SSE events (backlog is sent on connect).
- Alerts are pushed to a Redis list and optionally published to a channel. Clients can subscribe to
docker-compose.yml # compose services: backend, frontend, db (PostGIS), redis
init_db.sql # optional DB init SQL
README.md # project README (this file)
backend/ # Flask backend
Dockerfile # backend image build
requirements.txt # Python dependencies
manage.py # small CLI for migrations/seeding
alembic/ # alembic migrations and config
backend/ # backend app package
app.py # main Flask app and routes
db.py # SQLAlchemy models and DB helpers
tests/ # pytest unit tests for backend
frontend/ # React + Vite frontend
Dockerfile # frontend image build
package.json # npm scripts and dependencies
public/ # static public assets
demo-map.svg # demo map example
src/ # React source
App.jsx # main app shell (simulator + map)
MapView.jsx # Leaflet map view and GeoJSON rendering
__tests__/ # frontend unit tests (Jest)
scripts/ # helper scripts
verify_end_to_end.py # small verifier that exercises API + SSE
.github/ # CI workflows
workflows/
ci.yml # GitHub Actions: tests, build, e2e, publish
- Backend unit tests: run in
backend/with pytest. - Frontend tests: run in
frontend/withnpm test(Jest) — a simple MapView test is included.
A GitHub Actions workflow runs backend tests, builds the frontend, runs an end-to-end verifier that uses docker-compose, and (optionally) builds and publishes Docker images when registry secrets are configured.
To enable CI to publish Docker images, set these repository secrets in GitHub:
REGISTRY_URL,REGISTRY_USERNAME,REGISTRY_PASSWORD,BACKEND_IMAGE,FRONTEND_IMAGE
- If frontend builds fail due to native node_modules, ensure host
node_modulesis not mounted; the frontend Dockerfile runsnpm ciin-image and the repo includes.dockerignore. - If Alembic migrations fail in CI, check the Postgres health logs and increase wait times.
Open a PR with changes against main. Follow the code style and add tests where appropriate.
MIT
Want me to also:
- Create a
LICENSEfile with MIT text and commit it - Create a feature branch and prepare a PR for these README changes
- Replace the demo SVG with a screenshot you provide (or give commands to capture one)
Which of those should I do next?
# terrapulse