Back-End Logic

Runtime Environment

The backend simulation logic runs on Node.js. This allows us to share code interfaces (TypeScript types) between the frontend and the backend.

API Architecture

Communication between the client and the server (for saving games or multiplayer features) is handled via REST and WebSockets.

  • Express.js: Handles standard HTTP requests such as user authentication, loading save files, and fetching global leaderboards.

  • Socket.io (Optional): Used for real-time events if multiplayer features are enabled. It pushes simulation updates to connected clients to ensure synchronization.

Data Persistence

To save the city state, we serialize the simulation objects into JSON format.

  • Database: MongoDB (or similar NoSQL solution).

  • Schema Design: The data is stored non-relationally. A single "City" document contains nested arrays for "Buildings," "Agents," and "Roads." This structure matches the object-oriented nature of the simulation code, allowing for fast load and save operations.

Last updated