A production-style geospatial analytics experience that visualizes air-quality observations in real time. The dashboard combines a Vite + React client, a FastAPI analytics service, and a TimescaleDB warehouse preloaded with demo datasets. The stack demonstrates how to ingest, aggregate, and present OpenAQ data through a cohesive developer workflow.
- Why this project matters
- Feature tour
- Implementation blueprint
- System architecture
- Getting started
- Running services without Docker
- Data and API reference
- Roadmap and future upgrades
- Troubleshooting
Cities need rapid feedback about particulate concentrations and other pollutants to guide policy. Emissions Dashboard demonstrates how to ingest hourly sensor readings, aggregate them into KPIs, and share the insight through an interactive interface. The repository doubles as a template for full-stack data apps: reproducible infrastructure, modern frontend tooling, and a typed Python backend built for time-series workloads.
- Interactive geospatial dashboard – React, Leaflet, and Recharts combine to render station markers, KPI tiles, and time-series charts with smooth hover states.
- Analytics-grade backend – FastAPI exposes parameterized endpoints for stations, raw observations, and hourly aggregates, using SQLAlchemy models and Pydantic schemas for safety.
- Time-series warehouse – TimescaleDB hypertables, continuous aggregates, and seed SQL scripts accelerate analytical queries even with large observation volumes.
- Automated ingestion utilities – Scripts in
backend/app/ingestionhydrate the warehouse from OpenAQ, controlled via environment variables such asINGEST_SINCE. - Docker-first workflow –
make upbuilds the entire stack, attaches logs, and guarantees matching dependencies across machines. - Developer ergonomics – Clear Make targets,
.envtemplates, and typed code enable quick onboarding.
- Frontend – Vite bootstraps a React SPA. Components under
frontend/src/componentsrender maps, KPI cards, and charts. The API client infrontend/src/apiwraps Axios and honors theVITE_API_URLvariable. - Backend –
backend/app/main.pyassembles routers fromapp/routers. Each router speaks to TimescaleDB through a SQLAlchemy session created inapp/db.py. Response models inapp/schemas.pykeep the API contract explicit. - Database – Postgres 15 with TimescaleDB extensions initializes via
db/init/*.sql. Optional demo data resides indb/seeds/seed_demo.sqland loads throughmake seed. - Infrastructure –
docker-compose.ymldefinesfrontend,backend, anddbservices. Environment variables are sourced from.env, andMakefileconvenience targets orchestrate the lifecycle.
frontend/ (Vite + React)
├─ src/components → Map, charts, KPI cards
├─ src/api → Axios client for FastAPI (default http://localhost:8000)
└─ src/pages → Dashboard layout
backend/ (FastAPI)
├─ app/main.py → App factory + router registration
├─ app/routers → Stations, observations, analytics, health
├─ app/ingestion → OpenAQ ingestion utilities
├─ app/db.py → SQLAlchemy session + Timescale connection
└─ app/schemas.py → Pydantic models
db/
├─ init/ → Timescale/Schema bootstrap scripts
└─ seeds/ → Optional demo data
Services communicate over an internal Docker network: the frontend calls the API via VITE_API_URL, the backend connects to Postgres via DATABASE_URL, and the database exposes TimescaleDB hypertables for analytical queries.
- Docker and Docker Compose
- GNU Make
- Node.js 18+ and Python 3.11+ (only for running services outside Docker)
cp .env.example .env # configure credentials + service URLs
make up # build + start db, backend, frontend
# API docs → http://localhost:8000/docs
# Web UI → http://localhost:5173make up streams container logs. Press Ctrl+C to stop tailing without shutting down the stack. Run make down to stop services and clean volumes.
make seed # loads db/seeds/seed_demo.sql into the running Postgres container| Command | Description |
|---|---|
make logs |
Tail all service logs |
make api |
Print the FastAPI docs URL |
make web |
Print the frontend URL |
make psql |
Launch a psql shell inside the TimescaleDB container |
cd backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
export DATABASE_URL="postgresql+psycopg://postgres:postgres@localhost:5432/emissions"
export API_CORS_ORIGINS='["http://localhost:5173"]'
uvicorn app.main:app --reload --port 8000cd frontend
npm install
npm run dev # serves at http://localhost:5173Configure VITE_API_URL in .env or .env.local if the API runs on a different host/port.
| Variable | Description |
|---|---|
POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB |
Timescale/Postgres credentials |
DATABASE_URL |
SQLAlchemy connection string used by the API |
API_CORS_ORIGINS |
JSON list of allowed origins |
VITE_API_URL |
Base URL for the frontend Axios client |
INGEST_SINCE |
Optional ISO date for OpenAQ ingestion start |
OPENAQ_BASE_URL |
Optional override for the OpenAQ API base URL |
| Endpoint | Description |
|---|---|
GET / |
Service metadata |
GET /health |
Health probe for Compose |
GET /stations |
List up to 1000 stations with metadata |
GET /observations |
Raw observations filtered by station_id, parameter, start, end, limit |
GET /analytics/hourly |
Hourly aggregates for a station and pollutant |
Example request:
curl "http://localhost:8000/analytics/hourly?station_id=DEMO_1¶meter=pm25"Response snippet:
[
{
"time": "2024-05-01T10:00:00+00:00",
"station_id": "DEMO_1",
"parameter": "pm25",
"unit": "µg/m3",
"avg_value": 8.14,
"min_value": 4.08,
"max_value": 14.22,
"n": 12
}
]- Live streaming ingestion – Replace batch imports with Debezium or Kafka Connect to capture measurements continuously.
- Alerting and notifications – Trigger alerts when rolling averages breach thresholds, with integrations for email or webhooks.
- User personalization – Persist favorite stations, saved filters, and per-user KPI layouts via a lightweight auth service.
- Offline-first mobile view – Ship a PWA profile optimized for phones and add caching for recent readings.
- Automated testing pipeline – Add CI workflows that lint the frontend, run backend tests, and validate SQL migrations.
- Import errors – Activate the virtual environment before installing backend dependencies.
- CORS or URL mismatches – Ensure
VITE_API_URLmatches the FastAPI host, especially when using tunnels or custom domains. - Database connectivity – Confirm
DATABASE_URLpoints to the running TimescaleDB container; inspectmake logsfor failures. - Seed failures – The seed script assumes TimescaleDB extensions are loaded; rerun
make upif initialization did not complete.
Enjoy exploring the emissions data platform.