# xyt-dev/kingofsnake architecture

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

- Interactive diagram: https://gitdiagram.com/xyt-dev/kingofsnake
- Repository: https://github.com/xyt-dev/kingofsnake

## Overview

##### Main Components
- Frontend Clients:
- "acapp": A Vue.js client containing typical Vue components (e.g., App.vue, HelloWorld.vue) for a mobile or dedicated application experience.
- "web": Another Vue.js based web client that includes detailed game logic scripts (e.g., Snake.js, GameMap.js, Wall.js) along with multiple views (like ranking, record, user account, and PK-related views). This suggests refined, interactive interfaces for gameplay and user interaction.

- Backend Services (found under the "backendCloud" directory):
- "backend": Built in Java (using Spring Boot and Maven) with a structured arrangement of controllers, services, mappers, and configuration classes. It handles key features such as user management (register, login, account info), game session control (PK start and control, ranklist, record management), and configurations like JWT authentication and WebSocket setups.
- "botRunningSystem": A subsystem dedicated to managing the bot running logic. It includes configuration classes, controllers, and service implementations which likely serve to operate automated bots during gameplay.
- "matchingSystem": Another subsystem aimed at pairing users (or bots) together. It handles player matching logic and related configurations.

##### Relationships & Interactions
- The Frontend (acapp and web) interacts with the Backend (the “backend” module) through API calls. These interactions include user authentication (JWT tokens, login, registration) and game actions (starting games, recording game results).
- The backend communicates with auxiliary services like the botRunningSystem and matchingSystem. These subsystems likely work through REST API calls or messaging events, handling game-specific behaviors like bot moves or player matching in real time.
- WebSocket configurations in the Java backend (e.g., WebSocketConfig) indicate real-time data flows where the server pushes game updates to connected frontend clients.

##### Architectural Patterns & Design Principles
- Modular Design: Notice how the backendCloud directory is split into multiple modules (backend, matchingSystem, botRunningSystem), each with a focused responsibility. This modularity is a key element in the architecture.
- Clear Separation of Concerns: Frontend and backend are cleanly separated. The frontend focuses on UI, game rendering, and user interactions; the backend deals with business logic, security (JWT, CORS configurations), and service organization.
- MVC Structure in the Backend: The Java code structure (controllers, services, mappers, POJOs) is indicative of the typical Model-View-Controller separation.
- Real-Time Communication: Inclusion of WebSocket configurations hints at a real-time or near real-time data flow between client and server, important for interactive gaming.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Clients"
        ACAPP["acapp (Vue.js Client)"]:::frontend
        WEB["web (Vue.js Web Client)"]:::frontend
    end

    subgraph "Backend Cloud Services"
        BACKEND["Backend Application (Spring Boot)"]:::backend
        BOT["Bot Running System"]:::backend
        MATCH["Matching System"]:::backend
    end

    ACAPP -->|"API_call"| BACKEND
    WEB -->|"API_call"| BACKEND
    BACKEND -->|"calls_bot_service"| BOT
    BACKEND -->|"calls_matching_service"| MATCH
    BACKEND -->|"WebSocket_update"| ACAPP
    BACKEND -->|"WebSocket_update"| WEB

    click ACAPP "https://github.com/xyt-dev/kingofsnake/tree/main/acapp"
    click WEB "https://github.com/xyt-dev/kingofsnake/tree/main/web"
    click BACKEND "https://github.com/xyt-dev/kingofsnake/blob/main/backendCloud/backend/src/main/java/com/kos/backend/BackendApplication.java"
    click BOT "https://github.com/xyt-dev/kingofsnake/blob/main/backendCloud/botRunningSystem/src/main/java/com/kob/botrunningsystem/BotRunningSystemApplication.java"
    click MATCH "https://github.com/xyt-dev/kingofsnake/blob/main/backendCloud/matchingSystem/src/main/java/com/kob/matchingsystem/MatchingSystemApplication.java"

    classDef frontend fill:#FFCC00,stroke:#333,stroke-width:2px
    classDef backend fill:#66CCFF,stroke:#333,stroke-width:2px
```
