# lolligerhans/cocaco architecture

> Architecture diagram of the GitHub repository lolligerhans/cocaco, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lolligerhans/cocaco
- Repository: https://github.com/lolligerhans/cocaco

## Overview

##### Main Components

a. Browser Extension Components:
- Background Script Layer (represented by background-page.html and background.js)
- Content Scripts Layer (main extension logic)
- WebSocket Communication Layer (socket_main.js, socket_isolated.js)

b. Core Functional Modules:
- Game State Tracking System (state.js, player.js)
- Card Tracking System (cocaco.js, trade.js)
- Analysis Engines:
- Dice Roll Analysis
- Resource Tracking
- Rob Tracking
- Data Visualization Layer (plot.js, render.js)

c. External Dependencies:
- Plotly (for visualization)
- statistics.js (for statistical calculations)
- msgpack.js (for data serialization)

##### Relationship Flows to Highlight

- Data flow from Colonist.io game → WebSocket Layer → State Management
- State Updates → Analysis Engines → Visualization Layer
- User Interactions → State Management → Data Updates

##### Specific Implementation Details

- Blue rectangles: Core extension components
- Green diamonds: Analysis modules
- Yellow hexagons: External dependencies
- Purple circles: Data storage/state management
- Red rectangles: Communication layers

##### Architecture Patterns to Emphasize

- Observer Pattern (evident from observer.js)
- Pipeline Architecture (referenced in doc/pipelines.md)
- Event-driven Architecture (for game state tracking)
- Modular Component Structure (shown in the javascript/ directory)

##### Key Interactions

- Bidirectional communication between the extension and Colonist.io
- Data flow through the analysis pipeline
- State updates and their propagation
- User interaction flows

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        subgraph Extension
            BG[Background Script]
            CS[Content Scripts]
            WS[WebSocket Layer]
            
            subgraph Core["Core Modules"]
                GST[Game State Tracking]
                CTS[Card Tracking System]
                
                subgraph Analysis["Analysis Engines"]
                    DRA[Dice Roll Analysis]
                    RT[Resource Tracking]
                    ROB[Rob Tracking]
                end
                
                subgraph Visualization
                    DVL[Data Visualization]
                    PLOT[Plotting System]
                end
            end
            
            subgraph Dependencies
                PLT[Plotly]
                STATS[Statistics]
                MSG[MsgPack]
            end
        end
        
        GAME[Colonist.io Game]
    end
    
    %% Relationships
    GAME <--> WS
    WS --> GST
    GST --> Analysis
    Analysis --> Visualization
    CTS --> Analysis
    DVL --> PLOT
    PLOT --> PLT
    
    %% Component Interactions
    GST <--> CTS
    CS --> WS
    BG --> CS
    
    %% Click Events
    click BG "https://github.com/Lolligerhans/cocaco/blob/master/html/background-page.html"
    click WS "https://github.com/Lolligerhans/cocaco/blob/master/javascript/socket_main.js"
    click GST "https://github.com/Lolligerhans/cocaco/blob/master/javascript/state.js"
    click CTS "https://github.com/Lolligerhans/cocaco/blob/master/javascript/cocaco.js"
    click DVL "https://github.com/Lolligerhans/cocaco/blob/master/javascript/render.js"
    click PLOT "https://github.com/Lolligerhans/cocaco/blob/master/javascript/plot.js"
    click MSG "https://github.com/Lolligerhans/cocaco/blob/master/dependencies/msgpack.js"
    click STATS "https://github.com/Lolligerhans/cocaco/blob/master/dependencies/statistics.js"
    
    %% Styling
    classDef default fill:#ddd,stroke:#000,stroke-width:1px
    classDef core fill:#a8d5ff,stroke:#000
    classDef analysis fill:#90EE90,stroke:#000
    classDef viz fill:#FFB6C1,stroke:#000
    classDef deps fill:#FFE4B5,stroke:#000
    classDef comm fill:#FF6B6B,stroke:#000
    
    class BG,CS core
    class WS comm
    class GST,CTS core
    class DRA,RT,ROB analysis
    class DVL,PLOT viz
    class PLT,STATS,MSG deps
    
    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Analysis Modules]:::analysis
        L3[Visualization]:::viz
        L4[Dependencies]:::deps
        L5[Communication]:::comm
    end
```
