# abhinandan2699/nestnavigate architecture

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

- Interactive diagram: https://gitdiagram.com/abhinandan2699/nestnavigate
- Repository: https://github.com/abhinandan2699/nestnavigate

## Overview

1. **High-level shape**
   - This is a **React 18 + Vite + TypeScript** game app with a clear split between **UI/state orchestration** and a **Phaser 3 canvas layer**.
   - React owns the game state and screen transitions; Phaser is used for the animated/visual playfield only.

2. **App flow / screen boundaries**
   - The main user journey is organized into three screens under `src/screens`:
     - `StartScreen` for the intro / entry point
     - `GameScreen` for the live bidding loop
     - `ResultScreen` for the post-game outcome and scoring
   - `App.tsx` is the top-level router-like switch that decides which screen is active.

3. **Central game orchestration**
   - `src/hooks/useGameEngine.ts` is the core stateful subsystem.
   - It likely coordinates:
     - round progression
     - timer expiration
     - player actions like raise/hold/walk away/waive coverage
     - rival behavior
     - end-of-game resolution
   - This hook is the main boundary between user input and game rules.

4. **React UI components**
   - `BidPanel.tsx` is the action surface for the player’s bidding decisions.
   - `Timer.tsx` presents the round countdown pressure.
   - `RivalFeed.tsx` displays opponent activity/taunts and likely mirrors engine events.
   - `ScoreSummary.tsx` renders the final outcome and financial lesson after the reveal.
   - `PhaserCanvas.tsx` is the bridge component that mounts the Phaser instance inside the React layout.

5. **Phaser subsystem**
   - The Phaser code lives under `src/phaser`.
   - `game.ts` is the Phaser bootstrap/config entry.
   - `scenes/BiddingScene.ts` is the primary scene for in-round visual feedback.
   - Per the README, Phaser renders the neighborhood/house visuals, timer bar, and feedback effects, while React remains the source of truth for gameplay state.

6. **React ↔ Phaser integration**
   - The architecture uses a **shared event-driven bridge** rather than sharing DOM/canvas state directly.
   - React state changes are emitted into the Phaser scene, and the scene reacts visually.
   - This keeps rendering concerns isolated from game logic and avoids Phaser becoming the state owner.

7. **Domain logic**
   - `src/utils/rivals.ts` encodes opponent behavior, especially each rival’s aggression profile.
   - `src/utils/scoring.ts` handles the financial outcome rules: appraisal comparison, bid result, and whether the player can actually close after waiving the gap.
   - These utilities are pure rule engines and are important boundaries for the game’s lesson.

8. **Shared types and configuration**
   - `src/types.ts` defines the core domain models used across screens, hooks, and game logic.
   - `src/config.ts` likely centralizes tunable values such as starting price, bid increment, timing, or rival parameters.
   - This keeps the rules consistent across UI and engine layers.

9. **Data flow through the game**
   - Player input starts in `BidPanel`.
   - `useGameEngine` applies the rules, updates state, and triggers round/rival/timer changes.
   - `RivalFeed`, `Timer`, and the Phaser scene all consume that same evolving state in different forms.
   - When the game ends, `ResultScreen` uses scoring output to show whether the player merely won the bid or actually can close the deal.

10. **Repository-level emphasis**
   - The architecture is intentionally simple: no external backend, no persistent store, no complex global state library.
   - The important boundaries are:
     - **screen composition**
     - **game engine vs presentation**
     - **React state vs Phaser rendering**
     - **pure scoring/rival logic vs interactive gameplay**

