# mrbogdan/monopoly architecture

> Architecture diagram of the GitHub repository mrbogdan/monopoly, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrbogdan/monopoly
- Repository: https://github.com/mrbogdan/monopoly

## Overview

##### Project Type and Purpose
- The README confirms that this is an online Monopoly game. The project is a full-stack application, with a clear separation between the client (frontend) and the service (backend/game engine).
- The purpose is to run an online version of Monopoly, managing game state, player actions, and possibly real-time interactions.

##### File Structure
- Two main directories:
- The “client” folder: Contains JavaScript, HTML, and CSS resources. Likely responsible for rendering the game interface (e.g., map-playground.html) and interacting with the backend via APIs or WebSockets.
- The “service” folder: Implements the backend logic in TypeScript. This folder includes modules for:
▪ Game Logic: Components inside “src/game”, “src/action”, “src/tile”, and “src/tiles” that define how the game works, player actions, and board tiles (including specialized files for different types of tiles like Airlines, Cars, Restaurants, etc.).
▪ User Management: Found in “src/user” with repositories and services emphasizing user configuration and persistence (using a Postgres repository).
▪ HTTP Server: Modules under “src/http” and “src/decorators” which set up routes, controllers, and related middleware for REST API endpoints (e.g., HealthController.ts, UserPublicController.ts).
▪ WebSocket Server: Located in “src/wss”, indicating support for real-time communications.
▪ Dependency Injection (DI) and Error Handling: Seen in directories “src/di” and “src/errors” to manage service configurations and fault handling.
▪ Database Migrations: Files under “src/migrations” that handle schema changes (e.g., create-user-table.sql).
- Additional files:
- Docker-related files (e.g., docker-compose.yml, Dockerfiles) indicate containerization for deployment.
- Configuration files for linting, testing (Jest), and build scripts give insight into quality control and CI/CD processes.
- An extensive “docs” folder provides guidelines on collaboration, diagramming, and project-specific documentation.

- Components to include:
- Client (Frontend): A browser-based interface built using HTML/CSS/JS. It likely interacts via HTTP REST endpoints and/or WebSockets.
- Service (Backend): A NodeJS/TypeScript application subdivided into several layers:
▪ API Layer: HTTP server components, controllers, and route handlers (REST endpoints).
▪ WebSocket Layer: For real-time communication.
▪ Business Logic Layer: Game mechanics (game logic, action processing, tile management, bank operations) and user services.
▪ Data Access Layer: Repositories (like PostgresUserRepository) and migration management, interacting with a PostgreSQL database.
▪ Dependency Injection and Error Handling: Framework-level support for managing modules (using decorators, DI container) and managing protocol vs. business errors.
- External Services/Infrastructure:
▪ Database: Though not explicitly depicted as a folder, the use of a Postgres client and migrations indicate a PostgreSQL instance.
▪ Docker/Deployment: Container architecture using docker-compose pulls in both client and service components.
- Relationships:
- The Client calls backend REST APIs and WebSocket endpoints.
- The Backend routes the requests to the game logic and user management modules.
- The backend communicates with a database for persistent storage.
- CI/CD workflows (shown in .github/workflows) provide integration testing and code quality, though these are typically abstracted from the runtime architecture.

##### Architectural Patterns and Design Principles
- The project structure encourages separation of concerns: separating HTTP handling from game logic and data access.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Client (Frontend)"
        ClientFrontend("Client UI"):::frontend
    end

    subgraph "Service (Backend)"
        subgraph "API & WebSocket Layer"
            HTTPAPIServer("HTTP API Server"):::api
            WSS("WebSocket Server"):::api
        end
        subgraph "Business Logic Layer"
            subgraph "Game Modules"
                GameLogic("Game Logic"):::business
                ActionProcess("Action Processing"):::business
                TileModule("Tile Module"):::business
                TilesModule("Tiles Module"):::business
            end
            UserMgmt("User Management"):::business
        end
        subgraph "Data Access Layer"
            DBMigrations("Database Migrations"):::infra
        end
        subgraph "Infrastructure & Utilities"
            DI("Dependency Injection (DI)"):::infra
            ErrorHandling("Error Handling"):::infra
        end
    end

    subgraph "External Services"
        PostgresDB("PostgreSQL Database"):::db
    end

    subgraph "Deployment"
        Docker("Docker/Deployment"):::deploy
    end

    ClientFrontend -->|"REST/WebSocket"| HTTPAPIServer
    ClientFrontend -->|"REST/WebSocket"| WSS
    HTTPAPIServer -->|"Calls"| GameLogic
    HTTPAPIServer -->|"Calls"| ActionProcess
    HTTPAPIServer -->|"Calls"| TileModule
    HTTPAPIServer -->|"Calls"| TilesModule
    HTTPAPIServer -->|"Calls"| UserMgmt
    WSS -->|"RealTimeUpdates"| GameLogic
    UserMgmt -->|"DBOps"| DBMigrations
    DBMigrations -->|"Migrates"| PostgresDB
    DI -.-> HTTPAPIServer
    ErrorHandling -.-> HTTPAPIServer
    DI -.-> UserMgmt
    ErrorHandling -.-> UserMgmt
    Docker -.-> ClientFrontend
    Docker -.-> HTTPAPIServer
    Docker -.-> WSS

    click ClientFrontend "https://github.com/mrbogdan/monopoly/blob/main/client/src/map-playground.html"
    click GameLogic "https://github.com/mrbogdan/monopoly/tree/main/service/src/game"
    click ActionProcess "https://github.com/mrbogdan/monopoly/tree/main/service/src/action"
    click TileModule "https://github.com/mrbogdan/monopoly/tree/main/service/src/tile"
    click TilesModule "https://github.com/mrbogdan/monopoly/tree/main/service/src/tiles"
    click UserMgmt "https://github.com/mrbogdan/monopoly/tree/main/service/src/user"
    click HTTPAPIServer "https://github.com/mrbogdan/monopoly/tree/main/service/src/http"
    click WSS "https://github.com/mrbogdan/monopoly/tree/main/service/src/wss"
    click DI "https://github.com/mrbogdan/monopoly/tree/main/service/src/di"
    click ErrorHandling "https://github.com/mrbogdan/monopoly/tree/main/service/src/errors"
    click DBMigrations "https://github.com/mrbogdan/monopoly/blob/main/service/src/migrations/MNP-22/create-user-table.sql"
    click Docker "https://github.com/mrbogdan/monopoly/blob/main/docker-compose.yml"

    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef api fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef business fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef infra fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef db fill:#e2e3e5,stroke:#818182,stroke-dasharray:3,3,stroke-width:2px;
    classDef deploy fill:#fdfd96,stroke:#b4b400,stroke-width:2px;
```
