# eduardoapaiva/trabalhoredes architecture

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

- Interactive diagram: https://gitdiagram.com/eduardoapaiva/trabalhoredes
- Repository: https://github.com/eduardoapaiva/trabalhoredes

## Overview

Batalha Naval is a TCP client/server game for simultaneous two-player matches. Players connect, are paired by the server, place ships, take turns firing, and receive updated boards and win/loss results. The server also handles reconnect-to-match requests and disconnect cleanup. The map separates client interaction, server orchestration, game rules and state, and terminal rendering. Some server and game-rule code is excerpted only partially; README-documented capabilities are shown where their exact internal calls are not visible.

Main entry points: [`server.c`](https://github.com/eduardoapaiva/trabalhoredes/blob/main/server.c) (Server runtime), [`src/struct_jogo.c`](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/struct_jogo.c) (Match registry), [`src/terminal.c`](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/terminal.c) (Terminal views), [`src/funcoes.c`](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c) (Turn and combat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client interaction"]
  node_client_app["Client app<br/>[client.c]"]
end

subgraph group_server["Server orchestration"]
  node_server_runtime["Server runtime<br/>[server.c]"]
  node_matchmaking["Matchmaking<br/>[server.c]"]
  node_client_registry["Client registry<br/>[struct_cliente.c]"]
  node_match_registry["Match registry<br/>[struct_jogo.c]"]
end

subgraph group_game["Game domain"]
  node_client_state["Player state<br/>[struct_cliente.h]"]
  node_match_state["Match state<br/>[struct_jogo.h]"]
  node_board_setup["Board setup<br/>[funcoes.c]"]
  node_ship_placement["Ship placement<br/>[funcoes.c]"]
  node_turn_combat["Turn and combat<br/>[funcoes.c]"]
  node_game_config["Game configuration<br/>[consts.h]"]
end

subgraph group_presentation["Game presentation"]
  node_terminal_views["Terminal views<br/>[terminal.c]"]
  node_board_text["Board formatting<br/>[funcoes.c]"]
end

node_players(("Players"))

node_players -->|"enter commands"| node_client_app
node_client_app -->|"exchange TCP messages"| node_server_runtime
node_server_runtime -->|"pair players"| node_matchmaking
node_server_runtime -->|"register and remove"| node_client_registry
node_server_runtime -->|"create and remove matches"| node_match_registry
node_matchmaking -.->|"create match"| node_match_registry
node_match_registry -->|"initializes"| node_match_state
node_match_registry -->|"assigns players"| node_client_state
node_server_runtime -.->|"prepares boards"| node_board_setup
node_server_runtime -.->|"validates placement"| node_ship_placement
node_server_runtime -->|"validates attacks"| node_turn_combat
node_turn_combat -->|"updates boards and scores"| node_match_state
node_server_runtime -->|"dispatches game views"| node_terminal_views
node_turn_combat -->|"reports outcomes"| node_terminal_views
node_terminal_views -->|"formats boards"| node_board_text
node_terminal_views -->|"sends rendered state"| node_client_app
node_game_config -->|"sets ship fleet"| node_board_setup
node_players -->|"disconnect"| node_server_runtime
node_server_runtime -.->|"find another match"| node_matchmaking

click node_client_app "https://github.com/eduardoapaiva/trabalhoredes/blob/main/client.c"
click node_server_runtime "https://github.com/eduardoapaiva/trabalhoredes/blob/main/server.c"
click node_matchmaking "https://github.com/eduardoapaiva/trabalhoredes/blob/main/server.c"
click node_client_registry "https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/struct_cliente.c"
click node_match_registry "https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/struct_jogo.c"
click node_client_state "https://github.com/eduardoapaiva/trabalhoredes/blob/main/includes/struct_cliente.h"
click node_match_state "https://github.com/eduardoapaiva/trabalhoredes/blob/main/includes/struct_jogo.h"
click node_board_setup "https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c"
click node_ship_placement "https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c"
click node_turn_combat "https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c"
click node_terminal_views "https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/terminal.c"
click node_board_text "https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c"
click node_game_config "https://github.com/eduardoapaiva/trabalhoredes/blob/main/includes/consts.h"

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_client_app toneBlue
class node_server_runtime,node_matchmaking,node_client_registry,node_match_registry toneAmber
class node_client_state,node_match_state,node_board_setup,node_ship_placement,node_turn_combat,node_game_config toneMint
class node_terminal_views,node_board_text toneRose
class node_players toneIndigo
```

## Components

### Client interaction

- [Client app](https://github.com/eduardoapaiva/trabalhoredes/blob/main/client.c): `client.c`

### Server orchestration

- [Server runtime](https://github.com/eduardoapaiva/trabalhoredes/blob/main/server.c): `server.c`
- [Matchmaking](https://github.com/eduardoapaiva/trabalhoredes/blob/main/server.c): `server.c`
- [Client registry](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/struct_cliente.c): `src/struct_cliente.c`
- [Match registry](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/struct_jogo.c): `src/struct_jogo.c`

### Game domain

- [Player state](https://github.com/eduardoapaiva/trabalhoredes/blob/main/includes/struct_cliente.h): `includes/struct_cliente.h`
- [Match state](https://github.com/eduardoapaiva/trabalhoredes/blob/main/includes/struct_jogo.h): `includes/struct_jogo.h`
- [Board setup](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c): `src/funcoes.c`
- [Ship placement](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c): `src/funcoes.c`
- [Turn and combat](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c): `src/funcoes.c`
- [Game configuration](https://github.com/eduardoapaiva/trabalhoredes/blob/main/includes/consts.h): `includes/consts.h`

### Game presentation

- [Terminal views](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/terminal.c): `src/terminal.c`
- [Board formatting](https://github.com/eduardoapaiva/trabalhoredes/blob/main/src/funcoes.c): `src/funcoes.c`

### Other components

- **Players**

## Connections

- Players → Client app: enter commands (evidence: `README.md`)
- Client app → Server runtime: exchange TCP messages (evidence: `README.md`)
- Server runtime → Matchmaking: pair players (evidence: `README.md`)
- Server runtime → Client registry: register and remove (evidence: `server.c`)
- Server runtime → Match registry: create and remove matches (evidence: `server.c`)
- Matchmaking → Match registry: create match
- Match registry → Match state: initializes (evidence: `src/struct_jogo.c`)
- Match registry → Player state: assigns players (evidence: `src/struct_jogo.c`)
- Server runtime → Board setup: prepares boards
- Server runtime → Ship placement: validates placement
- Server runtime → Turn and combat: validates attacks (evidence: `server.c`)
- Turn and combat → Match state: updates boards and scores (evidence: `src/funcoes.c`)
- Server runtime → Terminal views: dispatches game views (evidence: `server.c`)
- Turn and combat → Terminal views: reports outcomes (evidence: `src/funcoes.c`)
- Terminal views → Board formatting: formats boards (evidence: `src/terminal.c`)
- Terminal views → Client app: sends rendered state (evidence: `src/terminal.c`)
- Game configuration → Board setup: sets ship fleet (evidence: `src/funcoes.c`)
- Players → Server runtime: disconnect (evidence: `README.md`)
- Server runtime → Matchmaking: find another match (evidence: `server.c`)
