# tanshanbhogue/monopoly-bank-manager architecture

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

- Interactive diagram: https://gitdiagram.com/tanshanbhogue/monopoly-bank-manager
- Repository: https://github.com/tanshanbhogue/monopoly-bank-manager

## Overview

#### Purpose and runtime

Monopoly Bank Manager is a single-process web application for managing players, balances, and money transfers during one Monopoly game. It runs as a Python Flask server with intentionally ephemeral in-memory state; restarting the process loses the game.

Primary server entry point: `app.py`. Browser entry point: `static/index.html`.

#### Application boundary

`app.py` owns both the REST API and game state. It serves the static browser UI and exposes `/api/*` endpoints for player lifecycle, transactions, history, and reset. There is no database, background worker, authentication layer, or external service integration.

Dependencies are installed from `requirements.txt`; execution is `python app.py`.

#### In-memory game model

The backend maintains the authoritative collection of players and transaction history in process memory in `app.py`.

Core domain rules:
- Players have IDs, names, and balances.
- `"BANK"` is a special transaction endpoint with unlimited funds.
- Player senders must have sufficient balance.
- Invalid transfers are rejected before balances/history are changed.
- Reset clears both players and history.

This makes Flask process memory the transaction consistency boundary: state is suitable for one local game, not persistence, concurrent multi-process deployment, or recovery.

#### Player-management API stage

Player creation, listing, and deletion are implemented in `app.py` under:
- `GET` / `POST` `/api/players`
- `DELETE` `/api/players/<id>`

Creation validates required names, duplicate names, and starting balances. Removal updates the live player set. The frontend invokes these APIs from `static/script.js` and renders player-oriented controls in `static/index.html`.

#### Transaction execution stage

`POST /api/transactions` in `app.py` is the central business operation. It accepts source, destination, amount, and note; sources/destinations may be player IDs or `"BANK"`.

Control flow is validation first—numeric positive amount, distinct endpoints, valid player references—followed by affordability checking for player senders, balance mutation, and transaction-history recording. This ordering prevents partial balance updates on rejected requests. `GET /api/transactions` returns history newest first.

#### Browser client

The UI is framework-free and has no build pipeline:
- `static/index.html` defines the application page.
- `static/script.js` performs API requests and updates rendered game state.
- `static/style.css` supplies presentation.

The client is a consumer of the Flask API rather than an independent state authority; refreshes can reconstruct its display from player and transaction endpoints while the server remains running.

#### Reset and verification

`POST /api/reset` in `app.py` starts a fresh game by clearing all in-memory domain state. Functional API behavior and rejection cases are exercised through `tests/test_api.py`, including balance preservation after insufficient-funds failures and transaction-history correctness.

Main entry points: [`app.py`](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py) (Flask entry & static serving), [`static/index.html`](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/index.html) (Game page), [`static/script.js`](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/script.js) (API client & rendering), [`static/style.css`](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/style.css) (Presentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser client"]
  node_page["Game page<br/>HTML<br/>[index.html]"]
  node_client["API client &amp; rendering<br/>JavaScript<br/>[script.js]"]
  node_styles["Presentation<br/>CSS<br/>[style.css]"]
end

subgraph group_server["Flask process"]
  node_app["Flask entry &amp; static serving<br/>Flask app<br/>[app.py]"]
  node_players_api["Player lifecycle API<br/>/api/players<br/>[app.py]"]
  node_transactions_api["Transaction API<br/>/api/transactions<br/>[app.py]"]
  node_transfer_rules["Transfer validation &amp; mutation<br/>domain operation<br/>[app.py]"]
  node_reset_api["Game reset API<br/>/api/reset<br/>[app.py]"]
  node_players_state[("Players &amp; balances<br/>in-memory state<br/>[app.py]")]
  node_history_state[("Transaction history<br/>in-memory state<br/>[app.py]")]
  node_bank["BANK endpoint<br/>domain special case<br/>[app.py]"]
end

node_page -->|"loads"| node_client
node_page -->|"uses"| node_styles
node_client -->|"fetches API and static UI"| node_app
node_app -->|"routes"| node_players_api
node_app -->|"routes"| node_transactions_api
node_app -->|"routes"| node_reset_api
node_players_api -->|"creates, lists, deletes"| node_players_state
node_transactions_api -->|"POST transfer"| node_transfer_rules
node_transactions_api -->|"GET history"| node_history_state
node_transfer_rules -->|"checks and mutates balances"| node_players_state
node_transfer_rules -->|"records successful transfer"| node_history_state
node_transfer_rules -->|"allows source or destination"| node_bank
node_reset_api -->|"clears"| node_players_state
node_reset_api -->|"clears"| node_history_state

click node_page "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/index.html"
click node_client "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/script.js"
click node_styles "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/style.css"
click node_app "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"
click node_players_api "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"
click node_transactions_api "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"
click node_transfer_rules "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"
click node_reset_api "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"
click node_players_state "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"
click node_history_state "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"
click node_bank "https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py"

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_page,node_client,node_styles toneBlue
class node_app,node_players_api,node_transactions_api,node_transfer_rules,node_reset_api,node_players_state,node_history_state,node_bank toneAmber
```

## Components

### Browser client

- [Game page](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/index.html): HTML · `static/index.html`
- [API client & rendering](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/script.js): JavaScript · Refreshes UI from server state. · `static/script.js`
- [Presentation](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/static/style.css): CSS · `static/style.css`

### Flask process

Single process; all game state is ephemeral in memory.

- [Flask entry & static serving](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): Flask app · Serves the browser UI and owns all REST routes. · `app.py`
- [Player lifecycle API](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): /api/players · Creates, lists, and removes live players. · `app.py`
- [Transaction API](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): /api/transactions · Executes transfers and returns newest-first history. · `app.py`
- [Transfer validation & mutation](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): domain operation · Validates before affordability checks, balance changes, and history recording. · `app.py`
- [Game reset API](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): /api/reset · Clears all live game state. · `app.py`
- [Players & balances](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): in-memory state · Authoritative player IDs, names, and balances. · `app.py`
- [Transaction history](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): in-memory state · Recorded only after successful transfers. · `app.py`
- [BANK endpoint](https://github.com/tanshanbhogue/monopoly-bank-manager/blob/main/app.py): domain special case · Unlimited-funds transaction endpoint. · `app.py`

## Connections

- Game page → API client & rendering: loads
- Game page → Presentation: uses
- API client & rendering → Flask entry & static serving: fetches API and static UI
- Flask entry & static serving → Player lifecycle API: routes
- Flask entry & static serving → Transaction API: routes
- Flask entry & static serving → Game reset API: routes
- Player lifecycle API → Players & balances: creates, lists, deletes
- Transaction API → Transfer validation & mutation: POST transfer
- Transaction API → Transaction history: GET history
- Transfer validation & mutation → Players & balances: checks and mutates balances
- Transfer validation & mutation → Transaction history: records successful transfer
- Transfer validation & mutation → BANK endpoint: allows source or destination
- Game reset API → Players & balances: clears
- Game reset API → Transaction history: clears
