# shunaaaaabbbbb/nba_analysis architecture

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

- Interactive diagram: https://gitdiagram.com/shunaaaaabbbbb/nba_analysis
- Repository: https://github.com/shunaaaaabbbbb/nba_analysis

## Overview

##### Project Type and Purpose
- This is a full‐stack, single‐page web application built with Streamlit.
- Purpose: Let users select an NBA game or player and render shot charts and comparative statistics by fetching data from the official NBA API.

##### File Structure
- Entry point: main.py – launches the Streamlit server and handles page routing.
- analysis_pages/ – modules that implement individual analysis screens (shot charts, player comparison, stats).
- nba_api_utils/ – data‐access layer wrapping NBA API endpoints (game, player, team, seasons, shot charts, etc.).
- utils/ – shared helper functions: constants, UI helpers, generic visualizations, business‐logic helpers.
- nba_stats_app/ – package folder (empty __init__.py) for distributing or namespacing the app.
- tests/ – unit tests for core logic.
- notebook/ – exploratory Jupyter notebook used during development.
- pyproject.toml – project metadata and dependency declarations.

##### Key Architecture Insights from README
- The app is deployed on Streamlit Cloud (URL given).
- Users interact via a sidebar to choose analysis type and parameters (player name, date, etc.).
- Outputs are visual: shot chart overlays, bar charts, tables.

##### Main Components
A. Client Layer
– Web Browser / Streamlit Frontend UI
B. Application Layer
1. Streamlit Server (main.py)
2. Analysis Pages (analysis_pages/*.py)
- nba_shotchart.py, player_comparison.py, show_stats.py
3. Utility Modules (utils/*.py)
- constants.py, helpers.py, ui_helpers.py, visualizations.py
C. Data Access Layer
– NBA API Utilities (nba_api_utils/*.py)
- game.py, player.py, team.py, seasons.py, shot_chart.py, input_data.py, button.py
D. External Services
– Official NBA REST API (external HTTP endpoints)
E. Supporting Components (non‐runtime)
– Tests (tests/)
– Development Notebook (notebook/)

##### Relationships and Data Flows
- Browser → Streamlit Server: user input, page navigation.
- Streamlit Server → Analysis Pages: invokes the correct page module based on user selection.
- Analysis Pages → Utils: calls helper functions for data transformation and chart creation.
- Analysis Pages → NBA API Utils: requests raw data (games, shot locations, stats).
- NBA API Utils → External NBA API: HTTP calls to fetch JSON data.
- Data flows back up: External NBA API → NBA API Utils → Analysis Pages → Streamlit UI → Browser.

##### Architectural Patterns and Principles
- Layered Architecture (Presentation → Business Logic → Data Access).
- Separation of Concerns:
– analysis_pages handles page‐specific logic,
– utils holds cross‐cutting helpers,
– nba_api_utils isolates all external API calls.
- Modular Design: each functional area lives in its own directory.
- Testability: core logic is covered by unit tests in tests/.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    Browser["Web Browser / Streamlit UI"]:::presentation
    Streamlit["Streamlit Server\n(main.py)"]:::presentation
    Browser -->|"user input / navigation"| Streamlit
    click Streamlit "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/main.py"

    %% Business Logic Layer: Analysis Pages
    subgraph "Analysis Pages" 
        direction TB
        ShotChart["nba_shotchart.py"]:::presentation
        PlayerComparison["player_comparison.py"]:::presentation
        ShowStats["show_stats.py"]:::presentation
    end
    Streamlit -->|"routes to module"| ShotChart
    Streamlit -->|"routes to module"| PlayerComparison
    Streamlit -->|"routes to module"| ShowStats
    click ShotChart "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/analysis_pages/nba_shotchart.py"
    click PlayerComparison "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/analysis_pages/player_comparison.py"
    click ShowStats "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/analysis_pages/show_stats.py"

    %% Business Logic Layer: Utility Modules
    subgraph "Utils" 
        direction TB
        Constants["constants.py"]:::logic
        Helpers["helpers.py"]:::logic
        UIHelpers["ui_helpers.py"]:::logic
        Visualizations["visualizations.py"]:::logic
    end
    ShotChart -->|"calls helpers"| Constants
    ShotChart -->|"calls helpers"| Helpers
    ShotChart -->|"calls ui & viz"| UIHelpers
    ShotChart -->|"calls viz"| Visualizations
    PlayerComparison -->|"calls helpers"| Helpers
    PlayerComparison -->|"calls ui & viz"| UIHelpers
    PlayerComparison -->|"calls viz"| Visualizations
    ShowStats -->|"calls helpers"| Helpers
    ShowStats -->|"calls ui & viz"| UIHelpers
    ShowStats -->|"calls viz"| Visualizations
    click Constants "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/utils/constants.py"
    click Helpers "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/utils/helpers.py"
    click UIHelpers "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/utils/ui_helpers.py"
    click Visualizations "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/utils/visualizations.py"

    %% Data Access Layer: NBA API Utils
    subgraph "NBA API Utils" 
        direction TB
        Game["game.py"]:::data
        Player["player.py"]:::data
        Team["team.py"]:::data
        Seasons["seasons.py"]:::data
        ShotChartUtil["shot_chart.py"]:::data
        InputData["input_data.py"]:::data
        ButtonUtil["button.py"]:::data
    end
    ShotChart -->|"fetch data"| ShotChartUtil
    PlayerComparison -->|"fetch data"| Player
    ShowStats -->|"fetch data"| Game
    ShotChart -->|"fetch UI wrappers"| InputData
    ShotChart -->|"button controls"| ButtonUtil
    click Game "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/nba_api_utils/game.py"
    click Player "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/nba_api_utils/player.py"
    click Team "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/nba_api_utils/team.py"
    click Seasons "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/nba_api_utils/seasons.py"
    click ShotChartUtil "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/nba_api_utils/shot_chart.py"
    click InputData "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/nba_api_utils/input_data.py"
    click ButtonUtil "https://github.com/shunaaaaabbbbb/nba_analysis/blob/main/nba_api_utils/button.py"

    NBA_API["External NBA REST API"]:::external
    ShotChartUtil -->|"HTTP request"| NBA_API
    Player -->|"HTTP request"| NBA_API
    Team -->|"HTTP request"| NBA_API
    Seasons -->|"HTTP request"| NBA_API
    Game -->|"HTTP request"| NBA_API

    %% Supporting Components (non-runtime)
    subgraph "Supporting Components" 
        direction TB
        Tests["tests/"]:::support
        Notebook["notebook/nba_api.ipynb"]:::support
        Packaging["nba_stats_app/__init__.py"]:::support
        Metadata["pyproject.toml\nREADME.md"]:::support
    end

    classDef presentation fill:#D0E7FF,stroke:#0366D6,color:#0366D6;
    classDef logic fill:#E6FFEA,stroke:#1C7C54,color:#1C7C54;
    classDef data fill:#FFEFE6,stroke:#C43015,color:#C43015;
    classDef external fill:#F3F4F6,stroke:#6A737D,color:#6A737D,stroke-dasharray: 5 5;
    classDef support fill:#F9F0FF,stroke:#6F42C1,color:#6F42C1,stroke-dasharray: 2 2;
```