Main entry points: [`src/hooks/useGameEngine.ts`](https://github.com/abhinandan2699/nestnavigate/blob/main/src/hooks/useGameEngine.ts) (Game Engine), [`src/screens/GameScreen.tsx`](https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/GameScreen.tsx) (Game), [`src/App.tsx`](https://github.com/abhinandan2699/nestnavigate/blob/main/src/App.tsx) (App), [`src/screens/ResultScreen.tsx`](https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/ResultScreen.tsx) (Result)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_ui["React UI"]
  node_app["App<br/>router shell<br/>[App.tsx]"]
  node_start_screen["Start<br/>screen<br/>[StartScreen.tsx]"]
  node_game_screen["Game<br/>screen<br/>[GameScreen.tsx]"]
  node_result_screen["Result<br/>screen<br/>[ResultScreen.tsx]"]
  node_bid_panel["Bid Panel<br/>control UI<br/>[BidPanel.tsx]"]
  node_timer(("Timer<br/>status UI<br/>[Timer.tsx]"))
  node_rival_feed["Rival Feed<br/>event UI<br/>[RivalFeed.tsx]"]
  node_score_summary["Score Summary<br/>summary UI<br/>[ScoreSummary.tsx]"]
  node_phaser_canvas["Canvas Bridge<br/>integration<br/>[PhaserCanvas.tsx]"]
end

subgraph group_group_engine["Game Engine"]
  node_use_game_engine{{"Game Engine<br/>state hook<br/>[useGameEngine.ts]"}}
end

subgraph group_group_phaser["Phaser Layer"]
  node_phaser_game["Phaser Boot<br/>bootstrap<br/>[game.ts]"]
  node_bidding_scene["Bidding Scene<br/>[BiddingScene.ts]"]
end

subgraph group_group_domain["Domain Rules"]
  node_shared_types["Types<br/>domain model<br/>[types.ts]"]
  node_config["Config<br/>tuning<br/>[config.ts]"]
  node_rivals["Rivals<br/>rule util<br/>[rivals.ts]"]
  node_scoring["Scoring<br/>rule util<br/>[scoring.ts]"]
end

node_app -->|"entry"| node_start_screen
node_app -->|"play"| node_game_screen
node_app -->|"results"| node_result_screen
node_game_screen -->|"state"| node_use_game_engine
node_game_screen -->|"actions"| node_bid_panel
node_game_screen -->|"countdown"| node_timer
node_game_screen -->|"events"| node_rival_feed
node_game_screen -->|"visuals"| node_phaser_canvas
node_result_screen -->|"summary"| node_score_summary
node_bid_panel -->|"input"| node_use_game_engine
node_use_game_engine -->|"models"| node_shared_types
node_use_game_engine -->|"tuning"| node_config
node_use_game_engine -->|"opponents"| node_rivals
node_use_game_engine -->|"outcome"| node_scoring
node_phaser_canvas -->|"boot"| node_phaser_game
node_phaser_game -->|"scene"| node_bidding_scene
node_use_game_engine -.->|"events"| node_phaser_canvas
node_use_game_engine -.->|"finish"| node_result_screen

click node_app "https://github.com/abhinandan2699/nestnavigate/blob/main/src/App.tsx"
click node_start_screen "https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/StartScreen.tsx"
click node_game_screen "https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/GameScreen.tsx"
click node_result_screen "https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/ResultScreen.tsx"
click node_bid_panel "https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/BidPanel.tsx"
click node_timer "https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/Timer.tsx"
click node_rival_feed "https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/RivalFeed.tsx"
click node_score_summary "https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/ScoreSummary.tsx"
click node_phaser_canvas "https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/PhaserCanvas.tsx"
click node_use_game_engine "https://github.com/abhinandan2699/nestnavigate/blob/main/src/hooks/useGameEngine.ts"
click node_shared_types "https://github.com/abhinandan2699/nestnavigate/blob/main/src/types.ts"
click node_config "https://github.com/abhinandan2699/nestnavigate/blob/main/src/config.ts"
click node_rivals "https://github.com/abhinandan2699/nestnavigate/blob/main/src/utils/rivals.ts"
click node_scoring "https://github.com/abhinandan2699/nestnavigate/blob/main/src/utils/scoring.ts"
click node_phaser_game "https://github.com/abhinandan2699/nestnavigate/blob/main/src/phaser/game.ts"
click node_bidding_scene "https://github.com/abhinandan2699/nestnavigate/blob/main/src/phaser/scenes/BiddingScene.ts"

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_app,node_start_screen,node_game_screen,node_result_screen,node_bid_panel,node_timer,node_rival_feed,node_score_summary,node_phaser_canvas toneBlue
class node_use_game_engine toneAmber
class node_phaser_game,node_bidding_scene toneMint
class node_shared_types,node_config,node_rivals,node_scoring toneRose
```

## Components

### React UI

Top-level screens and presentation components

- [App](https://github.com/abhinandan2699/nestnavigate/blob/main/src/App.tsx): router shell · Top-level screen switch for the game flow · `src/App.tsx`
- [Start](https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/StartScreen.tsx): screen · Intro and entry point · `src/screens/StartScreen.tsx`
- [Game](https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/GameScreen.tsx): screen · Active bidding play screen · `src/screens/GameScreen.tsx`
- [Result](https://github.com/abhinandan2699/nestnavigate/blob/main/src/screens/ResultScreen.tsx): screen · Post-game outcome and scoring screen · `src/screens/ResultScreen.tsx`
- [Bid Panel](https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/BidPanel.tsx): control UI · Player action surface for bidding decisions · `src/components/BidPanel.tsx`
- [Timer](https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/Timer.tsx): status UI · Round countdown and pressure indicator · `src/components/Timer.tsx`
- [Rival Feed](https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/RivalFeed.tsx): event UI · Opponent activity and taunts view · `src/components/RivalFeed.tsx`
- [Score Summary](https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/ScoreSummary.tsx): summary UI · Final outcome and financial lesson display · `src/components/ScoreSummary.tsx`
- [Canvas Bridge](https://github.com/abhinandan2699/nestnavigate/blob/main/src/components/PhaserCanvas.tsx): integration · Mounts the Phaser instance inside React · `src/components/PhaserCanvas.tsx`

### Game Engine

State orchestration and round flow

- [Game Engine](https://github.com/abhinandan2699/nestnavigate/blob/main/src/hooks/useGameEngine.ts): state hook · Core orchestration for rounds, actions, rivals, and end state · `src/hooks/useGameEngine.ts`

### Phaser Layer

Canvas rendering and scene bootstrap

- [Phaser Boot](https://github.com/abhinandan2699/nestnavigate/blob/main/src/phaser/game.ts): bootstrap · Phaser game configuration and startup · `src/phaser/game.ts`
- [Bidding Scene](https://github.com/abhinandan2699/nestnavigate/blob/main/src/phaser/scenes/BiddingScene.ts): scene · Primary in-round visual feedback scene · `src/phaser/scenes/BiddingScene.ts`

### Domain Rules

Shared types, config, scoring, and rival logic

- [Types](https://github.com/abhinandan2699/nestnavigate/blob/main/src/types.ts): domain model · Shared game data models · `src/types.ts`
- [Config](https://github.com/abhinandan2699/nestnavigate/blob/main/src/config.ts): tuning · Central gameplay constants and parameters · `src/config.ts`
- [Rivals](https://github.com/abhinandan2699/nestnavigate/blob/main/src/utils/rivals.ts): rule util · Opponent aggression and behavior logic · `src/utils/rivals.ts`
- [Scoring](https://github.com/abhinandan2699/nestnavigate/blob/main/src/utils/scoring.ts): rule util · Appraisal, bid outcome, and closing rules · `src/utils/scoring.ts`

## Connections

- App → Start: entry · Routes to the intro screen
- App → Game: play · Routes into the live game screen
- App → Result: results · Routes to the outcome screen
- Game → Game Engine: state · Game screen consumes the core engine state
- Game → Bid Panel: actions · Player decisions originate here
- Game → Timer: countdown · Shows remaining round time
- Game → Rival Feed: events · Displays rival and engine events
- Game → Canvas Bridge: visuals · Embeds the canvas playfield
- Result → Score Summary: summary · Shows final scoring and outcome
- Bid Panel → Game Engine: input · Player actions are applied by the engine
- Game Engine → Types: models · Uses shared game domain types
- Game Engine → Config: tuning · Reads gameplay constants
- Game Engine → Rivals: opponents · Uses rival behavior rules
- Game Engine → Scoring: outcome · Computes bid and closing results
- Canvas Bridge → Phaser Boot: boot · Creates and mounts the Phaser instance
- Phaser Boot → Bidding Scene: scene · Starts the main bidding scene
- Game Engine → Canvas Bridge: events · Emits state changes for visual updates
- Game Engine → Result: finish · Feeds end-of-game result state
