How lod-io/centaur works
Project Type & Purpose
• Type: Full-stack interactive web application.
• Purpose: To simulate horse races where each horse’s progress is determined by the performance (speed and correctness) of AI models answering questions.
• Key Feature: Real-time updates via WebSockets allow users to see AI model performance in a visually engaging way.
Components from the File Structure
• Frontend (Client):
• The main code is located in the “client” directory.
• Standard React project structure with directories like public, src, and components that include UI pieces such as HeaderButtons, RaceTrack, HorseSelector, etc.
• Utility folders like hooks (e.g., usePopovers) and data files (questionBank) support dynamic interactions.
• The client handles user interactions, rendering the race, and calls to the backend.
• Backend (Server):
• The “server” directory uses Go, with subdirectories for constants, handlers, models, and services.
• Handlers (e.g., answer.go, websocket.go) define endpoints and WebSocket connections, managing incoming requests.
• Models and services encapsulate business logic and data structures.
• Configuration and dependency management via go.mod and go.sum are also present.
a. Main Components:
• Client (React application): Represents the user interface, interactive elements, and hooks/components like RaceTrack, HorseSelector, etc.
• Server (Go backend): Hosts API endpoints, WebSocket server, and internal processing logic including models, services, and constants.
• External Services: Highlight the use of the CLōD API (set via .env) for additional data or processing if necessary.
b. Relationships & Data Flow:
• The client sends requests (via REST and/or WebSockets) to the server.
• The server processes these requests (e.g., checking answers or updating race states) and pushes real-time updates back to the client.
• Data flow: User actions in the UI trigger API calls → Server validates/processes → Real-time updates pushed via WebSockets → UI updates to reflect current race progress.
c. Architectural Patterns & Principles:
• Clear separation of concerns between frontend and backend.
• MVC-like structure on the server (handlers for routing, models for data structure, services for business logic).
• Real-time communication handled with WebSockets.
• Use of client-side state management to drive dynamic UI updates.
d. Relevant Technologies:
• Frontend: React, TypeScript, Node.js (npm) for dependency management.
• Backend: Go programming language, using standard modules and WebSocket handling.
• API Key management with environment variables (.env) for CLōD API.