# kavithranch/ranchedge architecture

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

- Interactive diagram: https://gitdiagram.com/kavithranch/ranchedge
- Repository: https://github.com/kavithranch/ranchedge

## Overview

##### Main System Components

a) Frontend Layer:
- Flask templates structure
- Hierarchy of base templates and specific sports pages
- Static assets management

b) Backend Layer:
- Flask application core
- Routes handling
- Model definitions
- Database interactions

c) Data Layer:
- Database storage
- API integration points
- Data fill scripts

**┌─ Frontend Layer ─────────────┐      ┌─ External Services ─┐**
- ┌─ Templates ──────────────┐ │      │                     │
- base.html            │ │      │  Sports APIs         │
- base_stats.html      │ │      │  Betting APIs        │
- Sport-specific pages │ │      │                     │
- ┘ │      └─────────────────────┘
- ▲
- ┬───────────────┘              │

- ▼                               │
**┌─ Backend Layer ──────────────┐             │**
- ┌─ Flask Application ───────┐│             │
- Routes                 ││             │
- Models                 ││◄────────────┘
- Business Logic        ││
- ┘│
- ┬───────────────┘

- ▼
**┌─ Data Layer ───────────────┐**
- ┌─ Database ─────────────┐ │
- Teams               │ │
- Stats              │ │
- Betting Data       │ │
- ┘│
- ┌─ Data Scripts ─────────┐ │
- Fill Scripts        │ │
- Update Scripts      │ │
- ┘│
- ┘

##### Important Architectural Aspects to Highlight

a) Data Flow:
- How data moves from external APIs through the backend
- How the fill scripts populate the database
- Demonstrate the flow from database to frontend views

b) Component Separation:
- Clear distinction between frontend templates and backend logic
- Separate data management layer
- External service integration points

##### Notes for Implementation
- Keep the database schema separate but referenced
- Version information (currently moving toward 1.3.0)
- Planned features (like NFL and NHL expansion)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Legend"
        L1[Frontend Component]:::frontend
        L2[Backend Component]:::backend
        L3[Data Component]:::data
        L4[External Service]:::external
        L5[("Database")]:::database
    end

    subgraph "Frontend Layer"
        FE[Frontend Entry]:::frontend
        click FE "https://github.com/KavithRanch/RanchEdge/tree/main/frontend"
        
        subgraph "Templates"
            BT["Base Template"]:::frontend
            click BT "https://github.com/KavithRanch/RanchEdge/blob/main/frontend/templates/base.html"
            BST["Base Stats Template"]:::frontend
            click BST "https://github.com/KavithRanch/RanchEdge/blob/main/frontend/templates/base_stats.html"
            NBAT["NBA Stats Page"]:::frontend
            click NBAT "https://github.com/KavithRanch/RanchEdge/blob/main/frontend/templates/nba_stats.html"
            NFLT["NFL Stats Page"]:::frontend
            click NFLT "https://github.com/KavithRanch/RanchEdge/blob/main/frontend/templates/nfl_stats.html"
        end

        SA["Static Assets"]:::frontend
        click SA "https://github.com/KavithRanch/RanchEdge/tree/main/frontend/static"

        BT --> BST
        BST --> NBAT
        BST --> NFLT
    end

    subgraph "Backend Layer"
        APP["Flask Application Core"]:::backend
        click APP "https://github.com/KavithRanch/RanchEdge/blob/main/backend/__init__.py"
        RH["Routes Handler"]:::backend
        click RH "https://github.com/KavithRanch/RanchEdge/blob/main/backend/routes.py"
        DM["Data Models"]:::backend
        click DM "https://github.com/KavithRanch/RanchEdge/blob/main/backend/models.py"
        APIT["API Tester"]:::backend
        click APIT "https://github.com/KavithRanch/RanchEdge/blob/main/APITester.py"
    end

    subgraph "Data Layer"
        DB[("Database")]:::database
        FS["Fill Scripts"]:::data
        click FS "https://github.com/KavithRanch/RanchEdge/blob/main/data/fillscripts.py"
        US["Update Scripts"]:::data
    end

    subgraph "External Services"
        SA1["Sports APIs"]:::external
        BA["Betting APIs"]:::external
    end

    MAIN["Application Entry"]:::backend
    click MAIN "https://github.com/KavithRanch/RanchEdge/blob/main/run.py"

    %% Connections
    MAIN --> APP
    APP --> RH
    RH --> DM
    DM --> DB
    FS --> DB
    US --> DB
    SA1 --> APIT
    BA --> APIT
    APIT --> APP
    APP --> FE
    FE --> BT

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
```
