FastAPI + TypeScript application with bundled frontend.
sim_francisco/
├── backend/ # Python FastAPI backend
│ ├── main.py # FastAPI application
│ ├── requirements.txt # Python dependencies
│ └── public/ # Static HTML files
│ └── index.html # Root page
├── frontend/ # TypeScript frontend
│ ├── src/
│ │ └── index.ts # TypeScript entry point
│ ├── dist/ # Build output (bundled JS)
│ ├── package.json # Node dependencies & scripts
│ └── tsconfig.json # TypeScript configuration
└── .gitignore
Backend:
cd backend
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt
cd ..Frontend:
cd frontend
npm install
cd ..Terminal 1 - Frontend watch mode:
cd frontend && npm run watchTerminal 2 - Backend server:
cd backend && uvicorn main:app --reloadVisit http://localhost:8000 and open the browser console to see "hey" logged!
Run both the backend server and frontend build watcher simultaneously:
Terminal 1 - Frontend (auto-rebuild on changes):
cd frontend
npm run watchTerminal 2 - Backend (auto-reload on changes):
cd backend
uvicorn main:app --reloadThen open your browser to: http://localhost:8000
-
Build the frontend once:
cd frontend npm run build -
Run the backend:
cd backend uvicorn main:app
GET /- Main application page (serves index.html)GET /health- Health check endpoint/dist/*- Static files (bundled JavaScript)GET /api/scenario- Get the current scenarioPOST /api/scenario- Create a new scenario (grid, buildings, shelters, agents)GET /api/riskmap- Risk grid for visualizationPOST /api/step- Compute safest paths for agents
- Frontend TypeScript source:
frontend/src/index.ts - Backend API routes:
backend/main.py - HTML template:
backend/public/index.html
The TypeScript code is bundled using esbuild and served by FastAPI as a static file.
- Leaflet: map grid cells to lat/lon and replace the canvas renderer with Leaflet layers.
- Real SF data: ingest building footprints and seismic risk zones, then swap the random scenario generator in
backend/sim/state.py. - Nemotron + Prime Intelligence: replace
SimulationState.step()with policy calls and verifier hooks.