# jose26398/unitgol architecture

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

- Interactive diagram: https://gitdiagram.com/jose26398/unitgol
- Repository: https://github.com/jose26398/unitgol

## Overview

##### Project Type and Purpose
- UnitGol is a client-side Progressive Web App (PWA) built with React, TypeScript, Vite, and Tailwind.
- It has no traditional server backend; data is stored locally in the browser (IndexedDB).
- Core features: match management, player statistics, and a smart team generator algorithm.

##### File Structure
- Top-level config/build: vite.config.ts, tsconfig*.json, postcss.config.js, tailwind.config.js
- public/: static assets and service worker/manifest for PWA
- src/: application code
- components/: UI broken into feature subfolders (Matches, Players, NewMatch, Seasons, TeamGenerator)
- db/: database schema and initialization (IndexedDB wrapper)
- hooks/: custom React hooks for data access (useDatabase.ts, useNewMatchForm.ts)
- utils/: algorithmic logic (playerStats.ts)
- types/: shared TypeScript definitions
- App.tsx & main.tsx: entry points

##### README for Additional Insights
- Progressive Web App with local data persistence
- Built with React + Vite + Tailwind
- No external API calls; everything runs in the browser
- Key modules: match tracking UIs, player profile UIs, team generation logic

##### Main Components & Their Relationships
a. Static Hosting Layer
- Vite build outputs static assets (HTML, JS, CSS).
- Served by any static file host (e.g., Render).
b. Frontend Application (Browser)
1. Service Worker & Manifest
- Enables offline support, installability, and caching.
2. UI Layer (React Components)
- Organized into feature modules:
– Matches (list view, detail view, modals)
– Players (list, new-player form)
– Seasons (selectors, stats, manager)
– NewMatch (forms for date, teams, goals)
– TeamGenerator (algorithm interface)
– Settings & ShareButton
3. State & Data Access
- Custom hooks (useDatabase) abstract database operations.
- useNewMatchForm orchestrates form state.
4. Local Database (IndexedDB)
- Defined in src/db/index.ts — likely using Dexie or idb.
- Stores matches, players, seasons.
5. Business Logic / Utilities
- playerStats.ts computes metrics (goals, assists, win rates).
- TeamGenerator.tsx uses these metrics to balance teams.

