# bhdj0107/ldjmafia architecture

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

- Interactive diagram: https://gitdiagram.com/bhdj0107/ldjmafia
- Repository: https://github.com/bhdj0107/ldjmafia

## Overview

##### Project type and purpose
- This is a two-tier client-server game application (“Mafia Game”) written in Python.
- It uses SSL/TLS-wrapped sockets for secure communication.
- The client tier has a Qt-based GUI (login, lobby, room, game screens), and the server tier handles authentication, game logic, state management, and persistence.

##### File structure
- Top-level (Server side):
– main.py     → server entrypoint, socket listener
– socketHandler.py → low-level SSL/TLS socket accept/send/recv
– mafiaProtocol.py → message framing & parsing rules
– mafiaRequest.py / mafiaResponse.py → request/response DTO definitions
– mafiaManagers.py → game logic, user/login state, role assignments
– id2nicknametable, logintable → simple flat files for user-ID to nickname & credentials
– samplecode/   → proof-of-concept SSL vs non-SSL socket tests
– requirements.txt → Python dependencies
- ClientSide/ (Client tier):
– main.py     → client entrypoint, Qt application bootstrap
– main.spec    → PyInstaller spec for building a standalone client
– *.ui       → Qt Designer forms for loginForm, lobbyForm, roomForm
– mafiaProtocol.py, mafiaRequest.py, mafiaResponse.py → mirrored DTO & framing logic
– mafiaUi.py    → glue between UI forms and application logic
– socketHandler.py → SSL/TLS socket wrapper for client
– roomTest.py, test.py, test2.py → unit/integration tests for client modules
– images/     → embedded assets used in the UI

##### README for additional insights
- The README is a slide deck of 31 pages showing the SSL/TLS handshake, message flows, client & server component interactions, and screen-by-screen UI flows.
- It confirms the layered breakdown: UI layer, application/request-response layer, network layer with SSL, and server-side game engine & persistence.

##### Detail
– Show the repro-usable protocol modules as a shared “contract” between tiers
– Capture how state flows through managers and back to the UI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Zone
    subgraph "Client Tier"
        direction TB
        subgraph "UI Layer"
            direction TB
            LF["LoginForm"]:::ui
            LOF["LobbyForm"]:::ui
            RF["RoomForm"]:::ui
        end
        subgraph "App Layer"
            direction TB
            MUI["mafiaUi.py"]:::logic
            CRQ["mafiaRequest.py"]:::dto
            CRP["mafiaResponse.py"]:::dto
            CEP["main.py"]:::entry
            CSP["main.spec"]:::packaging
        end
        subgraph "Network Layer"
            direction TB
            CPP["mafiaProtocol.py"]:::protocol
            CSK["socketHandler.py"]:::network
        end
        subgraph "Assets & Tests"
            direction TB
            CA["images/"]:::assets
            CT1["roomTest.py"]:::test
            CT2["test.py"]:::test
            CT3["test2.py"]:::test
        end
    end

    %% Secure Channel
    SSL["SSL/TLS Channel"]:::secure

    %% Server Zone
    subgraph "Server Tier"
        direction TB
        subgraph "Network Layer"
            direction TB
            SSK["socketHandler.py"]:::network
            SPP["mafiaProtocol.py"]:::protocol
        end
        subgraph "App/Game Layer"
            direction TB
            SRQ["mafiaRequest.py"]:::dto
            SRP["mafiaResponse.py"]:::dto
            SMGR["mafiaManagers.py"]:::logic
        end
        subgraph "Persistence Layer"
            direction TB
            LT["logintable"]:::storage
            ID["id2nicknametable"]:::storage
        end
        subgraph "External/Test Code"
            direction TB
            EX1["nonsslSocktest.py"]:::external
            EX2["sslSocktest.py"]:::external
        end
        REQ["requirements.txt"]:::config
        SL["README.md"]:::config
    end

    %% Client Flow
    LF -->|UI event| MUI
    LOF -->|UI event| MUI
    RF -->|UI event| MUI
    MUI -->|"build Request"| CRQ
    CRQ -->|"serialize"| CPP
    CPP -->|"to SSL socket"| CSK
    CSK -->|"encrypt/send"| SSL

    %% Server Flow
    SSL -->|"decrypt/recv"| SSK
    SSK -->|"raw bytes"| SPP
    SPP -->|"parse Request"| SRQ
    SRQ -->|"process"| SMGR
    SMGR -->|"read/write"| LT
    SMGR -->|"read/write"| ID
    SMGR -->|"produce Response"| SRP
    SRP -->|"serialize"| SPP
    SPP -->|"to socket"| SSK
    SSK -->|"encrypt/send"| SSL

    %% Response Back to Client
    SSL -->|"decrypt/recv"| CSK
    CSK -->|"raw bytes"| CPP
    CPP -->|"parse Response"| CRP
    CRP -->|"deliver to"| MUI
    MUI -->|update UI| LF
    MUI -->|update UI| LOF
    MUI -->|update UI| RF

    %% Click Events
    click LF "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/loginForm.ui"
    click LOF "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/lobbyForm.ui"
    click RF "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/roomForm.ui"
    click MUI "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/mafiaUi.py"
    click CRQ "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/mafiaRequest.py"
    click CRP "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/mafiaResponse.py"
    click CEP "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/main.py"
    click CSP "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/main.spec"
    click CPP "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/mafiaProtocol.py"
    click CSK "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/socketHandler.py"
    click CA "https://github.com/bhdj0107/ldjmafia/tree/master/ClientSide/images/"
    click CT1 "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/roomTest.py"
    click CT2 "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/test.py"
    click CT3 "https://github.com/bhdj0107/ldjmafia/blob/master/ClientSide/test2.py"
    click SSK "https://github.com/bhdj0107/ldjmafia/blob/master/socketHandler.py"
    click SPP "https://github.com/bhdj0107/ldjmafia/blob/master/mafiaProtocol.py"
    click SRQ "https://github.com/bhdj0107/ldjmafia/blob/master/mafiaRequest.py"
    click SRP "https://github.com/bhdj0107/ldjmafia/blob/master/mafiaResponse.py"
    click SMGR "https://github.com/bhdj0107/ldjmafia/blob/master/mafiaManagers.py"
    click LT "https://github.com/bhdj0107/ldjmafia/tree/master/logintable"
    click ID "https://github.com/bhdj0107/ldjmafia/tree/master/id2nicknametable"
    click EX1 "https://github.com/bhdj0107/ldjmafia/blob/master/samplecode/nonsslSocktest.py"
    click EX2 "https://github.com/bhdj0107/ldjmafia/blob/master/samplecode/sslSocktest.py"
    click REQ "https://github.com/bhdj0107/ldjmafia/blob/master/requirements.txt"
    click SL "https://github.com/bhdj0107/ldjmafia/blob/master/README.md"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef dto fill:#E0FFFF,stroke:#333,stroke-width:1px
    classDef entry fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef packaging fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef network fill:#FFA07A,stroke:#333,stroke-width:1px
    classDef protocol fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef assets fill:#FFEFD5,stroke:#333,stroke-width:1px
    classDef test fill:#FFC0CB,stroke:#333,stroke-width:1px
    classDef secure fill:#B0C4DE,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#F0E68C,stroke:#333,stroke-width:1px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:1px
```
