How ihortarkhan/x-com works
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