# dascr/dascr-board architecture

> Architecture diagram of the GitHub repository dascr/dascr-board, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dascr/dascr-board
- Repository: https://github.com/dascr/dascr-board

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    F["Frontend Client"]:::frontend
    WS["WebSocket Server"]:::ws
    
    subgraph "Backend API Server"
        AR["API Routes (REST Endpoints)"]:::backend
        GE["Game Engine Modules"]:::module
        AR -->|"calls"| GE
    end
    
    DB["Database Layer"]:::db
    DEP["Deployment & Containerization"]:::deployment

    F -->|"REST_Calls"| AR
    F -->|"WebSocket"| WS
    WS -->|"RealTime_Updates"| GE
    AR -->|"Persistent_Data"| DB
    DEP -->|"Deploys_to"| F
    DEP -->|"Deploys_to"| AR
    DEP -->|"Deploys_to"| WS

    click F "https://github.com/dascr/dascr-board/tree/main/frontend/"
    click AR "https://github.com/dascr/dascr-board/blob/main/main.go"
    click GE "https://github.com/dascr/dascr-board/tree/main/game/"
    click DB "https://github.com/dascr/dascr-board/blob/main/database/db.go"
    click WS "https://github.com/dascr/dascr-board/tree/main/ws/"
    click DEP "https://github.com/dascr/dascr-board/tree/main/Dockerfile"

    classDef frontend fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef backend fill:#CCEEFF,stroke:#333,stroke-width:2px;
    classDef module fill:#EEFFCC,stroke:#333,stroke-width:2px;
    classDef db fill:#FFDDEE,stroke:#333,stroke-width:2px,stroke-dasharray: 5,5;
    classDef ws fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef deployment fill:#CCCCFF,stroke:#333,stroke-width:2px;
```
