# ihortarkhan/x-com architecture

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

- Interactive diagram: https://gitdiagram.com/ihortarkhan/x-com
- Repository: https://github.com/ihortarkhan/x-com

## Overview

##### Project Type and Purpose
- It’s a full-stack web application (online turn-based game).
- Frontend: React + TypeScript SPA.
- Backend: Spring Boot (Java) providing REST APIs, WebSocket endpoints, JWT-based auth, database persistence via JPA/Liquibase.

##### File Structure
a. Top-level directories:
- backend/ – Spring Boot service
- frontend/ – React application
b. Backend substructure:
- config/ – CORS, Security, Liquibase, Socket configuration
- controller/ – REST controllers for auth, units, positions, test data
- dto/ – request/response payload models
- entity/ – JPA entities (Player, Unit, Position)
- repository/ – Spring Data JPA interfaces
- service/ – business logic layer
- security/ – JWT provider, filters, user details service
- socket/ – WebSocket message controller
c. Frontend substructure:
- src/api/ – API wrappers (useGetAll, usePost, etc.)
- src/component/ – UI pieces (Battleground, Units, Positions, Auth popups)
- src/page/ – Page containers (Main, Battleground, Socket)
- src/util/ – Axios wrapper, cookie utilities
- src/dto/ – client-side models matching backend DTOs
d. Config/build files:
- backend/pom.xml – Maven dependencies
- backend/src/main/resources/application.yml – DB, server, JWT settings
- frontend/package.json, tsconfig.json – Node build

##### Extract Additional Insights from README
- Minimal text: “x-com online game”
- Implies multiplayer game, real-time updates

##### Main Components and Their Relationships
a. Client (Browser)
- React SPA served either by static host (e.g., CDN) or by Spring Boot’s resource endpoint.
- Handles UI, invokes REST APIs via Axios, maintains JWT in cookies.
- Opens WebSocket connection for real-time game updates.
b. API Gateway / Backend Server (Spring Boot)
- Exposes REST endpoints for authentication, player/unit/position CRUD.
- WebSocket endpoint for bidirectional real-time messages.
- Enforces security: JWTTokenFilter, CORS rules.
- Orchestrates business logic via Service layer.
c. Business Logic Layer
- Services (UnitService, PositionService, PlayerAuthenticationService).
- Interaction with Repositories.
d. Persistence Layer
- JPA Repositories mapping entities to a relational database (PostgreSQL/MySQL).
- Liquibase for schema migrations.
e. External Services (if any)
- None explicit, but could note future integration points here.

##### Architectural Patterns & Design Principles
- Layered Architecture: Controller → Service → Repository → Database
- DTO mapping (Mapper classes) to decouple entity from API model
- JWT-based stateless authentication
- WebSocket (SocketConfig) for real-time messaging
- Liquibase migration for versioned DB changes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        FE_APP["Frontend Application"]:::frontend
        FE_API["API Wrappers"]:::frontend
        FE_UI["UI Components"]:::frontend
        FE_PAGE["Page Containers"]:::frontend
        FE_DTO["DTO Models"]:::frontend
        FE_UTIL["Utilities (Axios, Cookies)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Spring Boot)"
        direction TB
        BE_APP["Application Entry Point"]:::backend
        BE_CONFIG["Configuration (CORS, Security, Liquibase, WebSocket)"]:::backend
        BE_CTRL["REST Controllers"]:::backend
        BE_WS["WebSocket Controller"]:::backend
        BE_SVC["Service Layer"]:::backend
        BE_REPO["Repository Interfaces"]:::backend
        BE_DTO["DTO Models"]:::backend
        BE_ENT["JPA Entities"]:::backend
        BE_SEC["Security (JWT, Filters)"]:::backend
        BE_PROP["Property Configuration"]:::backend
        BE_EXC["Exception Handling"]:::backend
        BE_MAP["Entity-DTO Mappers"]:::backend
        BE_UTIL_B["Utility Classes"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        DB["Relational Database"]:::db
        LIQUIBASE["Liquibase Changelog"]:::db
    end

    %% Communications
    FE_UI -->|"invoke REST API"| FE_API
    FE_PAGE --> FE_UI
    FE_API -->|"HTTP REST"| BE_CTRL
    FE_UI -->|"WebSocket"| BE_WS

    BE_CTRL -->|"calls"| BE_SVC
    BE_WS -- "push/pull messages" --> BE_SVC
    BE_SVC -->|"uses"| BE_REPO
    BE_REPO -->|"queries"| DB
    BE_CONFIG -- "runs migrations" --> LIQUIBASE
    LIQUIBASE --> DB
    BE_APP --> BE_CONFIG
    BE_APP --> BE_CTRL
    BE_APP --> BE_WS

    %% Click Events - Frontend
    click FE_APP "https://github.com/ihortarkhan/x-com/tree/master/frontend/src"
    click FE_API "https://github.com/ihortarkhan/x-com/tree/master/frontend/src/api"
    click FE_UI "https://github.com/ihortarkhan/x-com/tree/master/frontend/src/component"
    click FE_PAGE "https://github.com/ihortarkhan/x-com/tree/master/frontend/src/page"
    click FE_DTO "https://github.com/ihortarkhan/x-com/tree/master/frontend/src/dto"
    click FE_UTIL "https://github.com/ihortarkhan/x-com/tree/master/frontend/src/util"

    %% Click Events - Backend
    click BE_APP "https://github.com/ihortarkhan/x-com/blob/master/backend/src/main/java/net/lafox/ihor/backend/Application.java"
    click BE_CONFIG "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/config"
    click BE_CTRL "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/controller"
    click BE_WS "https://github.com/ihortarkhan/x-com/blob/master/backend/src/main/java/net/lafox/ihor/backend/socket/MessageController.java"
    click BE_DTO "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/dto"
    click BE_ENT "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/entity"
    click BE_REPO "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/repository"
    click BE_SVC "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/service"
    click BE_SEC "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/security"
    click BE_PROP "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/property"
    click BE_EXC "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/exception"
    click BE_MAP "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/mapper"
    click BE_UTIL_B "https://github.com/ihortarkhan/x-com/tree/master/backend/src/main/java/net/lafox/ihor/backend/util"
    click LIQUIBASE "https://github.com/ihortarkhan/x-com/blob/master/backend/src/main/resources/changelog.xml"

    %% Click Events - Config Files
    click BE_PROP "https://github.com/ihortarkhan/x-com/blob/master/backend/src/main/resources/application.yml"
    click DB "https://github.com/ihortarkhan/x-com/blob/master/backend/pom.xml"

    classDef frontend fill:#D0E8FF,stroke:#0366d6
    classDef backend fill:#DFFFE0,stroke:#228B22
    classDef db fill:#FFF5CC,stroke:#DAA520
```
