# g33kd4ddy/blackjack architecture

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

- Interactive diagram: https://gitdiagram.com/g33kd4ddy/blackjack
- Repository: https://github.com/g33kd4ddy/blackjack

## Overview

##### Project type and purpose
- This is a small, command‐line Python application that implements a single‐deck, one‐player vs. dealer game of blackjack.
- There are no external services, databases, or separate frontend/back-end tiers—everything lives in one Python script (blackjack.py).

##### File structure
- Top level:
- README.md – project description and usage.
- blackjack.py – the entire game logic and CLI lives here.
- No additional directories or configuration files exist, which tells us the code is organized as one module.

##### README for additional insights
- It confirms “command line based,” “single deck,” one player vs. the house.
- No mention of external dependencies or extension points.

##### Main components
a. CLI (Command‐Line Interface)
- Responsible for reading user input (hit, stay, etc.) and printing results.
b. Game Controller / Engine
- Orchestrates overall game flow: deal cards, resolve bets, apply blackjack rules.
c. Deck Manager
d. Player Entity
- Tracks player’s hand, calculates hand value, decides actions based on input.
e. Dealer Entity
- Tracks dealer’s hand and automated decision logic (e.g., hit until 17+).
f. Card and Hand abstractions
- Card: suit & rank data structure.
- Hand: collection of cards plus value‐calculation method.

##### Relationships and interactions
- CLI → Game Controller: user inputs (“hit”, “stand”) flow into the controller.
- Game Controller → Player/Dealer: deal initial hands and subsequent draws.
- Player/Dealer → Hand: add drawn cards; Hand → Game Controller: report hand value.
- Game Controller → CLI: print updated game state after each interaction.

##### Architectural patterns and design principles
- Single‐module, procedural‐plus‐object design.
- Separation of concerns: keep game logic (Game Controller) distinct from I/O (CLI) and card abstractions.
- Entities encapsulate state and behavior (Player, Dealer, Deck).

##### Detail without overthinking
- Even though it’s one file, break it into these logical parts.
- The level of detail should let a new engineer immediately understand where each responsibility lives, even in a single‐script codebase.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "I/O"
        CLI["CLI Input/Output"]:::io
    end

    subgraph "Core Logic"
        GC["Game Controller"]:::core
        DM["Deck Manager"]:::core
    end

    subgraph "Entities"
        subgraph "Participants"
            P["Player"]:::entity
            D["Dealer"]:::entity
        end
        subgraph "Abstractions"
            C["Card"]:::entity
            H["Hand"]:::entity
        end
    end

    CLI -->|"user commands"| GC
    GC -->|"shuffle/draw"| DM
    DM -->|"cards"| GC
    GC -->|"deal/draw"| P
    GC -->|"deal/draw"| D
    P -->|"addCard()"| H
    D -->|"addCard()"| H
    H -->|"value()"| GC
    GC -->|"display state"| CLI

    click CLI "https://github.com/g33kd4ddy/blackjack/blob/main/blackjack.py"
    click GC "https://github.com/g33kd4ddy/blackjack/blob/main/blackjack.py"
    click DM "https://github.com/g33kd4ddy/blackjack/blob/main/blackjack.py"
    click P "https://github.com/g33kd4ddy/blackjack/blob/main/blackjack.py"
    click D "https://github.com/g33kd4ddy/blackjack/blob/main/blackjack.py"
    click C "https://github.com/g33kd4ddy/blackjack/blob/main/blackjack.py"
    click H "https://github.com/g33kd4ddy/blackjack/blob/main/blackjack.py"

    classDef io fill:#D0E6F5,stroke:#003F5C,stroke-width:2px
    classDef core fill:#D0F5D0,stroke:#2F8F2F,stroke-width:2px
    classDef entity fill:#F5E6D0,stroke:#A66310,stroke-width:2px
```
