# leojoker/lanusstats architecture

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

- Interactive diagram: https://gitdiagram.com/leojoker/lanusstats
- Repository: https://github.com/leojoker/lanusstats

## Overview

##### Project Type & Purpose
- LanusStats is an open-source Python library/SDK for scraping soccer statistics from multiple external websites (FBref, FotMob, SofaScore, 365Scores, Transfermarkt) and generating ready-to-use visualizations.

##### High-Level Components
- FBref
- FotMob
- SofaScore
- 365Scores
- Transfermarkt

1. config.py
- Stores constants, URL templates, headers, default parameters
2. exceptions.py
- Defines custom exception classes for error handling
3. functions.py
- Shared utility functions: HTTP request wrappers, HTML parsing helpers, DataFrame cleaning
4. datafactory.py
- Implements the Factory Pattern: dispatches user calls to the correct scraper class based on the chosen “page”
5. Scraper Modules (one class per file)
- fbref.py → class Fbref
- fotmob.py → class FotMob
- sofascore.py → class SofaScore
- threesixfivescores.py → class ThreeSixFiveScores
- transfermarkt.py → class Transfermarkt
6. visualizations.py
- Prebuilt plotting functions that invoke scraper methods, then render via Matplotlib/MPLSoccer
7. setup.py
- Installation metadata and entry point definitions

C. CI/CD Pipeline
- .github/workflows/publish-package.yml
- Trigger: Git tag push → build/test → publish to PyPI

##### Relationships & Data Flow
1. User Script / Notebook
→ Instantiates one of the LanusStats classes or calls a generic factory function
2. datafactory.py (if used)
→ Returns an instance of the appropriate scraper class
3. Scraper Class (e.g., Fbref)
→ Calls functions.py utilities to build and send HTTP requests to its external website
→ Parses HTML/JSON response, handles errors via exceptions.py
→ Constructs and returns a pandas DataFrame (or saves CSV/Excel if flagged)
4. visualizations.py (when invoked)
→ Calls scraper methods under the hood
→ Takes returned DataFrame and generates plots (heatmaps, shotmaps, hexbins, etc.)
5. CI/CD
→ On tag push, GitHub Actions runs tests, builds package, and publishes to PyPI

##### Architectural Patterns & Principles
- Factory Pattern: datafactory.py dynamically selects the right scraper class
- Single Responsibility:
- Each scraper module focuses on one data source
- Shared logic centralized in functions.py, config.py, exceptions.py
- Visualization logic isolated in visualizations.py
- Extensibility: To add a new site, you add a scraper module + register it in datafactory.py
- Loose Coupling: User code and visualization code depend only on the public scraper interfaces

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User Script / Notebook"]:::user

    subgraph "LanusStats SDK"
        config["config.py"]:::internal
        exceptions["exceptions.py"]:::internal
        functions["functions.py"]:::internal
        datafactory["datafactory.py"]:::internal
        subgraph "Scraper Modules"
            fbref["Fbref Scraper"]:::internal
            fotmob["FotMob Scraper"]:::internal
            sofascore["SofaScore Scraper"]:::internal
            scores365["ThreeSixFiveScores Scraper"]:::internal
            transfermarkt["Transfermarkt Scraper"]:::internal
        end
        visualizations["visualizations.py"]:::internal
        setup["setup.py"]:::internal
    end

    subgraph "External Data Sources"
        fbref_ext["FBref"]:::external
        fotmob_ext["FotMob"]:::external
        sofascore_ext["SofaScore"]:::external
        scores365_ext["365Scores"]:::external
        transfermarkt_ext["Transfermarkt"]:::external
    end

    df_out["DataFrame / CSV / Excel"]:::data
    plot_out["Plot Output"]:::data

    cicd["GitHub Actions"]:::cicd
    pypi["PyPI"]:::external

    %% Flow
    User -->|"instantiate or call factory"| datafactory
    datafactory -->|"dispatch to scraper"| fbref
    datafactory -->|"dispatch to scraper"| fotmob
    datafactory -->|"dispatch to scraper"| sofascore
    datafactory -->|"dispatch to scraper"| scores365
    datafactory -->|"dispatch to scraper"| transfermarkt

    fbref -->|"use utilities"| functions
    fotmob -->|"use utilities"| functions
    sofascore -->|"use utilities"| functions
    scores365 -->|"use utilities"| functions
    transfermarkt -->|"use utilities"| functions

    functions -->|"send HTTP request"| fbref_ext
    functions -->|"send HTTP request"| fotmob_ext
    functions -->|"send HTTP request"| sofascore_ext
    functions -->|"send HTTP request"| scores365_ext
    functions -->|"send HTTP request"| transfermarkt_ext

    fbref_ext -->|"response"| functions
    fotmob_ext -->|"response"| functions
    sofascore_ext -->|"response"| functions
    scores365_ext -->|"response"| functions
    transfermarkt_ext -->|"response"| functions

    fbref -->|"return DataFrame"| df_out
    fotmob -->|"return DataFrame"| df_out
    sofascore -->|"return DataFrame"| df_out
    scores365 -->|"return DataFrame"| df_out
    transfermarkt -->|"return DataFrame"| df_out

    User -->|"call visualizations"| visualizations
    df_out -->|"input for plots"| visualizations
    visualizations -->|"generate plots"| plot_out

    cicd -->|"on tag push build/test"| setup
    cicd -->|"publish package"| pypi

    %% Click Events
    click fbref "https://github.com/leojoker/lanusstats/blob/main/LanusStats/fbref.py"
    click fotmob "https://github.com/leojoker/lanusstats/blob/main/LanusStats/fotmob.py"
    click sofascore "https://github.com/leojoker/lanusstats/blob/main/LanusStats/sofascore.py"
    click scores365 "https://github.com/leojoker/lanusstats/blob/main/LanusStats/threesixfivescores.py"
    click transfermarkt "https://github.com/leojoker/lanusstats/blob/main/LanusStats/transfermarkt.py"
    click config "https://github.com/leojoker/lanusstats/blob/main/LanusStats/config.py"
    click exceptions "https://github.com/leojoker/lanusstats/blob/main/LanusStats/exceptions.py"
    click functions "https://github.com/leojoker/lanusstats/blob/main/LanusStats/functions.py"
    click datafactory "https://github.com/leojoker/lanusstats/blob/main/LanusStats/datafactory.py"
    click visualizations "https://github.com/leojoker/lanusstats/blob/main/LanusStats/visualizations.py"
    click setup "https://github.com/leojoker/lanusstats/blob/main/setup.py"
    click cicd "https://github.com/leojoker/lanusstats/blob/main/.github/workflows/publish-package.yml"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#004085
    classDef external fill:#d4edda,stroke:#155724
    classDef cicd fill:#ffe5b4,stroke:#b35f00
    classDef user fill:#e2e3e5,stroke:#6c757d
    classDef data fill:#e2e3e5,stroke:#6c757d
```
