# brunoaguinaga0/batalla-naval architecture

> Architecture diagram of the GitHub repository brunoaguinaga0/batalla-naval, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/brunoaguinaga0/batalla-naval
- Repository: https://github.com/brunoaguinaga0/batalla-naval

## Overview

Batalla Naval is a PHP/MySQL browser game: players register or log in, configure a fleet and board, then play turns against an AI, with help, surrender, and ranking/record features. The graph separates account, setup, combat, and persistence responsibilities. Sampled PHP shows the main game and DAO calls; some UI/backend wiring and ranking/help/surrender implementations were not sampled, so those links are omitted or marked unverified rather than inferred.

Main entry points: [`Assets/JavaScript/JuegoJS/batalla.js`](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/JuegoJS/batalla.js) (Battle interactions), [`Pages/inicio.php`](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Pages/inicio.php) (Game lobby), [`Classes/database/PartidaDAO.php`](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/PartidaDAO.php) (Match records DAO), [`Classes/database/JugadorDAO.php`](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/JugadorDAO.php) (Player records DAO)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_accounts["Accounts"]
  node_login["Login page<br/>[index.php]"]
  node_registration["Registration page<br/>[registro.php]"]
  node_auth["Account handlers<br/>[loginBack.php]"]
  node_register_handler["Registration handler<br/>[registroBack.php]"]
end

subgraph group_setup["Fleet setup"]
  node_home["Game lobby<br/>[inicio.php]"]
  node_fleet_ui["Fleet placement UI<br/>[flota.js]"]
  node_board_ui["Board setup UI<br/>[mostrarTablero.js]"]
  node_setup_ui["Lobby interactions<br/>[juego.js]"]
  node_game_setup["Initialize match<br/>[partida.php]"]
end

subgraph group_combat["Naval combat"]
  node_battle_page["Battle page<br/>[juego_batalla.php]"]
  node_battle_ui["Battle interactions<br/>[batalla.js]"]
  node_board["Board rules<br/>[tablero.class.php]"]
  node_player_attack["Player attack handler<br/>[ataque.php]"]
  node_ai_attack["AI attack handler<br/>[ataque_ia.php]"]
  node_help["Game help<br/>[ayuda.php]"]
  node_resign["Surrender handler<br/>[rendirse.php]"]
end

subgraph group_persistence["Persistence"]
  node_ranking_handler["Global ranking<br/>[ranking.php]"]
  node_player_dao["Player records DAO<br/>[JugadorDAO.php]"]
  node_match_dao["Match records DAO<br/>[PartidaDAO.php]"]
  node_db_connection["Database connection<br/>[conexionBD.php]"]
  node_mysql[("MySQL database<br/>[batallanaval.sql]")]
end

node_player(("Player"))

node_player -->|"signs in"| node_login
node_player -->|"creates account"| node_registration
node_login -->|"posts credentials"| node_auth
node_auth -->|"authenticates"| node_player_dao
node_registration -->|"submits account"| node_register_handler
node_register_handler -->|"registers player"| node_player_dao
node_player_dao -->|"queries and updates"| node_db_connection
node_match_dao -->|"queries and writes"| node_db_connection
node_db_connection -->|"connects to"| node_mysql
node_home -->|"loads player records"| node_player_dao
node_home -->|"loads latest match"| node_match_dao
node_home -.->|"configures fleet"| node_fleet_ui
node_home -.->|"configures board"| node_board_ui
node_home -.->|"handles lobby actions"| node_setup_ui
node_player -.->|"configures match"| node_home
node_game_setup -->|"creates boards"| node_board
node_battle_page -->|"reads shot state"| node_board
node_battle_page -->|"loads personal records"| node_player_dao
node_player -.->|"plays turns"| node_battle_ui
node_battle_ui -.->|"fires at AI"| node_player_attack
node_battle_ui -.->|"requests AI turn"| node_ai_attack
node_player_attack -->|"applies shot"| node_board
node_player_attack -->|"saves victory"| node_match_dao
node_ai_attack -->|"applies AI shot"| node_board
node_ai_attack -->|"saves defeat"| node_match_dao
node_battle_ui -.->|"requests hint"| node_help
node_battle_ui -.->|"submits surrender"| node_resign
node_battle_ui -.->|"loads ranking"| node_ranking_handler
node_ranking_handler -->|"retrieves top five"| node_match_dao
node_match_dao -->|"joins player records"| node_player_dao

