# alihaidar2/fantasyplstats architecture

> Architecture diagram of the GitHub repository alihaidar2/fantasyplstats, 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/alihaidar2/fantasyplstats
- Repository: https://github.com/alihaidar2/fantasyplstats

## Overview

- Frontend Client:
- Next.js Pages and Layouts (e.g., app/page.tsx, app/differential/page.tsx, app/fixtures/page.tsx, app/layout.tsx)
- UI Components (all components/ subdirectories: header, footer, differential_table, gameweek_table, manager_panel, manager_team_table, etc.)
- Global Styles & Assets (styles/ and public/ directories)
- Backend / API:
- API Routes under app/api/ (such as fixtures, manager endpoints for dynamic route parameters like [managerId], and search functionalities)
- Server-side logic managed by Next.js for handling requests and rendering responses
- Libraries & Utilities:
- Helper functions and clients (lib/cosmosClient.ts, lib/tableUtils.ts)
- Type definitions (types/ directory)
- Scripts & Deployment Infrastructure:
- Database population and update scripts (scripts/populateDatabase.js, scripts/updateManagers.js)
- CI/CD configuration (GitHub workflows in .github/workflows/)
- Docker configuration (DockerFile) suggesting containerization
- External Services:
- Although not explicitly detailed, the existence of a Cosmos client indicates an external database service.
- Deployment platforms such as Vercel (as referenced in the README) or Azure (from the workflow file) may act as the hosting environment.

##### Relationships and Interactions
- Flow from API routes to the libraries that interact with external resources like Cosmos DB.
- How scripts (manual or scheduled jobs) interact – for example, populating or updating the data in the database.

