# hoanghai0810/football-online architecture

> Architecture diagram of the GitHub repository hoanghai0810/football-online, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hoanghai0810/football-online
- Repository: https://github.com/hoanghai0810/football-online

## Overview

1. **Repository shape**
   - This is a monorepo with three deployable parts: a **React frontend** in `frontend`, a **Spring Boot backend** in `backend`, and a **Python AI chatbot service** in `chatbot`.
   - The overall system is a game platform: UI → game API/backend → SQL persistence, with a separate AI assistant service for coaching/advice.

2. **Frontend boundary**
   - `frontend/src` is a Vite-based React app that owns presentation, routing, and client-side state.
   - Pages like `Dashboard`, `Market`, `Packs`, `Squad`, `Tournaments`, `SoloMatch`, and `Trophies` map to the major game modes.
   - Shared UI is split into reusable components such as `AiAssistant`, `InteractiveMatch`, `MatchSimulationModal`, `StandingsTable`, and `TournamentLeaders`.

3. **Frontend data flow**
   - The frontend talks to the backend through `frontend/src/services/api.js`.
   - `AuthContext` and `PrivateRoute` indicate that authentication state is held client-side and used to guard protected game pages.
   - The AI assistant component is a separate UI entry point that likely calls the chatbot service rather than the core game backend directly.

4. **Backend application core**
   - The backend is a Spring Boot 3 application centered at `FootballApplication.java`.
   - It contains the main game domain: squad management, player cards, inventory packs, missions/quests, career progression, tournaments, match simulation, and user stats.
   - Controllers are grouped by feature area: `Auth`, `User`, `Player`, `PlayerCard`, `Squad`, `Inventory`, `Mission`, `Career`, `Gameplay`, and `Ai`.

5. **Backend service and domain boundaries**
   - Business logic is pushed into services such as `MatchService`, `MatchSimulationEngine`, `SquadService`, `CareerService`, `InventoryService`, `MissionService`, `PlayerCardService`, and `SeasonGeneratorService`.
   - This separation suggests a clean flow of: controller request → service logic → repository persistence → DTO response.
   - `MatchSimulationEngine` is the core simulation boundary for gameplay results, while `SeasonGeneratorService` drives league/career content.

6. **Persistence model**
   - The backend uses Spring Data JPA repositories over a relational database.
   - Main entities include users, careers, player templates/cards, squads, missions, packs, seasons, tournaments, standings, trophies, fixtures, and system settings.
   - The readme says H2 is used locally and a managed SQL database is used in production on Render.

7. **Security and identity**
   - Authentication is handled by Spring Security with both **JWT** and **Google OAuth2**.
   - `JwtAuthenticationFilter`, `JwtUtils`, `UserDetailsServiceImpl`, and `OAuth2LoginSuccessHandler` define the auth boundary.
   - `AuthController` and `SecurityConfig` are the main entry points for login/session establishment and protected API access.

8. **Startup, seeding, and migrations**
   - `DataInitializer`, `StartupService`, `PlayerSeeder`, and `DatabaseSchemaFixer` suggest the backend bootstraps both schema compatibility and initial game data.
   - There is also a migration framework under `service/migration`, including versioned migrations for league/player updates and balance changes.
   - This means some gameplay content is generated or corrected at startup, not only stored statically.

9. **AI assistant service**
   - The `chatbot` service is a separate Python application using LangGraph/LangChain-style agent orchestration and Google Gemini.
   - It exposes an AI manager assistant with tool-style access to game context, squad optimization, and tactical advice.
   - The repo description says it uses in-memory rate limiting, which matters architecturally because it keeps AI requests isolated and cost-controlled without depending on the main game database for throttling.

10. **Interaction between backend and chatbot**
   - The AI service is not just a generic chatbot; it is meant to consume live game state such as coin balance, squad layout, and available cards.
   - That implies a cross-service flow where the frontend or backend supplies context to the chatbot, and the chatbot returns advisory output to the UI.
   - This is an important boundary for diagrams: the AI service is adjunct to the game backend, not part of the core persistence or simulation path.

11. **Deployment and packaging**
   - Each major part has its own containerization/deployment setup: `backend/Dockerfile`, `chatbot/Dockerfile`, and a static frontend build.
   - `render.yaml` ties the system to Render, with separate services for backend, chatbot, and frontend.
   - GitHub Actions workflows exist for backend and frontend CI, so build/test pipelines are split along the same service boundaries.

12. **What to emphasize in an architecture diagram**
   - Show three top-level services: browser frontend, Java game API, and Python AI service.
   - Inside the backend, distinguish auth/security, gameplay/match simulation, squad/inventory/career/tournament domains, and JPA repositories.
   - Show the database as the backend’s system of record, with startup seeding/migrations feeding it.
   - Show the chatbot as a separate consumer of game context, with responses flowing back to the frontend AI assistant UI.

