# cyan8041/spacewars architecture

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

- Interactive diagram: https://gitdiagram.com/cyan8041/spacewars
- Repository: https://github.com/cyan8041/spacewars

## Overview

SpaceWars is a Unity 1:1 online, turn-based strategy game. A player authenticates, enters a lobby for records, rankings, and room matching, joins a waiting room to chat and choose a map, then plays a synchronized tile-grid battle; the result updates Firebase records. The graph follows the README’s documented script roles and workflow. Source excerpts were unavailable, so internal call-level relationships and unmentioned implementation details are not inferred.

Main entry points: [`Assets/Scripts/WaitLobbyManager.cs`](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/WaitLobbyManager.cs) (Lobby profile), [`Assets/Scripts/InGameManager.cs`](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/InGameManager.cs) (Turns and AP), [`Assets/Scripts/GameResult.cs`](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/GameResult.cs) (Game result), [`Assets/Scripts/FirebaseAuthManager.cs`](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/FirebaseAuthManager.cs) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and records"]
  node_auth["Authentication"]
  node_records[("Player records")]
  node_lobby_stats["Lobby profile"]
  node_rankings["Rankings"]
end

subgraph group_lobby["Lobby and matchmaking"]
  node_room_matching["Room matching<br/>[PhotonManager.cs]"]
  node_room_data["Room data<br/>[RoomData.cs]"]
  node_waiting_room["Waiting room<br/>[LobbyManager.cs]"]
end

subgraph group_battle["Turn-based battle"]
  node_map_setup["Map and units<br/>[ExampleStart.cs]"]
  node_turns_ap["Turns and AP<br/>[InGameManager.cs]"]
  node_unit_combat["Unit combat<br/>[UnitMove.cs]"]
  node_unit_combat_alt["Unit movement<br/>[UnitMove2.cs]"]
  node_base["Base health<br/>[Base.cs]"]
  node_camera["Battle camera"]
  node_result["Game result<br/>[GameResult.cs]"]
end

subgraph group_platforms["External services"]
  node_photon{{"Photon PUN"}}
  node_firebase{{"Firebase"}}
end

node_player(("Player"))

node_player -->|"signs in"| node_auth
node_auth -->|"authenticates"| node_firebase
node_auth -->|"initializes records"| node_records
node_player -->|"enters lobby"| node_lobby_stats
node_lobby_stats -->|"reads records"| node_records
node_lobby_stats -->|"opens rankings"| node_rankings
node_rankings -->|"queries records"| node_firebase
node_lobby_stats -->|"opens rooms"| node_room_matching
node_room_matching -->|"updates room list"| node_room_data
node_room_matching -->|"matches players"| node_photon
node_player -->|"joins room"| node_waiting_room
node_waiting_room -->|"syncs chat and room"| node_photon
node_waiting_room -->|"starts selected map"| node_map_setup
node_map_setup -->|"sets up battle"| node_turns_ap
node_turns_ap -->|"enables actions"| node_unit_combat
node_turns_ap -->|"enables actions"| node_unit_combat_alt
node_unit_combat -->|"syncs combat"| node_photon
node_unit_combat_alt -->|"syncs combat"| node_photon
node_unit_combat -->|"attacks base"| node_base
node_turns_ap -->|"checks victory"| node_result
node_result -->|"sends result RPC"| node_photon
node_result -->|"updates records"| node_firebase
node_result -->|"returns to lobby"| node_lobby_stats
node_player -->|"controls view"| node_camera

click node_auth "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/FirebaseAuthManager.cs"
click node_records "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/FirebaseAuthManager.cs"
click node_lobby_stats "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/WaitLobbyManager.cs"
click node_rankings "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/LeaderBoardManager.cs"
click node_room_matching "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/PhotonManager.cs"
click node_room_data "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/RoomData.cs"
click node_waiting_room "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/LobbyManager.cs"
click node_map_setup "https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/ExampleStart.cs"
click node_turns_ap "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/InGameManager.cs"
click node_unit_combat "https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/UnitMove.cs"
click node_unit_combat_alt "https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/UnitMove2.cs"
click node_base "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/Base.cs"
click node_camera "https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/CameraController.cs"
click node_result "https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/GameResult.cs"

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_auth,node_records,node_lobby_stats,node_rankings toneBlue
class node_room_matching,node_room_data,node_waiting_room toneAmber
class node_map_setup,node_turns_ap,node_unit_combat,node_unit_combat_alt,node_base,node_camera,node_result toneMint
class node_photon,node_firebase toneRose
class node_player toneIndigo
```

## Components

### Identity and records

- [Authentication](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/FirebaseAuthManager.cs): `Assets/Scripts/FirebaseAuthManager.cs`
- [Player records](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/FirebaseAuthManager.cs): `Assets/Scripts/FirebaseAuthManager.cs`
- [Lobby profile](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/WaitLobbyManager.cs): `Assets/Scripts/WaitLobbyManager.cs`
- [Rankings](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/LeaderBoardManager.cs): `Assets/Scripts/LeaderBoardManager.cs`

### Lobby and matchmaking

- [Room matching](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/PhotonManager.cs): `Assets/Scripts/PhotonManager.cs`
- [Room data](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/RoomData.cs): `Assets/Scripts/RoomData.cs`
- [Waiting room](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/LobbyManager.cs): `Assets/Scripts/LobbyManager.cs`

### Turn-based battle

- [Map and units](https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/ExampleStart.cs): `Assets/RedBjorn/ProtoTiles/Examples/Scripts/ExampleStart.cs`
- [Turns and AP](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/InGameManager.cs): `Assets/Scripts/InGameManager.cs`
- [Unit combat](https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/UnitMove.cs): `Assets/RedBjorn/ProtoTiles/Examples/Scripts/UnitMove.cs`
- [Unit movement](https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/UnitMove2.cs): `Assets/RedBjorn/ProtoTiles/Examples/Scripts/UnitMove2.cs`
- [Base health](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/Base.cs): `Assets/Scripts/Base.cs`
- [Battle camera](https://github.com/cyan8041/spacewars/blob/main/Assets/RedBjorn/ProtoTiles/Examples/Scripts/CameraController.cs): `Assets/RedBjorn/ProtoTiles/Examples/Scripts/CameraController.cs`
- [Game result](https://github.com/cyan8041/spacewars/blob/main/Assets/Scripts/GameResult.cs): `Assets/Scripts/GameResult.cs`

### External services

- **Photon PUN**
- **Firebase**

### Other components

- **Player**

## Connections

- Player → Authentication: signs in
- Authentication → Firebase: authenticates
- Authentication → Player records: initializes records
- Player → Lobby profile: enters lobby
- Lobby profile → Player records: reads records
- Lobby profile → Rankings: opens rankings
- Rankings → Firebase: queries records
- Lobby profile → Room matching: opens rooms
- Room matching → Room data: updates room list
- Room matching → Photon PUN: matches players
- Player → Waiting room: joins room
- Waiting room → Photon PUN: syncs chat and room
- Waiting room → Map and units: starts selected map
- Map and units → Turns and AP: sets up battle
- Turns and AP → Unit combat: enables actions
- Turns and AP → Unit movement: enables actions
- Unit combat → Photon PUN: syncs combat
- Unit movement → Photon PUN: syncs combat
- Unit combat → Base health: attacks base
- Turns and AP → Game result: checks victory
- Game result → Photon PUN: sends result RPC
- Game result → Firebase: updates records
- Game result → Lobby profile: returns to lobby
- Player → Battle camera: controls view
