How harlanljones/urban-signal works
Purpose and Entry Points
Urban Signal is a multi-city municipal-data streaming and spatial forecasting platform. It converts permits, 311 complaints, licenses, and deeds into H3-grid features, catalyst alerts, and 6/12/18-month commercial appreciation forecasts.
Operational entry points:
• Ingestion scheduler: src/producers/scheduler.py
• Kafka workers: src/consumers/spatial_enrichment_worker.py, src/consumers/feature_aggregation_worker.py, src/consumers/postgis_worker.py
• Retraining/export: src/models/retraining_job.py
• FastAPI service: src/serving/app.py
• Cloudflare edge handler: workers/src/index.ts
Municipal Ingestion and City Boundary
Producers retrieve city-specific open-data feeds through Socrata and ArcGIS, normalize/deduplicate events, and publish typed raw events. City/feed availability is intentionally partial and centrally resolved through the city registry rather than assumed uniformly across metros.
Core paths:
• src/producers/base_producer.py
• src/producers/socrata_client.py
• src/producers/arcgis_client.py
• src/spatial/city_registry.py
• src/spatial/cities/
Avro contracts form the boundary between producers and consumers: src/schemas/avro/.
Event Streaming and Consumer Stages
Kafka is the asynchronous backbone. Raw municipal topics flow into three separable consumer responsibilities:
1. spatial normalization onto H3 resolutions 7/8/9;
2. temporal feature aggregation and catalyst-alert emission;
3. durable raw/feature synchronization to PostGIS.
Core paths:
• src/consumers/base_consumer.py
• src/consumers/spatial_enrichment_worker.py
• src/consumers/feature_aggregation_worker.py
• src/consumers/postgis_worker.py
Kafka topic and cluster infrastructure is defined in deploy/k8s/kafka/kafka-topics.yaml and deploy/k8s/kafka/strimzi-cluster.yaml; KEDA scales consumer capacity in deploy/k8s/consumers/keda-scaledobject.yaml.
Spatial and Feature Computation
Spatial processing assigns events to hierarchical H3 cells, graphs neighboring cells, and maps cells into city divisions/submarkets. Feature engineering computes time-decayed CapEx, 311 shift dynamics, and the normalized Leading Indicator Momentum Score (LIMS). LIMS threshold crossings become catalyst alerts.
Core paths:
• src/spatial/h3_indexer.py
• src/spatial/graph_builder.py
• src/spatial/submarkets.py
• src/features/pipeline.py
• src/features/lims_calculator.py
This stage is the boundary between heterogeneous municipal records and model-ready spatial-temporal feature vectors.
Storage, Training, and Model Artifacts
PostGIS is the queryable spatial system of record; feature partitions and model artifacts use MinIO/S3. Retraining applies walk-forward temporal validation with H3 spatial holdouts, trains three horizon-specific models, and exports ONNX for serving.
Core paths:
• src/storage/postgis_sync.py
• src/models/retraining_job.py
• src/models/trainer.py
• src/models/export_onnx.py
• models_storage/
Models are LightGBM quantiles (6m), spatio-temporal GNN (12m), and DCN-v2 (18m): src/models/quantile_lgbm.py, src/models/st_gnn.py, src/models/dcn_v2.py.
Real-Time API, Dashboard, and Edge Delivery
FastAPI validates requests, resolves H3/city context, runs ONNX inference, adds SHAP-style driver attribution, and exposes prediction, grid, catalog, and health endpoints. It also serves the MapLibre dashboard and dispatches webhook alerts.
Core paths:
• src/serving/app.py
• src/serving/router.py
• src/serving/engine.py
• src/serving/dashboard.py
• src/serving/dispatcher.py
src/export/snapshot_builder.py produces precomputed dashboard/API snapshots for the Cloudflare Worker, which serves edge/KV-backed responses via workers/src/index.ts.
Runtime and Deployment Topology
Primary runtime is Python 3.11/3.12 with FastAPI, Kafka clients, H3, PostGIS, DuckDB/Polars, and ONNX Runtime using CUDA when available. External services are Socrata, ArcGIS FeatureServer, Kafka/Schema Registry, PostGIS, MinIO, webhooks, and Cloudflare KV.
Local dependencies are composed in deploy/docker/docker-compose.dev.yml. Kubernetes deploys Strimzi Kafka, PostGIS storage, autoscaled consumers, and GPU inference through deploy/k8s/ and deploy/k8s/inference/inference-deployment.yaml.
Main entry points: kafka-topics.yaml Kafka topics · postgis_sync.py PostGIS · spatial_enrichment_worker.py Spatial enrichment · base_producer.py Municipal producers
Components 19
Municipal Ingestion
- City registry · Resolves supported city and feed availability.
src/spatial/city_registry.py - Socrata & ArcGIS
src/producers/socrata_client.py - Municipal producers · Normalize and deduplicate city feed events.
src/producers/base_producer.py - Avro contracts · Typed boundary between producers and consumers.
Kafka Pipeline
- Kafka topics · Raw, enriched, feature, and alert streams.
deploy/k8s/kafka/kafka-topics.yaml - Spatial enrichment · Assigns events to H3 resolutions 7, 8, and 9.
src/consumers/spatial_enrichment_worker.py - Feature aggregation · Builds temporal features and emits catalyst alerts.
src/consumers/feature_aggregation_worker.py - PostGIS sync worker · Persists raw events and features.
src/consumers/postgis_worker.py - KEDA autoscaling
deploy/k8s/consumers/keda-scaledobject.yaml
Spatial Features
- H3 & submarkets · Builds cell neighborhoods and maps cells to city divisions.
src/spatial/graph_builder.py - Feature pipeline · Computes CapEx, 311 dynamics, and LIMS vectors.
src/features/pipeline.py
Training & Storage
- PostGIS
src/storage/postgis_sync.py - MinIO/S3 artifacts · Stores feature partitions, ONNX models, and snapshots.
- Retraining job · Uses walk-forward validation and H3 spatial holdouts.
src/models/retraining_job.py - Horizon models · LightGBM 6m, GNN 12m, and DCN-v2 18m models.
src/models/trainer.py - ONNX export
src/models/export_onnx.py
Serving & Edge
- FastAPI service · Resolves city/H3 context, runs inference, dashboard, and webhooks.
src/serving/app.py - Snapshot builder · Precomputes dashboard and API responses.
src/export/snapshot_builder.py - Cloudflare Worker · Serves KV-backed snapshots at the edge.
workers/src/index.ts
Connections 25
- City registry → Municipal producers: supported feeds
- Socrata & ArcGIS → Municipal producers: city records
- Municipal producers → Avro contracts: typed events
- Avro contracts → Kafka topics: raw topics
- Kafka topics → Spatial enrichment: raw events
- Spatial enrichment → H3 & submarkets: H3 assignment
- Spatial enrichment → Kafka topics: enriched events
- Kafka topics → Feature aggregation: enriched stream
- H3 & submarkets → Feature pipeline: cell context
- Feature aggregation → Feature pipeline: event windows
- Feature pipeline → Kafka topics: features and alerts
- Kafka topics → PostGIS sync worker: raw and feature topics
- PostGIS sync worker → PostGIS: durable sync
- KEDA autoscaling → Spatial enrichment: scales
- KEDA autoscaling → Feature aggregation: scales
- PostGIS → Retraining job: historical data
- MinIO/S3 artifacts → Retraining job: feature partitions
- Retraining job → Horizon models: validated training
- Horizon models → ONNX export: trained models
- ONNX export → MinIO/S3 artifacts: ONNX artifacts
- MinIO/S3 artifacts → FastAPI service: model artifacts
- PostGIS → FastAPI service: grid and catalog queries
- PostGIS → Snapshot builder: queryable data
- Snapshot builder → MinIO/S3 artifacts: precomputed snapshots
- MinIO/S3 artifacts → Cloudflare Worker: edge snapshots