# driss292/poker-odds-calculator architecture

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

- Interactive diagram: https://gitdiagram.com/driss292/poker-odds-calculator
- Repository: https://github.com/driss292/poker-odds-calculator

## Overview

##### Main Components

- Frontend/UI Layer:
- This layer consists of all the React components under the “src/components” directory (e.g., Card, Deck, CardPlaceholder, Flop, River, Turn, Seat, IconDeck, ImageTable, ResetButton, StartAnalysis, Suit). These components together form the interactive poker table UI with drag and drop functionality.
- The index.html (in the root) serves as the entry point, along with the main.tsx in “src”, which bootstraps the React application.

- Drag and Drop Interaction:
- The application uses “Dnd Kit” to implement drag and drop. Mark this as a critical interaction layer that communicates between UI elements (cards, slots on the table) and internal state.

- Calculation/Business Logic Layer:
- This encapsulates the logic for computing odds, implemented in “src/utils/Calculator” (including modules like Card, CardGroup, Game, HandRank, OddsCalculator) as well as other calculation utilities in “src/utils”. These modules process the data based on the user’s card placements to deliver win probability estimates.

- Data/State Management and Supporting Utilities:
- Other utility modules (“src/utils/calculateOdds.ts”, “src/utils/data.ts”, etc.) handle helper functions, state modifications related to the drag and drop interactions, and the overall data flow.

- Configuration and Build:
- The project configuration files (e.g., package.json, vite.config.ts, tsconfig.json, etc.) support build processes and dependency management.

##### Relationships and Data Flow

- User Interface and Interaction:
- The user manipulates the UI on a virtual poker table via drag and drop; the interactive events are captured by the Dnd Kit integration.
- The UI components then relay these actions to the business logic layer.

- Business Logic Communication:
- When a card is dropped into a slot (for instance, in the CardSlot component), the action triggers the corresponding functions in the Calculator modules.
- These modules compute the odds based on the current state of the game (which cards are on the table, in the deck, etc.).

- Presentation of Results:
- The computed probabilities are then funneled back into the UI components, like StartAnalysis or the statistics display, updating the visual feedback.

- External Communication:
- Although the core functionality is computed within the client’s browser, the README mentions plans for a Chrome extension version which may require packaging or interfacing with browser APIs.

##### Architectural Patterns and Design Principles

- Separation of Concerns:
- Keep the UI (React components) distinct from the calculation logic (in the utils folder), ensuring modularity.

- Reusability and Componentization:
- The project's file structure indicates a strong emphasis on reuse with modular components (e.g., Card, Deck, IconDeck) and clear separation within the Calculator folder.

- Event-Driven Data Flow:

##### Technologies & External Libraries

- React & TypeScript:
- That the application uses React for the frontend coupled with TypeScript for type safety.

- Dnd Kit:
- Role of Dnd Kit as the library managing drag and drop interactions.