Main entry points: [`frontend/src/services/api.js`](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/services/api.js) (API Client), [`chatbot/src/server.py`](https://github.com/hoanghai0810/football-online/blob/master/chatbot/src/server.py) (Chat Agent), [`frontend/src/App.jsx`](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/App.jsx) (Pages), [`frontend/src/components/AiAssistant.jsx`](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/components/AiAssistant.jsx) (Shared UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_webapp["Browser UI<br/>react app<br/>[main.jsx]"]
  node_routing["Pages<br/>routing/state<br/>[App.jsx]"]
  node_gamepages["Game Modes<br/>views<br/>[Dashboard.jsx]"]
  node_uikit["Shared UI<br/>components<br/>[AiAssistant.jsx]"]
  node_api["API Client<br/>http client<br/>[api.js]"]
end

subgraph group_backend["Backend"]
  node_boot["FootballApp<br/>spring boot"]
  node_security["Security<br/>auth"]
  node_authctl["Auth API<br/>controller"]
  node_gameapi["Game APIs<br/>controllers"]
  node_matchsvc["Match Engine<br/>simulation service"]
  node_domainsvc["Game Services<br/>domain services<br/>[SquadService.java]"]
  node_bootstrap["Bootstrap<br/>startup/migration"]
end

subgraph group_chatbot["AI Service"]
  node_agent["Chat Agent<br/>python service<br/>[server.py]"]
  node_tools["Agent Tools<br/>tooling<br/>[tools.py]"]
end

subgraph group_data["Data"]
  node_repo[("Repositories<br/>persistence")]
  node_entities["Domain Model<br/>jpa entities<br/>[Users.java]"]
  node_db[("SQL DB<br/>database")]
end

subgraph group_delivery["Delivery"]
  node_deploy["Deploy<br/>docker/render<br/>[render.yaml]"]
end

node_webapp -->|"renders"| node_routing
node_routing -->|"navigates"| node_gamepages
node_routing -->|"uses"| node_uikit
node_uikit -->|"fetches"| node_api
node_gamepages -->|"calls"| node_api
node_api -->|"auth"| node_authctl
node_api -->|"game data"| node_gameapi
node_boot -->|"configures"| node_security
node_authctl -->|"uses"| node_security
node_gameapi -->|"delegates"| node_domainsvc
node_domainsvc -->|"simulates"| node_matchsvc
node_domainsvc -->|"persists"| node_repo
node_repo -->|"maps"| node_entities
node_entities -->|"stored in"| node_db
node_bootstrap -->|"seeds/fixes"| node_db
node_agent -->|"orchestrates"| node_tools
node_uikit -->|"assistant ui"| node_agent
node_webapp -.->|"ships with"| node_deploy
node_boot -.->|"ships with"| node_deploy
node_agent -.->|"ships with"| node_deploy
node_gameapi -.->|"shares context"| node_agent

click node_webapp "https://github.com/hoanghai0810/football-online/blob/master/frontend/src/main.jsx"
click node_routing "https://github.com/hoanghai0810/football-online/blob/master/frontend/src/App.jsx"
click node_gamepages "https://github.com/hoanghai0810/football-online/blob/master/frontend/src/pages/Dashboard.jsx"
click node_uikit "https://github.com/hoanghai0810/football-online/blob/master/frontend/src/components/AiAssistant.jsx"
click node_api "https://github.com/hoanghai0810/football-online/blob/master/frontend/src/services/api.js"
click node_boot "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/FootballApplication.java"
click node_security "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/config/SecurityConfig.java"
click node_authctl "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/controller/AuthController.java"
click node_gameapi "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/controller/GameplayController.java"
click node_matchsvc "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/service/MatchSimulationEngine.java"
click node_domainsvc "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/service/SquadService.java"
click node_bootstrap "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/config/DataInitializer.java"
click node_repo "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/repository/UserRepository.java"
click node_entities "https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/entity/Users.java"
click node_agent "https://github.com/hoanghai0810/football-online/blob/master/chatbot/src/server.py"
click node_tools "https://github.com/hoanghai0810/football-online/blob/master/chatbot/src/tools.py"
click node_deploy "https://github.com/hoanghai0810/football-online/blob/master/render.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_webapp,node_routing,node_gamepages,node_uikit,node_api toneBlue
class node_boot,node_security,node_authctl,node_gameapi,node_matchsvc,node_domainsvc,node_bootstrap toneAmber
class node_agent,node_tools toneMint
class node_repo,node_entities,node_db toneRose
class node_deploy toneIndigo
```

## Components

### Frontend

React UI, routing, and client-side state

- [Browser UI](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/main.jsx): react app · Vite-based frontend for game play, navigation, and assistant entry point · `frontend/src/main.jsx`
- [Pages](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/App.jsx): routing/state · App shell, protected routes, and auth context for game pages · `frontend/src/App.jsx`
- [Game Modes](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/pages/Dashboard.jsx): views · Dashboard, market, packs, squad, tournaments, solo match, trophies, quests, and upgrades · `frontend/src/pages/Dashboard.jsx`
- [Shared UI](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/components/AiAssistant.jsx): components · Reusable match, standings, leaderboards, and assistant components · `frontend/src/components/AiAssistant.jsx`
- [API Client](https://github.com/hoanghai0810/football-online/blob/master/frontend/src/services/api.js): http client · Frontend service layer used to call the backend APIs · `frontend/src/services/api.js`

### Backend

Spring Boot game API and persistence boundary

- [FootballApp](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/FootballApplication.java): spring boot · Backend application entry point · `backend/src/main/java/com/example/football/FootballApplication.java`
- [Security](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/config/SecurityConfig.java): auth · JWT, OAuth2, user details, and request filtering · `backend/src/main/java/com/example/football/config/SecurityConfig.java`
- [Auth API](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/controller/AuthController.java): controller · Login, token issuance, and OAuth2 callback handling · `backend/src/main/java/com/example/football/controller/AuthController.java`
- [Game APIs](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/controller/GameplayController.java): controllers · Gameplay, squad, inventory, missions, careers, users, players, and AI endpoints · `backend/src/main/java/com/example/football/controller/GameplayController.java`
- [Match Engine](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/service/MatchSimulationEngine.java): simulation service · Match service and simulation engine for gameplay results · `backend/src/main/java/com/example/football/service/MatchSimulationEngine.java`
- [Game Services](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/service/SquadService.java): domain services · Squad, inventory, mission, career, player card, season generation, and startup services · `backend/src/main/java/com/example/football/service/SquadService.java`
- [Bootstrap](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/config/DataInitializer.java): startup/migration · Data initialization, schema fixes, seeding, and versioned migrations · `backend/src/main/java/com/example/football/config/DataInitializer.java`

### AI Service

Python assistant service for coaching and advice

- [Chat Agent](https://github.com/hoanghai0810/football-online/blob/master/chatbot/src/server.py): python service · LangGraph/LangChain-style assistant orchestration for coaching and tactical advice · `chatbot/src/server.py`
- [Agent Tools](https://github.com/hoanghai0810/football-online/blob/master/chatbot/src/tools.py): tooling · Game-context tools and prompt/state logic used by the assistant · `chatbot/src/tools.py`

### Data

Database, entities, repositories, and migrations

- [Repositories](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/repository/UserRepository.java): persistence · Spring Data repositories for users, squads, cards, tournaments, trophies, and related state · `backend/src/main/java/com/example/football/repository/UserRepository.java`
- [Domain Model](https://github.com/hoanghai0810/football-online/blob/master/backend/src/main/java/com/example/football/entity/Users.java): jpa entities · Users, careers, cards, squads, missions, seasons, tournaments, standings, trophies, and fixtures · `backend/src/main/java/com/example/football/entity/Users.java`
- **SQL DB**: database · H2 locally and managed SQL in production; backend system of record

### Delivery

Docker and Render deployment setup

- [Deploy](https://github.com/hoanghai0810/football-online/blob/master/render.yaml): docker/render · Separate containerization and Render service definitions for frontend, backend, and chatbot · `render.yaml`

## Connections

- Browser UI → Pages: renders · Browser app is composed into routing and page state
- Pages → Game Modes: navigates · Protected routes drive the major game modes
- Pages → Shared UI: uses · Shared components are mounted across pages
- Shared UI → API Client: fetches · UI widgets call backend services through the API client
- Game Modes → API Client: calls · Game pages load and mutate game state via the API client
- API Client → Auth API: auth · Frontend login and token flows reach the auth API
- API Client → Game APIs: game data · Frontend game actions call the backend feature controllers
- FootballApp → Security: configures · Application startup wires auth and request protection
- Auth API → Security: uses · Auth endpoints depend on JWT and OAuth2 security components
- Game APIs → Game Services: delegates · Controllers hand off business logic to domain services
- Game Services → Match Engine: simulates · Gameplay services use the match simulation boundary
- Game Services → Repositories: persists · Domain services read and write through repositories
- Repositories → Domain Model: maps · Repositories operate over the JPA domain model
- Domain Model → SQL DB: stored in · Entity state is persisted to the SQL database
- Bootstrap → SQL DB: seeds/fixes · Startup logic seeds data and repairs schema/content
- Chat Agent → Agent Tools: orchestrates · Assistant runtime uses prompts, state, and tools
- Shared UI → Chat Agent: assistant ui · AI assistant UI communicates with the chatbot service
- Browser UI → Deploy: ships with · Frontend build is part of the deployment setup
- FootballApp → Deploy: ships with · Backend container and Render service are defined for deployment
- Chat Agent → Deploy: ships with · Chatbot container and Render service are defined for deployment
- Game APIs → Chat Agent: shares context · Assistant flow can consume live game state from the platform