click node_login "https://github.com/brunoaguinaga0/batalla-naval/blob/main/index.php"
click node_registration "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Pages/registro.php"
click node_auth "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/loginBack.php"
click node_register_handler "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/registroBack.php"
click node_home "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Pages/inicio.php"
click node_fleet_ui "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/InicioJS/flota.js"
click node_board_ui "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/InicioJS/mostrarTablero.js"
click node_setup_ui "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/InicioJS/juego.js"
click node_game_setup "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/partida.php"
click node_battle_page "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Pages/juego_batalla.php"
click node_battle_ui "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/JuegoJS/batalla.js"
click node_board "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/entities/tablero.class.php"
click node_player_attack "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ataque.php"
click node_ai_attack "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ataque_ia.php"
click node_help "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ayuda.php"
click node_resign "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/rendirse.php"
click node_ranking_handler "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ranking.php"
click node_player_dao "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/JugadorDAO.php"
click node_match_dao "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/PartidaDAO.php"
click node_db_connection "https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/conexionBD.php"
click node_mysql "https://github.com/brunoaguinaga0/batalla-naval/blob/main/ZBD%20BATALLA%20NAVAL/batallanaval.sql"

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_login,node_registration,node_auth,node_register_handler toneBlue
class node_home,node_fleet_ui,node_board_ui,node_setup_ui,node_game_setup toneAmber
class node_battle_page,node_battle_ui,node_board,node_player_attack,node_ai_attack,node_help,node_resign toneMint
class node_ranking_handler,node_player_dao,node_match_dao,node_db_connection,node_mysql toneRose
class node_player toneIndigo
```

## Components

### Accounts

- [Login page](https://github.com/brunoaguinaga0/batalla-naval/blob/main/index.php): `index.php`
- [Registration page](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Pages/registro.php): `Pages/registro.php`
- [Account handlers](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/loginBack.php): `Backend/loginBack.php`
- [Registration handler](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/registroBack.php): `Backend/registroBack.php`

### Fleet setup

- [Game lobby](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Pages/inicio.php): `Pages/inicio.php`
- [Fleet placement UI](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/InicioJS/flota.js): `Assets/JavaScript/InicioJS/flota.js`
- [Board setup UI](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/InicioJS/mostrarTablero.js): `Assets/JavaScript/InicioJS/mostrarTablero.js`
- [Lobby interactions](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/InicioJS/juego.js): `Assets/JavaScript/InicioJS/juego.js`
- [Initialize match](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/partida.php): `Backend/partida.php`

### Naval combat

- [Battle page](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Pages/juego_batalla.php): `Pages/juego_batalla.php`
- [Battle interactions](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Assets/JavaScript/JuegoJS/batalla.js): `Assets/JavaScript/JuegoJS/batalla.js`
- [Board rules](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/entities/tablero.class.php): `Classes/entities/tablero.class.php`
- [Player attack handler](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ataque.php): `Backend/ataque.php`
- [AI attack handler](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ataque_ia.php): `Backend/ataque_ia.php`
- [Game help](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ayuda.php): `Backend/ayuda.php`
- [Surrender handler](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/rendirse.php): `Backend/rendirse.php`

### Persistence

- [Global ranking](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Backend/ranking.php): `Backend/ranking.php`
- [Player records DAO](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/JugadorDAO.php): `Classes/database/JugadorDAO.php`
- [Match records DAO](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/PartidaDAO.php): `Classes/database/PartidaDAO.php`
- [Database connection](https://github.com/brunoaguinaga0/batalla-naval/blob/main/Classes/database/conexionBD.php): `Classes/database/conexionBD.php`
- [MySQL database](https://github.com/brunoaguinaga0/batalla-naval/blob/main/ZBD%20BATALLA%20NAVAL/batallanaval.sql): `ZBD BATALLA NAVAL/batallanaval.sql`

### Other components

- **Player**

## Connections

- Player → Login page: signs in (evidence: `index.php`)
- Player → Registration page: creates account (evidence: `Pages/registro.php`)
- Login page → Account handlers: posts credentials (evidence: `index.php`)
- Account handlers → Player records DAO: authenticates (evidence: `Backend/loginBack.php`)
- Registration page → Registration handler: submits account (evidence: `Pages/registro.php`)
- Registration handler → Player records DAO: registers player (evidence: `Backend/registroBack.php`)
- Player records DAO → Database connection: queries and updates (evidence: `Classes/database/JugadorDAO.php`)
- Match records DAO → Database connection: queries and writes (evidence: `Classes/database/PartidaDAO.php`)
- Database connection → MySQL database: connects to (evidence: `Classes/database/conexionBD.php`)
- Game lobby → Player records DAO: loads player records (evidence: `Pages/inicio.php`)
- Game lobby → Match records DAO: loads latest match (evidence: `Pages/inicio.php`)
- Game lobby → Fleet placement UI: configures fleet
- Game lobby → Board setup UI: configures board
- Game lobby → Lobby interactions: handles lobby actions
- Player → Game lobby: configures match
- Initialize match → Board rules: creates boards (evidence: `Backend/partida.php`)
- Battle page → Board rules: reads shot state (evidence: `Pages/juego_batalla.php`)
- Battle page → Player records DAO: loads personal records (evidence: `Pages/juego_batalla.php`)
- Player → Battle interactions: plays turns
- Battle interactions → Player attack handler: fires at AI
- Battle interactions → AI attack handler: requests AI turn
- Player attack handler → Board rules: applies shot (evidence: `Backend/ataque.php`)
- Player attack handler → Match records DAO: saves victory (evidence: `Backend/ataque.php`)
- AI attack handler → Board rules: applies AI shot (evidence: `Backend/ataque_ia.php`)
- AI attack handler → Match records DAO: saves defeat (evidence: `Backend/ataque_ia.php`)
- Battle interactions → Game help: requests hint
- Battle interactions → Surrender handler: submits surrender
- Battle interactions → Global ranking: loads ranking
- Global ranking → Match records DAO: retrieves top five (evidence: `Backend/ranking.php`)
- Match records DAO → Player records DAO: joins player records (evidence: `Classes/database/PartidaDAO.php`)