- CSS Modules:
- That styling is handled using Module CSS to maintain scope.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User Interaction
    User["User Interaction"]:::external

    %% Frontend/UI Layer
    subgraph "Frontend/UI Layer"
        Card["Card"]:::frontend
        Deck["Deck"]:::frontend
        CardPlaceholder["CardPlaceholder"]:::frontend
        Flop["Flop"]:::frontend
        River["River"]:::frontend
        Turn["Turn"]:::frontend
        Seat["Seat"]:::frontend
        IconDeck["IconDeck"]:::frontend
        ImageTable["ImageTable"]:::frontend
        ResetButton["ResetButton"]:::frontend
        StartAnalysis["StartAnalysis"]:::frontend
        Suit["Suit"]:::frontend
        MainApp["Main Bootstrapping"]:::frontend
        HTML["HTML Entry Point"]:::frontend
    end

    %% Drag & Drop Module
    subgraph "Drag & Drop Module"
        DragDrop["Dnd Kit Integration"]:::dragdrop
    end

    %% Calculation/Business Logic Layer
    subgraph "Calculation/Business Logic"
        CalcCard["Calculator: Card"]:::calculation
        CalcCardGroup["Calculator: CardGroup"]:::calculation
        CalcGame["Calculator: Game"]:::calculation
        CalcHandRank["Calculator: HandRank"]:::calculation
        CalcOddsCalculator["Calculator: OddsCalculator"]:::calculation
        CalculateOdds["calculateOdds Utility"]:::calculation
    end

    %% Data/State Management & Supporting Utilities
    subgraph "Data/State & Utilities"
        DataUtil["Data Utilities"]:::utilities
        FuncUtil["Other Utility Functions"]:::utilities
    end

    %% Configuration & Build
    subgraph "Configuration & Build"
        Package["package.json"]:::config
        Vite["vite.config.ts"]:::config
        TSConfig["tsconfig.json"]:::config
        TSApp["tsconfig.app.json"]:::config
        TSNode["tsconfig.node.json"]:::config
    end

    %% Connections - User Interaction to UI Components
    User -->|"triggers"| Card
    User -->|"triggers"| Deck
    User -->|"triggers"| CardPlaceholder

    %% UI to Drag & Drop
    Card ---|"drag event"| DragDrop
    Deck ---|"drag event"| DragDrop
    CardPlaceholder ---|"drag event"| DragDrop

    %% Drag & Drop initiates Calculation
    DragDrop -->|"initiates"| CalcCard
    DragDrop -->|"initiates"| CalcCardGroup
    DragDrop -->|"initiates"| CalcGame
    DragDrop -->|"initiates"| CalcHandRank
    DragDrop -->|"initiates"| CalcOddsCalculator

    %% Calculation Logic Flow
    CalcCard -->|"computes"| CalculateOdds
    CalcCardGroup -->|"computes"| CalculateOdds
    CalcGame -->|"computes"| CalculateOdds
    CalcHandRank -->|"computes"| CalculateOdds
    CalculateOdds -->|"updates state"| DataUtil

    %% Supporting Utilities Feedback to UI
    DataUtil -->|"supports"| StartAnalysis
    FuncUtil -->|"triggers update"| ResetButton
    CalcOddsCalculator -->|"returns odds"| StartAnalysis

    %% Click Events for Frontend/UI Layer
    click Card "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/Card/Card.tsx"
    click Deck "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/Deck/Deck.tsx"
    click CardPlaceholder "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/CardPlaceholder/CardPlaceholder.tsx"
    click Flop "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/Flop/Flop.tsx"
    click River "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/River/River.tsx"
    click Turn "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/Turn/Turn.tsx"
    click Seat "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/Seat/Seat.tsx"
    click IconDeck "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/IconDeck/IconDeck.tsx"
    click ImageTable "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/ImageTable/ImageTable.tsx"
    click ResetButton "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/ResetButton/ResetButton.tsx"
    click StartAnalysis "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/StartAnalysis/StartAnalysis.tsx"
    click Suit "https://github.com/driss292/poker-odds-calculator/blob/main/src/components/Suit/Suit.tsx"
    click MainApp "https://github.com/driss292/poker-odds-calculator/blob/main/src/main.tsx"
    click HTML "https://github.com/driss292/poker-odds-calculator/blob/main/index.html"

    %% Click Events for Drag & Drop Interaction
    click DragDrop "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/drop.ts"

    %% Click Events for Calculation/Business Logic Layer
    click CalcCard "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/Calculator/Card.ts"
    click CalcCardGroup "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/Calculator/CardGroup.ts"
    click CalcGame "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/Calculator/Game.ts"
    click CalcHandRank "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/Calculator/HandRank.ts"
    click CalcOddsCalculator "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/Calculator/OddsCalculator.ts"
    click CalculateOdds "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/calculateOdds.ts"

    %% Click Events for Data/State & Utilities
    click DataUtil "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/data.ts"
    click FuncUtil "https://github.com/driss292/poker-odds-calculator/blob/main/src/utils/functions.ts"

    %% Click Events for Configuration & Build
    click Package "https://github.com/driss292/poker-odds-calculator/blob/main/package.json"
    click Vite "https://github.com/driss292/poker-odds-calculator/blob/main/vite.config.ts"
    click TSConfig "https://github.com/driss292/poker-odds-calculator/blob/main/tsconfig.json"
    click TSApp "https://github.com/driss292/poker-odds-calculator/blob/main/tsconfig.app.json"
    click TSNode "https://github.com/driss292/poker-odds-calculator/blob/main/tsconfig.node.json"

    %% Styles
    classDef frontend fill:#d0eaff,stroke:#003366,stroke-width:2px;
    classDef dragdrop fill:#ffe0b3,stroke:#cc6600,stroke-width:2px;
    classDef calculation fill:#d1ffd6,stroke:#006633,stroke-width:2px;
    classDef utilities fill:#e6ccff,stroke:#003366,stroke-width:2px;
    classDef config fill:#ffd6d6,stroke:#cc0000,stroke-width:2px;
    classDef external fill:#f2f2f2,stroke:#999999,stroke-width:2px,stroke-dasharray:5,5;
```
