# Server Coordinator Documentation ## Overview The **Server Coordinator** orchestrates communication between the 10 autonomous engines and manages the Smart Client architecture. **Key Responsibilities:** - Engine coordination and communication routing - Smart Client request/response management - Performance monitoring and load balancing - System-wide state synchronization ## Architecture ### Smart Client Pattern From `architecture-technique.md`: - **Request/Response Only**: No streaming, stateless communication - **Engine Autonomy**: Engines operate independently between requests - **Performance Target**: 60fps with 1000+ AI companies - **FOW Granularity**: Chunk-level fog of war coordination ### Engine Coordination - **Inter-Engine Communication**: Message routing between engines - **State Synchronization**: Coordinated updates across engine boundaries - **Event Broadcasting**: Global events distributed to all engines - **Performance Monitoring**: Engine load balancing and optimization ## Core Systems ### Communication Hub ```cpp class ServerCoordinator { // Engine management void registerEngine(EngineType type, std::shared_ptr engine); void routeMessage(const Message& message); void broadcastEvent(const GlobalEvent& event); // Client management void handleClientRequest(const ClientRequest& request); ClientResponse processRequest(const ClientRequest& request); void updateClientFOW(int clientId, const FOWUpdate& update); // Performance monitoring void monitorEnginePerformance(); void balanceEngineLoads(); PerformanceMetrics getSystemMetrics() const; }; ``` ### Engine Communication Patterns #### Economy ↔ Factory - Production cost calculations - Resource availability updates - Manufacturing order processing #### War ↔ Operation - Battle result analysis - Strategic learning data - Tactical coordination #### Intelligence ↔ All Engines - Metrics collection from every system - FOW updates and coordination - Performance analytics #### Event → All Engines - Global event broadcasting - Breakthrough notifications - System-wide state changes ### Client Request Processing From `architecture-technique.md`: 1. **Request Validation**: Ensure client permissions and data integrity 2. **Engine Routing**: Direct requests to appropriate engines 3. **State Coordination**: Manage cross-engine dependencies 4. **Response Assembly**: Compile responses from multiple engines 5. **FOW Filtering**: Apply visibility restrictions per client ### Performance Requirements - **60fps Target**: Maintain real-time performance - **1000+ Companies**: Scale to massive multiplayer scenarios - **Engine Autonomy**: Minimize blocking between engines - **Memory Efficiency**: Optimize inter-engine communication ## Key Integration Points ### Fog of War Coordination - **Intelligence-Engine**: FOW state management - **Map-Engine**: Chunk visibility coordination - **Client Filtering**: Per-client visibility enforcement ### Event System Integration - **Event-Engine**: Global event generation and scheduling - **All Engines**: Event consumption and response - **Client Notification**: Event broadcasting to relevant clients ### Metrics and Analytics - **Intelligence-Engine**: System-wide metrics collection - **Performance Monitoring**: Real-time system health - **Load Balancing**: Dynamic resource allocation ## Implementation Notes - Smart Client pattern eliminates streaming complexity - Engine autonomy maximizes parallel processing - FOW at chunk granularity optimizes performance - Message routing minimizes engine coupling