##### Architectural Patterns & Principles
- Modular feature grouping: UI components co-located by feature folder.
- Separation of concerns:
- UI (components)
- Data layer (hooks + db)
- Business logic (utils)
- PWA pattern: service worker, manifest, offline caching.
- Type safety: all shared types in src/types.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hosting Layer
    subgraph "Static Hosting Layer" 
        direction TB
        SH_Public["public/"]:::hosting
        SH_Index["index.html"]:::hosting
        SH_ViteConfig["vite.config.ts"]:::hosting
    end
    click SH_Public "https://github.com/jose26398/unitgol/tree/master/public/"
    click SH_Index "https://github.com/jose26398/unitgol/blob/master/index.html"
    click SH_ViteConfig "https://github.com/jose26398/unitgol/blob/master/vite.config.ts"

    SH_Public -->|Serves assets| BrowserEnv

    %% Browser Environment
    subgraph "Browser Environment"
        direction TB

        %% PWA Layer
        SW["Service Worker & Manifest"]:::pwa
        click SW "https://github.com/jose26398/unitgol/tree/master/public/"

        %% Frontend Entry
        FE_Main["main.tsx"]:::frontend
        FE_App["App.tsx"]:::frontend
        click FE_Main "https://github.com/jose26398/unitgol/blob/master/src/main.tsx"
        click FE_App "https://github.com/jose26398/unitgol/blob/master/src/App.tsx"

        %% UI Layer
        subgraph "UI Layer" 
            direction TB
            %% Matches Feature
            subgraph "Matches" 
                direction TB
                M_Card["MatchCard"]:::frontend
                M_Summary["PlayerSummaryModal"]:::frontend
                M_Confirm["ConfirmDeleteModal"]:::frontend
                M_Edit["EditMatchDialog"]:::frontend
                M_GoalEntry["GoalEntry"]:::frontend
            end
            click M_Card "https://github.com/jose26398/unitgol/blob/master/src/components/Matches/MatchCard.tsx"
            click M_Summary "https://github.com/jose26398/unitgol/blob/master/src/components/Matches/PlayerSummaryModal.tsx"
            click M_Confirm "https://github.com/jose26398/unitgol/blob/master/src/components/ConfirmDeleteModal.tsx"
            click M_Edit "https://github.com/jose26398/unitgol/blob/master/src/components/EditMatchDialog.tsx"
            click M_GoalEntry "https://github.com/jose26398/unitgol/blob/master/src/components/GoalEntry.tsx"

            %% Players Feature
            subgraph "Players"
                direction TB
                P_New["NewPlayerForm"]:::frontend
                P_Card["PlayerCard"]:::frontend
            end
            click P_New "https://github.com/jose26398/unitgol/blob/master/src/components/Players/NewPlayerForm.tsx"
            click P_Card "https://github.com/jose26398/unitgol/blob/master/src/components/Players/PlayerCard.tsx"

            %% Seasons Feature
            subgraph "Seasons"
                direction TB
                S_Selector["SeasonSelector"]:::frontend
                S_Stats["SeasonStats"]:::frontend
                S_Manager["SeasonsManager"]:::frontend
            end
            click S_Selector "https://github.com/jose26398/unitgol/blob/master/src/components/Seasons/SeasonSelector.tsx"
            click S_Stats "https://github.com/jose26398/unitgol/blob/master/src/components/Seasons/SeasonStats.tsx"
            click S_Manager "https://github.com/jose26398/unitgol/blob/master/src/components/Seasons/SeasonsManager.tsx"

            %% NewMatch Feature
            subgraph "NewMatch"
                direction TB
                NM_Form["NewMatchForm"]:::frontend
                NM_Goals["GoalsSection"]:::frontend
                NM_Date["MatchDateInput"]:::frontend
                NM_TeamSel["TeamSelector"]:::frontend
            end
            click NM_Form "https://github.com/jose26398/unitgol/blob/master/src/components/NewMatch/NewMatchForm.tsx"
            click NM_Goals "https://github.com/jose26398/unitgol/blob/master/src/components/NewMatch/GoalsSection.tsx"
            click NM_Date "https://github.com/jose26398/unitgol/blob/master/src/components/NewMatch/MatchDateInput.tsx"
            click NM_TeamSel "https://github.com/jose26398/unitgol/blob/master/src/components/NewMatch/TeamSelector.tsx"

            %% Team Generator Feature
            TG["TeamGenerator"]:::frontend
            click TG "https://github.com/jose26398/unitgol/blob/master/src/components/TeamGenerator/TeamGenerator.tsx"

            %% Settings & Share
            SM["SettingsModal"]:::frontend
            SB["ShareButton"]:::frontend
            click SM "https://github.com/jose26398/unitgol/blob/master/src/components/SettingsModal.tsx"
            click SB "https://github.com/jose26398/unitgol/blob/master/src/components/ShareButton.tsx"
        end

        %% Hooks Layer
        subgraph "Custom Hooks" 
            direction TB
            H_DB["useDatabase"]:::datalayer
            H_Form["useNewMatchForm"]:::datalayer
        end
        click H_DB "https://github.com/jose26398/unitgol/blob/master/src/hooks/useDatabase.ts"
        click H_Form "https://github.com/jose26398/unitgol/blob/master/src/hooks/useNewMatchForm.ts"

        %% Local Database
        DB["IndexedDB (src/db/index.ts)"]:::datalayer
        click DB "https://github.com/jose26398/unitgol/blob/master/src/db/index.ts"

        %% Utilities
        UT["playerStats.ts & other utils"]:::logic
        click UT "https://github.com/jose26398/unitgol/blob/master/src/utils/playerStats.ts"

        %% Shared Types
        TY["Types (src/types/index.ts)"]:::logic
        click TY "https://github.com/jose26398/unitgol/blob/master/src/types/index.ts"

    end

    %% Data Flow
    BrowserEnv --> UI_Layer
    SW -->|Caches assets| UI_Layer
    UI_Layer -->|reads/writes| H_DB
    H_DB -->|queries| DB
    DB -->|data| H_DB
    H_DB -->|provides data| UI_Layer
    UI_Layer -->|calls| UT
    UT -->|computes stats| UI_Layer

    %% Legend
    subgraph Legend
        direction LR
        L1["UI Components"]:::frontend
        L2["Data Layer"]:::datalayer
        L3["Business Logic"]:::logic
        L4["PWA / Offline"]:::pwa
        L5["Hosting"]:::hosting
    end

    classDef frontend fill:#D0E8FF,stroke:#005B9A,color:#005B9A;
    classDef datalayer fill:#DFF5D3,stroke:#2E7D32,color:#2E7D32;
    classDef logic fill:#FFE2B3,stroke:#E65100,color:#E65100;
    classDef pwa fill:#E1BEE7,stroke:#6A1B9A,color:#4A148C;
    classDef hosting fill:#ECEFF1,stroke:#455A64,color:#37474F;
```