##### Architectural Patterns and Design Principles
- Separation of concerns: UI components are clearly separated from business logic in the API routes.
- That the project leverages Next.js conventions (file-system based routing for pages and API endpoints) which help drive the architectural choices.
- That the project includes component reusability (UI components are modular) and utility abstraction (library functions and type definitions).
- Point out containerization (DockerFile) which indicates deployment as a container alongside CI/CD with GitHub Actions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser
    Browser["User Browser"]:::browser

    %% Frontend: Next.js UI Rendering Layer
    subgraph "Frontend (UI Rendering)"
        Pages["Next.js Pages & Layouts"]:::pages
        PageHome["Home Page"]:::pages
        PageDifferential["Differential Page"]:::pages
        PageFixtures["Fixtures Page"]:::pages
        Layout["Layout Wrapper"]:::pages

        subgraph "UI Components"
            Header["Header Component"]:::ui
            Footer["Footer Component"]:::ui
            DiffTable["Differential Table Component"]:::ui
            GameweekTable["Gameweek Table Component"]:::ui
            GT_Hook["GameweekTable Hook"]:::ui
            ManagerPanel["Manager Panel Component"]:::ui
            ManagerTeamTable["Manager Team Table Component"]:::ui
            MTT_Hook["ManagerTeamTable Hook"]:::ui
        end

        subgraph "Global Styles & Assets"
            GlobalStyles["Global Styles"]:::styles
            PublicAssets["Public Assets"]:::styles
        end
    end

    %% Backend: API Endpoints Layer
    subgraph "Backend (API Endpoints)"
        FixturesAPI["Fixtures API Endpoint"]:::api
        ManagerAPI["Manager API [managerId] Endpoint"]:::api
        SearchManagersAPI["Search Managers API Endpoint"]:::api
    end

    %% Libraries & Utilities
    subgraph "Libraries & Utilities"
        CosmosClient["Cosmos Client"]:::lib
        TableUtils["Table Utils"]:::lib
        TypeDefs["Type Definitions"]:::lib
    end

    %% Scripts & Deployment Infrastructure
    subgraph "Scripts & Deployment"
        PopulateDB["Populate Database Script"]:::scripts
        UpdateManagers["Update Managers Script"]:::scripts
        CICD["CI/CD Workflow"]:::scripts
        Docker["DockerFile"]:::scripts
    end

    %% External Services
    CosmosDB["Cosmos DB"]:::external

    %% Connections
    Browser -->|"requests"| Pages
    Pages --> PageHome
    Pages --> PageDifferential
    Pages --> PageFixtures
    Pages --> Layout
    PageHome -->|"composes"| Header
    PageHome -->|"composes"| Footer
    PageDifferential -->|"composes"| DiffTable
    PageFixtures -->|"composes"| GameweekTable
    GameweekTable -->|"uses"| GT_Hook
    PageHome -->|"composes"| ManagerPanel
    ManagerPanel -->|"composes"| ManagerTeamTable
    ManagerTeamTable -->|"uses"| MTT_Hook
    Layout -->|"applies"| GlobalStyles
    Layout -->|"serves"| PublicAssets

    %% API Communication from Frontend
    Pages -->|"fetches data via API"| FixturesAPI
    Pages -->|"fetches data via API"| ManagerAPI
    Pages -->|"fetches data via API"| SearchManagersAPI

    %% Backend API calls Libraries
    FixturesAPI -->|"calls"| CosmosClient
    ManagerAPI -->|"calls"| CosmosClient
    SearchManagersAPI -->|"calls"| CosmosClient
    FixturesAPI -->|"utilizes"| TableUtils
    ManagerAPI -->|"utilizes"| TableUtils

    %% Libraries and External Service
    CosmosClient -->|"connects to"| CosmosDB

    %% Scripts interactions
    PopulateDB -->|"populates"| CosmosDB
    UpdateManagers -->|"updates"| CosmosDB
    CICD -->|"deploys container"| Docker

    %% Click Events
    click PageHome "https://github.com/alihaidar2/fantasyplstats/blob/master/app/page.tsx"
    click PageDifferential "https://github.com/alihaidar2/fantasyplstats/blob/master/app/differential/page.tsx"
    click PageFixtures "https://github.com/alihaidar2/fantasyplstats/blob/master/app/fixtures/page.tsx"
    click Layout "https://github.com/alihaidar2/fantasyplstats/blob/master/app/layout.tsx"

    click Header "https://github.com/alihaidar2/fantasyplstats/blob/master/components/header.tsx"
    click Footer "https://github.com/alihaidar2/fantasyplstats/blob/master/components/footer.tsx"
    click DiffTable "https://github.com/alihaidar2/fantasyplstats/blob/master/components/differential_table/differential_table.tsx"
    click GameweekTable "https://github.com/alihaidar2/fantasyplstats/blob/master/components/gameweek_table/gameweek_table.tsx"
    click GT_Hook "https://github.com/alihaidar2/fantasyplstats/blob/master/components/gameweek_table/hooks/useGameweekTable.tsx"
    click ManagerPanel "https://github.com/alihaidar2/fantasyplstats/blob/master/components/manager_panel/manager_panel.tsx"
    click ManagerTeamTable "https://github.com/alihaidar2/fantasyplstats/blob/master/components/manager_team_table/manager_team_table.tsx"
    click MTT_Hook "https://github.com/alihaidar2/fantasyplstats/blob/master/components/manager_team_table/hooks/useManagerTeamTable.tsx"

    click GlobalStyles "https://github.com/alihaidar2/fantasyplstats/tree/master/styles/"
    click PublicAssets "https://github.com/alihaidar2/fantasyplstats/tree/master/public/"

    click FixturesAPI "https://github.com/alihaidar2/fantasyplstats/blob/master/app/api/fixtures/route.ts"
    click ManagerAPI "https://github.com/alihaidar2/fantasyplstats/blob/master/app/api/manager/[managerId]/route.ts"
    click SearchManagersAPI "https://github.com/alihaidar2/fantasyplstats/blob/master/app/api/manager/searchManagers/route.ts"

    click CosmosClient "https://github.com/alihaidar2/fantasyplstats/blob/master/lib/cosmosClient.ts"
    click TableUtils "https://github.com/alihaidar2/fantasyplstats/blob/master/lib/tableUtils.ts"
    click TypeDefs "https://github.com/alihaidar2/fantasyplstats/tree/master/types/"

    click PopulateDB "https://github.com/alihaidar2/fantasyplstats/blob/master/scripts/populateDatabase.js"
    click UpdateManagers "https://github.com/alihaidar2/fantasyplstats/blob/master/scripts/updateManagers.js"
    click CICD "https://github.com/alihaidar2/fantasyplstats/blob/master/.github/workflows/azure-static-web-apps-green-plant-0bd68360f.yml"
    click Docker "https://github.com/alihaidar2/fantasyplstats/tree/master/DockerFile"

    %% Styles
    classDef browser fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef pages fill:#E1F5FE,stroke:#039BE5,stroke-width:2px;
    classDef ui fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef styles fill:#FFECB3,stroke:#FBC02D,stroke-width:2px;
    classDef api fill:#FFCDD2,stroke:#E53935,stroke-width:2px;
    classDef lib fill:#D1C4E9,stroke:#5E35B1,stroke-width:2px;
    classDef scripts fill:#F0F4C3,stroke:#7CB342,stroke-width:2px;
    classDef external fill:#EF9A9A,stroke:#C62828,stroke-width:2px;
```
