How dascr/dascr-board works
Project Type and Purpose
• This is a full-stack application designed as a darts scoreboard.
• Its core function is to manage various darts games (X01, Cricket, Elimination, Shanghai, etc.) by handling game state, player data, score tracking, and real-time updates.
• The backend is coded in Go, whereas the frontend is built using the Svelte framework.
Main Components
a. Frontend Client
• Located in the “frontend” folder, it includes Svelte pages, components (header, footer, game controllers, scoreboards, etc.), and build configuration files (vite.config.js, tailwind, etc.).
• It communicates with the backend via REST endpoints and WebSockets.
b. Backend API Server
• Main entry-point given by main.go and additional application logic is separated into packages:
• “api” folder for defining REST endpoints (for game, player, debug, etc.).
• “config” for environment and configuration handling.
• “logger” for logging and “ws” for managing websocket connections.
• The Go-based backend also orchestrates game logic present in the “game” folder and handling core operations such as scoring, next player logic, and undo actions.
c. Game Engine and Modules
• The “game” folder holds the tactical logic for different game types (ATC, Cricket, X01, etc.) and integrates with the API.
• The “player”, “podium”, “score”, “throw”, and “undo” folders demarcate distinct functionalities interrelated with game play and score management.
d. Database Layer
• Even though there isn’t an external database depicted explicitly (like SQL or NoSQL), the “database” folder provides a DB helper (database/db.go) that likely abstracts persistent storage.
e. WebSockets & Real-Time Communication
• The “ws” folder contains the client and hub code for managing WebSocket connections used for real-time updates (scoreboard changes, game state updates).
f. Deployment & Containerization
• Docker-related files (Dockerfile, .dockerignore, docker-compose*.yml, scripts) and CI/CD workflows illustrate containerization and deployment strategies.
• There are separate builds for frontend and backend via Docker, as well as instructions for running with caddy server and systemd on production.
Relationships and Interactions
• The Frontend sends HTTP requests to the Backend API (e.g., game state manipulation, player management) and also utilizes WebSocket connections for live updates.
• The Backend retrieves or updates game and player data using its internal game engine modules and, if applicable, interacts with a storage mechanism defined under “database”.
• Websocket modules (ws) manage two-way communication between the backend and connected frontend clients.
• Docker and Docker Compose encapsulate both the frontend and backend services for deployment, while caddy (as detailed in the deployment documentation) serves as a reverse proxy and static file server.
Architectural Patterns and Design Principles
• Separation of concerns: distinct directories for API routes, game logic, configurations, and UI components.
• Modular design: packages are separated by functionality (e.g., “game” for logic, “api” for endpoints, “ws” for realtime communications).
• Containerization: The Dockerfiles and docker-compose configurations enable isolated, reproducible environments.
• Real-time communication: Use of WebSocket channels is vital for live updates in the scoreboard.