Physics Sandbox — Aspire Microservices Demo
Architecture
Five services, all communication routed through the Server.
|
Services
Service |
Role |
Tech |
|---|---|---|
Server |
Central hub. Routes all messages between services. |
ASP.NET gRPC server |
Simulation |
Runs physics simulation. Receives commands, emits state. |
F# + BepuPhysics2, gRPC bidirectional stream |
Client |
REPL for user input. Sends commands and camera/UI settings. |
F# + Spectre.Console, gRPC client |
Viewer |
3D rendering of simulation state. Receives state + camera. |
F# + Stride3D, gRPC client |
MCP |
AI assistant integration. 38 tools for simulation control. |
F# + ModelContextProtocol, gRPC client |
Communication Flows
1. Commands: Client → Server → Simulation
|
User types commands in the REPL (add body, apply force, set gravity, step,
play, pause). Client sends them to Server via SendCommand / SendBatchCommand.
Server forwards to Simulation via the ConnectSimulation bidirectional stream.
2. Simulation Data: Simulation → Server → Client + Viewer
|
Simulation streams world state (body positions, velocities, timing) to
Server via the ConnectSimulation upstream. Server caches the latest state
(for late joiners) and fans out to all StreamState subscribers.
3. View Commands: Client → Server → Viewer
|
User sets camera position, zoom, toggle wireframe. Client sends to
Server via SendViewCommand, Server forwards to Viewer via StreamViewCommands.
Contracts (Platform.Shared.Contracts)
|
Aspire AppHost
|
Server starts first. Simulation, Viewer, and Client wait for Server to be
healthy, then connect via service discovery (https+http://server).
Spec-Kit Workflow
Each service is a feature spec, built one at a time:
- Spec 001: Contracts + Server (the hub must exist first)
- Spec 002: Simulation (physics engine + gRPC integration)
- Spec 003: Client (REPL + command sending + state display)
- Spec 004: Viewer (3D rendering + state/camera streaming)
Each spec starts a fresh branch, fresh context. The constitution
(fsMicroservices) governs all four.
PhysicsSandbox