GridTwin : Self-hosted · Energy

GridTwin — a digital twin of a national grid

A live, web-based model of a national transmission and distribution grid, built on Kenya's 400/220/132 kV network: from the ±500 kV Ethiopia–Kenya HVDC link and the Uganda and Tanzania interconnectors down to substation bays, breakers, relays, feeders and individual towers.

It combines my electrical engineering background (power systems, SCADA, protection) with the software and infrastructure work I do now. It runs on the production host of my homelab and is deployed by the same Gitea Actions pattern as everything else there.

Template data: station locations, routes, ratings, staff and customers are approximate or fictional and exist to demonstrate the platform.

What it does

One live grid, every second

  • Merit-order dispatch: geothermal, hydro, wind, solar, thermal and cross-border imports
  • DC load flow per electrical island, I²R losses, frequency and reserve margin
  • IEC 60076-7 thermal models for 158 power transformers
  • Feeder faults with recloser sequences; line faults with distance-to-fault and nearest tower
  • Energy balance per feeder: technical and non-technical losses
  • Slow degradation: SF6 leaks, transformer DGA and surge-arrester leakage

Predictions, every ~45 seconds

  • N-1 screening of every contingency, double-circuit lines modelled correctly
  • 24 h demand vs available capacity at the evening peak
  • Line loadings 12 h ahead and transformer hot-spots 24 h ahead
  • AC load flow (pandapower, Newton-Raphson) with tap changers and reactive limits
  • SF6 and DGA trends projected to days-to-alarm
  • Predicted problems raise alerts before they happen

Built for operations teams

Drill-down from country to breaker

National → region → substation (live single-line diagram, bays, transformers, feeders, alerts) → bay → equipment, with telemetry, nameplate, protection settings and 48 h history against alarm limits.

Alerts routed to the right team

Each alert is routed by region and specialty (lines, substation, protection, distribution, revenue protection) to a team lead, then acknowledged, assigned, worked and resolved on a timeline.

Field data you can trust

A mobile field app only accepts readings inside the asset's geofence (60 m for towers). The server re-checks every submission and flags poor GPS accuracy, impossible travel, clock skew and duplicate readings. A reading entered from home shows on the audit map as a red line kilometres long.

Design tools

A network designer for substations and lines (bays, towers and diagrams generated automatically), an IEC 60617-style single-line diagram editor, CIM/CGMES model import, and breaker switching with interlocking.

Architecture & deployment

The simulation runs in its own twin service, one process that owns the engine and the studies. The public FastAPI app is stateless and runs several workers that ask the twin for live state, so the web tier scales without duplicating the simulation. Nginx serves the Angular SPA and proxies the API and the WebSocket live feed.

ContainerRoleExposed
twinEngine, studies, Alembic migrations, seedingInternal only, service key
apiFastAPI, JWT auth, login lockout, 4 workersInternal only
webNginx + Angular 21 SPA, /api and /ws proxyCloudflare Tunnel
postgresShared PostgreSQL stack on the same VMInternal network

Gitea Actions tests the API (pytest, mypy) and builds the SPA on the Docker runner, and SonarQube scans the code. A push to main then has the host-mode runner on the Debian VM rebuild the stack with Docker Compose, wait until the twin reports ready through Nginx, and prune old images and build cache so the disk stays free.

Python 3.11FastAPINumPySciPypandapowerPostgreSQLAlembicAngular 21LeafletEChartsWebSocketDocker ComposeGitea Actions