# yan-yu-lin/ai_npc architecture

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

- Interactive diagram: https://gitdiagram.com/yan-yu-lin/ai_npc
- Repository: https://github.com/yan-yu-lin/ai_npc

## Overview

##### Project type and purpose
- The “worlds” directory full of JSON files holds game data (maps, items, saves, interactions).

##### File structure
Top-level:
- main.py         – entry point, wires together subsystems
- backend.py      – core game logic (state management, rules, interactions)
- pygame_display.py       – rendering engine using pygame
- pygame_map_selection.py – UI for choosing or browsing maps
- demo.py         – scripted demo or example run of the game
- fonts/          – font assets for rendering text
- worlds/         – game data (JSON definitions for maps, items, saves)
- requirements.txt, pyrightconfig.json – project configuration
Observations:
- MVC-like separation: backend (Model), pygame_display + pygame_map_selection (View + Controller)
- Data persistence via JSON files under worlds/
- No web server, purely local application

##### README for additional insights
– README is empty; rely solely on file structure and naming conventions.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entry Points
    DemoRunner["Demo Runner\n(demo.py)"]:::script
    InputLoop["Input & Event Loop\n(main.py)"]:::app

    %% Core Layers
    subgraph "Game Logic Layer" 
        direction TB
        Backend["Core Game Logic\n(backend.py)"]:::app
        StateManager["State Manager"]:::app
        RulesEngine["Rules Engine"]:::app
        EntityManager["Entity Manager"]:::app
        Backend --> StateManager
        Backend --> RulesEngine
        Backend --> EntityManager
    end

    Rendering["Rendering Engine\n(pygame_display.py)"]:::app
    MapUI["Map Selection UI\n(pygame_map_selection.py)"]:::app

    %% Data Layer
    subgraph "Data Storage Layer" 
        direction TB
        Worlds_DS["worlds/"]:::data
        DS1["Dragon_Slayer.json"]:::data
        DS2["Dragon_Slayer_Mar_18.json"]:::data
        DS3["item.json"]:::data
        DS4["maps/map.json"]:::data
        DS5["maps/new_save.json"]:::data
        DS6["maps/world_test.json"]:::data
        DS7["new_save.json"]:::data
        DS8["new_save_new_interaction_mechanism.json"]:::data
        DS9["old.py"]:::data
        DS10["unnamed_save.json"]:::data
        DS11["world_test.json"]:::data
        DS12["images/"]:::data
        DS13["picture/"]:::data
        Worlds_DS --> DS1
        Worlds_DS --> DS2
        Worlds_DS --> DS3
        Worlds_DS --> DS4
        Worlds_DS --> DS5
        Worlds_DS --> DS6
        Worlds_DS --> DS7
        Worlds_DS --> DS8
        Worlds_DS --> DS9
        Worlds_DS --> DS10
        Worlds_DS --> DS11
        Worlds_DS --> DS12
        Worlds_DS --> DS13
    end

    %% Assets and Config
    Fonts["Font Assets\n(fonts/)"]:::data
    Config["Project Config\n(requirements.txt\npyrightconfig.json)"]:::data

    %% Relationships
    DemoRunner -->|invokes| InputLoop
    DemoRunner -->|pre-configures| Backend
    InputLoop -->|captures events| Backend
    InputLoop -->|captures events| MapUI
    MapUI -->|load map| Backend
    Backend -->|"current state"| Rendering
    Backend -->|load/save| Worlds_DS
    Rendering -->|uses fonts| Fonts
    Config -.-> InputLoop
    Config -.-> Backend
    Config -.-> Rendering
    Config -.-> MapUI
    Config -.-> DemoRunner

    %% Click Events
    click DemoRunner "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/demo.py"
    click InputLoop "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/main.py"
    click Backend "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/backend.py"
    click Rendering "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/pygame_display.py"
    click MapUI "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/pygame_map_selection.py"
    click Fonts "https://github.com/yan-yu-lin/ai_npc/tree/year_edit/fonts/"
    click Worlds_DS "https://github.com/yan-yu-lin/ai_npc/tree/year_edit/worlds/"
    click DS1 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/Dragon_Slayer.json"
    click DS2 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/Dragon_Slayer_Mar_18.json"
    click DS3 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/item.json"
    click DS4 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/maps/map.json"
    click DS5 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/maps/new_save.json"
    click DS6 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/maps/world_test.json"
    click DS7 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/new_save.json"
    click DS8 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/new_save_new_interaction_mechanism.json"
    click DS9 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/old.py"
    click DS10 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/unnamed_save.json"
    click DS11 "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/worlds/world_test.json"
    click DS12 "https://github.com/yan-yu-lin/ai_npc/tree/year_edit/worlds/images/"
    click DS13 "https://github.com/yan-yu-lin/ai_npc/tree/year_edit/worlds/picture/"
    click Config "https://github.com/yan-yu-lin/ai_npc/blob/year_edit/requirements.txt"

    %% Styles
    classDef app fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px
    classDef script fill:#D3D3D3,stroke:#333,stroke-width:1px
```
