# lucasayb/pkmds-blazor architecture

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

- Interactive diagram: https://gitdiagram.com/lucasayb/pkmds-blazor
- Repository: https://github.com/lucasayb/pkmds-blazor

## Overview

##### Project Type & Purpose
- PKMDS is a Progressive Web App (PWA) built on Blazor WebAssembly.
- It runs entirely in the browser (no custom backend), loading .NET DLLs (including PKHeX.Core) into a WebAssembly runtime to parse and edit Pokémon save files.
- It supports offline use via a Service Worker.

##### File Structure
- Top-level “Pkmds.Web” directory contains:
- Components/ (UI razor components)
- Services/ (C# classes for file parsing, state, JS interop)
- wwwroot/ (static assets, service-worker.js, sprites, CSS, JS libs)
- Program.cs & App.razor (app startup)
- Config files: launchSettings.json, libman.json, Service Worker manifests, _Imports.razor
- No “backend” directory: this is a purely client-side app.

##### Technical Stack from README
- Blazor WebAssembly (.NET 7+), PKHeX.Core (.NET library for save‐file I/O)
- PWA features: service‐worker.js, manifest.webmanifest
- JS interop for file download (fileSave.js) and crypto (crypto-js)
- Hosted on GitHub Pages, initial fetch from static HTTP server, then offline.

##### Main Components & Interactions
a. Browser & PWA Layer
- User’s browser (Chrome/Chromium)
- Service Worker: caches HTML, CSS, JS, .NET DLLs, sprites, manifest
- Offline cache ensures repeat loads from local

b. Blazor WebAssembly Runtime
- Bootstraps .NET runtime in WebAssembly
- Loads Pkmds.Web.dll + dependencies (PKHeX.Core.dll)

c. UI Layer (Components)
- Razor components (FileUploadDialog, PokemonEditForm, BoxGrid, etc.)
- Data-bound to an application state (AppState.cs / IAppState)

d. Application Logic & Services
- AppService: orchestrates reading/parsing save‐file bytes via PKHeX.Core
- RefreshService: notifies UI of data changes
- JsService: JS Interop for calling fileSave.js & Crypto-JS functions (AES, MD5)

e. PKHeX.Core Library
- .NET library loaded into Wasm to read/write various save formats

f. Browser APIs & External Libraries
- IndexedDB or in‐memory store (if used)
- FileSaver API (via fileSave.js)
- crypto-js for cryptographic helpers (if needed by PKHeX.Core)

g. Assets & Static Content
- Sprites (wwwroot/sprites/…)
- CSS (app.css)

##### Architectural Patterns & Design Principles
- Component-Based UI (Blazor Razor components)
- Service Abstraction (IAppService, IRefreshService, JsService interfaces)
- Single-Page Application with PWA caching
- Separation of concerns: UI vs. file I/O vs. state management vs. JS interop

- Clear labels: “Browser”, “Service Worker (Cache)”, “Blazor Wasm Runtime”, “Pkmds.Web.dll”, “PKHeX.Core.dll”, “JsService”, etc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser & PWA Layer"
        Browser["User Browser"]:::external
        SW["Service Worker"]:::external
        Index["index.html"]:::assets
        Manifest["manifest.webmanifest"]:::assets
    end

    subgraph "Blazor WebAssembly Runtime"
        Runtime[".NET Wasm Runtime"]:::services
        Program["Program.cs"]:::services
        AppR["App.razor"]:::services
        Imports["_Imports.razor"]:::services
        Globals["GlobalUsings.cs"]:::services
        Csproj["Pkmds.Web.csproj"]:::services
    end

    subgraph "UI Components"
        Layout["MainLayout.razor"]:::ui
        FileUpload["FileUploadDialog.razor"]:::ui
        HomePage["Home.razor"]:::ui
        PokemonForm["PokemonEditForm.razor"]:::ui
        BoxGrid["BoxGrid.razor"]:::ui
        BoxComp["BoxComponent.razor"]:::ui
        PartyGrid["PartyGrid.razor"]:::ui
        StorageComp["PokemonStorageComponent.razor"]:::ui
    end

    subgraph "Services & State"
        AppStateImpl["AppState.cs"]:::services
        IAppState["IAppState.cs"]:::services
        AppService["AppService.cs"]:::services
        IAppService["IAppService.cs"]:::services
        RefreshService["RefreshService.cs"]:::services
        IRefresh["IRefreshService.cs"]:::services
        JsService["JsService.cs"]:::services
        AesProv["BlazorAesProvider.cs"]:::services
        Md5Prov["BlazorMd5Provider.cs"]:::services
    end

    subgraph "External Libraries & APIs"
        PKHeX["PKHeX.Core.dll"]:::external
        FileSaveJS["fileSave.js"]:::external
        CryptoJS["crypto-js"]:::external
    end

    subgraph "Static Assets"
        CSS["app.css"]:::assets
        Sprites["Sprites Directory"]:::assets
    end

    subgraph "Config & Manifests"
        Launch["launchSettings.json"]:::assets
        LibMan["libman.json"]:::assets
    end

    Browser --> SW
    Browser --> Index
    Browser --> Manifest
    SW --> Index
    SW --> Program

    Program --> Runtime
    Runtime --> Csproj
    Csproj --> PKHeX
    Runtime --> AppR
    AppR --> Layout

    Layout --> FileUpload
    Layout --> HomePage
    FileUpload --> AppService
    AppService --> PKHeX
    PKHeX --> AppService
    AppService --> RefreshService
    RefreshService --> Layout
    AppService --> JsService
    JsService --> FileSaveJS
    JsService --> CryptoJS

    Layout --> PokemonForm
    PokemonForm --> IAppState
    IAppState --> AppStateImpl
    AppStateImpl --> PokemonForm

    HomePage --> BoxGrid
    HomePage --> PartyGrid
    BoxGrid --> BoxComp
    BoxGrid --> AppStateImpl
    PartyGrid --> AppStateImpl
    StorageComp --> AppStateImpl

    Runtime --> CSS
    Layout --> Sprites

    LibMan --> Csproj
    Launch --> Program

    click SW "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/wwwroot/service-worker.js"
    click SW "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/wwwroot/service-worker.published.js"
    click Index "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/wwwroot/index.html"
    click Manifest "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/wwwroot/manifest.webmanifest"

    click Program "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Program.cs"
    click AppR "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/App.razor"
    click Imports "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/_Imports.razor"
    click Globals "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/GlobalUsings.cs"
    click Csproj "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Pkmds.Web.csproj"

    click Layout "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/Layout/MainLayout.razor"
    click FileUpload "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/FileUploadDialog.razor"
    click PokemonForm "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/Components/EditForms/PokemonEditForm.razor"
    click BoxGrid "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/BoxGrid.razor"
    click BoxComp "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/BoxComponent.razor"
    click PartyGrid "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/PartyGrid.razor"
    click StorageComp "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/PokemonStorageComponent.razor"
    click HomePage "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Components/Pages/Home.razor"

    click AppStateImpl "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/AppState.cs"
    click IAppState "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/IAppState.cs"
    click AppService "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Services/AppService.cs"
    click IAppService "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Services/IAppService.cs"
    click RefreshService "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Services/RefreshService.cs"
    click IRefresh "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Services/IRefreshService.cs"
    click JsService "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Services/JsService.cs"
    click AesProv "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Services/BlazorAesProvider.cs"
    click Md5Prov "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Services/BlazorMd5Provider.cs"

    click FileSaveJS "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/wwwroot/js/fileSave.js"
    click CryptoJS "https://github.com/lucasayb/pkmds-blazor/tree/main/Pkmds.Web/wwwroot/js/lib/crypto-js"

    click CSS "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/wwwroot/css/app.css"
    click Sprites "https://github.com/lucasayb/pkmds-blazor/tree/main/Pkmds.Web/wwwroot/sprites/"

    click Launch "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/Properties/launchSettings.json"
    click LibMan "https://github.com/lucasayb/pkmds-blazor/blob/main/Pkmds.Web/libman.json"

    classDef ui fill:#E3F2FD,stroke:#90CAF9
    classDef services fill:#E8F5E9,stroke:#A5D6A7
    classDef external fill:#FFF3E0,stroke:#FFB74D
    classDef assets fill:#ECEFF1,stroke:#B0BEC5
```
