# n-eeraj/pokemon-black-crystal architecture

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

- Interactive diagram: https://gitdiagram.com/n-eeraj/pokemon-black-crystal
- Repository: https://github.com/n-eeraj/pokemon-black-crystal

## Overview

##### Project type and purpose
- This is a client-side single-page application (SPA) built in Vue 3. It’s a fan-made online Pokémon game that runs entirely in the browser, leveraging local JSON data for offline game modes and PeerJS for real-time P2P multiplayer (PvP, Trade).

##### File structure
- Top level:
- src/ → application code
– assets/ → audio, images, JSON game data
– js/ → Vue entrypoints, components, router, store, mixins
– styles/ → SCSS modules
– registerServiceWorker.js → offline caching
– main.js → bootstraps Vue app
- There is no custom backend; real-time features use PeerJS (client library) plus its hosted signaling server.

##### Key insights from README
- Tech stack: Vue 3, SCSS, Vue Router, Vuex, PeerJS, AutoAnimate
- Game modes include Story, Exploration (offline & Safari Zone), Arcade, PvP, Trade, Carnival
- PvP/Trade modes require real-time P2P connections

- asset fetch flow (Browser → Static Host)
- router → component render flow
- Vuex dispatch/commit flows
- network flows: Browser ↔ Signaling Server ↔ Browser
- Assets/data in another
- Network/external services in a third
- Persistent layers (Service Worker, Store)
- Transient modules (Components, Router)

Summary
1. Static Hosting & Assets (public/, src/assets/data)
2. Browser Application Core (Service Worker caching, main.js, Vue Router, Vuex Store)
3. Presentation Layer (View components, UI modules, AutoAnimate)
4. Networking Layer (PeerJS Client ↔ PeerJS Signaling Server ↔ Other Clients)
This will capture all essential architectural elements without over-splitting components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layer 1: Static Hosting & Assets
    subgraph "Static Hosting & Assets"
        direction TB
        StaticHost["HTML Shell<br/>public/index.html"]:::assets
        Audio["Audio Assets"]:::assets
        Images["Image Assets"]:::assets
        Fonts["Font Assets"]:::assets
        Icons["Icon Assets"]:::assets
        LocalJSON["Local JSON Data Module"]:::assets
    end

    %% Layer 2: Browser Application Core
    subgraph "Browser Application Core"
        direction TB
        SW["Service Worker<br/>caching & offline"]:::app
        MainJS["Application Bootstrap<br/>main.js"]:::app
        RouterMain["Vue Router<br/>index.js"]:::app
        RouterRoutes["Route Definitions<br/>routes/"]:::app
        StoreCore["Vuex Store<br/>store.js"]:::app
        StoreActions["Vuex Actions"]:::app
        StoreMutations["Vuex Mutations"]:::app
        StoreGetters["Vuex Getters"]:::app
        AppRoot["Root App Component<br/>App.vue"]:::app
        Migrations["Data Migration Logic"]:::app
    end

    %% Layer 3: Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Views["View Components"]:::app
        Components["UI Components"]:::app
        AutoAnimate["UI Transitions<br/>(AutoAnimate)"]:::app
    end

    %% Layer 4: Networking Layer
    subgraph "Networking Layer"
        direction TB
        PeerClient["PeerJS Client"]:::network
        Signaling["PeerJS Signaling Server"]:::network
        OtherClients["Other Peer Clients"]:::network
    end

    %% Connections: Static Hosting & Assets to Core
    StaticHost -->|loads| SW
    StaticHost -->|loads| MainJS
    Audio -->|fetched| SW
    Images -->|fetched| SW
    Fonts -->|fetched| SW
    Icons -->|fetched| SW
    LocalJSON -->|served| SW

    %% Core initialization flow
    SW -->|registers| MainJS
    MainJS -->|bootstraps| AppRoot
    MainJS -->|initializes| StoreCore
    MainJS -->|initializes| RouterMain
    StoreCore -->|uses| StoreActions
    StoreCore -->|uses| StoreMutations
    StoreCore -->|uses| StoreGetters
    StoreCore -->|runs| Migrations
    AppRoot -->|renders| RouterMain
    RouterMain -->|loads routes| RouterRoutes

    %% Presentation flow
    RouterMain -->|navigates to| Views
    Views -->|composed of| Components
    Components -->|integrates| AutoAnimate
    Components -->|dispatches| StoreActions
    StoreCore -->|updates| Components

    %% Data flow for JSON assets
    Components -->|fetches| LocalJSON
    StoreActions -->|commits| StoreMutations -->|updates| StoreCore

    %% Networking flow
    Components -->|invokes| PeerClient
    PeerClient -->|requests ID| Signaling
    OtherClients -->|requests ID| Signaling
    PeerClient <-->|P2P DataConnection| OtherClients
    PeerClient -->|dispatches network messages| StoreActions
    StoreCore -->|reactive update| Components

    %% Click Events
    click StaticHost "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/public/index.html"
    click Audio "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/assets/audio"
    click Images "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/assets/images"
    click Fonts "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/assets/fonts"
    click Icons "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/assets/icons"
    click LocalJSON "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/assets/data"
    click SW "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/registerServiceWorker.js"
    click MainJS "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/main.js"
    click RouterMain "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/router/index.js"
    click RouterRoutes "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/js/router/routes/"
    click StoreCore "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/store/store.js"
    click StoreActions "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/store/actions.js"
    click StoreMutations "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/store/mutations.js"
    click StoreGetters "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/store/getters.js"
    click AppRoot "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/App.vue"
    click Migrations "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/js/mixins/migrations/"
    click Views "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/js/views/"
    click Components "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/js/components/"
    click AutoAnimate "https://github.com/n-eeraj/pokemon-black-crystal/tree/main/src/js/components/UI/"
    click PeerClient "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/mixins/invitation.js"
    click PeerClient "https://github.com/n-eeraj/pokemon-black-crystal/blob/main/src/js/mixins/messages.js"

    %% Styles
    classDef assets fill:#FDEBD0,stroke:#D35400,color:#78281F
    classDef app fill:#D6EAF8,stroke:#2874A6,color:#1B4F72
    classDef network fill:#D5F5E3,stroke:#239B56,color:#145A32
```
