How hoanghai0810/football-online works
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: api.js API Client · server.py Chat Agent · App.jsx Pages · AiAssistant.jsx Shared UI
Components 18
Frontend
React UI, routing, and client-side state
- Browser UI · Vite-based frontend for game play, navigation, and assistant entry point
frontend/src/main.jsx - Pages · App shell, protected routes, and auth context for game pages
frontend/src/App.jsx - Game Modes · Dashboard, market, packs, squad, tournaments, solo match, trophies, quests, and upgrades
frontend/src/pages/Dashboard.jsx - Shared UI · Reusable match, standings, leaderboards, and assistant components
frontend/src/components/AiAssistant.jsx - API Client · Frontend service layer used to call the backend APIs
frontend/src/services/api.js
Backend
Spring Boot game API and persistence boundary
- FootballApp · Backend application entry point
backend/src/main/java/com/example/football/FootballApplication.java - Security · JWT, OAuth2, user details, and request filtering
backend/src/main/java/com/example/football/config/SecurityConfig.java - Auth API · Login, token issuance, and OAuth2 callback handling
backend/src/main/java/com/example/football/controller/AuthController.java - Game APIs · Gameplay, squad, inventory, missions, careers, users, players, and AI endpoints
backend/src/main/java/com/example/football/controller/GameplayController.java - Match Engine · Match service and simulation engine for gameplay results
backend/src/main/java/com/example/football/service/MatchSimulationEngine.java - Game Services · Squad, inventory, mission, career, player card, season generation, and startup services
backend/src/main/java/com/example/football/service/SquadService.java - Bootstrap · 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 · LangGraph/LangChain-style assistant orchestration for coaching and tactical advice
chatbot/src/server.py - Agent Tools · Game-context tools and prompt/state logic used by the assistant
chatbot/src/tools.py
Data
Database, entities, repositories, and migrations
- Repositories · Spring Data repositories for users, squads, cards, tournaments, trophies, and related state
backend/src/main/java/com/example/football/repository/UserRepository.java - Domain Model · Users, careers, cards, squads, missions, seasons, tournaments, standings, trophies, and fixtures
backend/src/main/java/com/example/football/entity/Users.java - SQL DB · H2 locally and managed SQL in production; backend system of record
Delivery
Docker and Render deployment setup
- Deploy · Separate containerization and Render service definitions for frontend, backend, and chatbot
render.yaml
Connections 21
- 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