# moise7000/p-l-level-editor architecture

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

- Interactive diagram: https://gitdiagram.com/moise7000/p-l-level-editor
- Repository: https://github.com/moise7000/p-l-level-editor

## Overview

##### Project type and purpose
- This is a macOS desktop application built in Swift/SwiftUI (an Xcode project).

##### File structure
- Xcode scaffolding (P-L-Level-Editor.xcodeproj & workspace).
- P-L-Level-Editor/Assets.xcassets & Sound – app-bundled images and sounds.
- P-L-Level-Editor/Helpers
– FileMonitor.swift: watches the user-selected game folder for changes
– JSONFunction.swift, FileManager utilities, generic playground/tester views
- P-L-Level-Editor/Models
– AssetsModel, GridModel, GraphModel, LevelsGraphMonitor, DataController (persistence)
– Data folder: domain data types and SwiftData controller
- P-L-Level-Editor/Views
– SwiftUI screens: ContentView, LevelEditorView, EditLevelView, LevelsGraphView, SoundEditorView, etc.
- Entry point: P_L_Level_EditorApp.swift

##### README for insights
- User must select the game’s `src/` folder so the editor can traverse
- PNG naming conventions (camelCase) feed into JSON generation
- Scene files in `src/scenes` drive the “Levels Architecture” graph

##### Defining components
a. Main components
– UI Layer (SwiftUI Views & View structs)
– ViewModels/Controllers (Models + DataController orchestrating data flow)
– File System & Asset Scanner (FileMonitor, FileManager, JSONFunction)
– Graph Engine (GraphModel, LevelsGraphMonitor)
– Local Storage (JSON files, SwiftData store)
– External “Game Project src folder” (assets & scenes)

b. Relationships & interactions
1. User opens app → Views rendered by SwiftUI
2. User selects “src” folder → FileMonitor begins scanning → JSONFunction parses asset files → AssetsModel & LevelsModel populated
3. Models publish changes → Views update (via @ObservedObject/@State)
4. On edit/save → Views invoke DataController → writes JSON or SwiftData → persisted to disk
5. GraphModel listens for scene file changes → updates LevelsGraphView

c. Architectural patterns
– MVVM: SwiftUI Views bind to Observable Models/ViewModels
– Observer/Publisher (Combine) in FileMonitor and DataController
– Singleton or shared DataController for centralized persistence

d. Key technologies & frameworks
– SwiftUI for UI
– Combine for reactive updates
– JSONEncoder/Decoder for metadata
– FileManager APIs for directory traversal
– SwiftData or custom JSON-backed persistence

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        UI_Content["ContentView"]:::ui
        UI_LevelEditor["LevelEditorView"]:::ui
        UI_EditLevel["EditLevelView"]:::ui
        UI_LevelsGraph["LevelsGraphView"]:::ui
        UI_NewLevel["NewLevelView"]:::ui
        UI_SavedLevels["SavedLevelsView"]:::ui
        UI_SoundEditor["SoundEditorView"]:::ui
        UI_AssetsCollection["AssetsCollectionView"]:::ui
        UI_AssetsTyped["AssetsCollectionTypedView"]:::ui
        UI_Arrow["ArrowView"]:::ui
    end

    %% Logic Layer
    subgraph "Logic Layer"
        direction TB
        Logic_AssetsModel["AssetsModel"]:::logic
        Logic_AssetsTypeModel["AssetsTypeModel"]:::logic
        Logic_GridModel["GridModel"]:::logic
        Logic_GridItemModel["GridItemModel"]:::logic
        Logic_SavedLevelsModel["SavedLevelsModel"]:::logic
        Logic_APTModel["APTModel"]:::logic
        Logic_LevelGridModel["LevelGridForSwiftDataModel"]:::logic
        Logic_DataController["DataController"]:::logic
        subgraph "Graph Engine"
            direction TB
            Logic_GraphModel["GraphModel"]:::logic
            Logic_LevelsGraphMonitor["LevelsGraphMonitor"]:::logic
        end
        subgraph "Persistence"
            direction TB
            Logic_AssetsData["AssetsDataModel"]:::logic
        end
    end

    %% I/O Layer
    subgraph "I/O Layer"
        direction TB
        IO_FileMonitor["FileMonitor"]:::io
        IO_JSONFunc["JSONFunction"]:::io
        IO_ImageFunc["ImageFunction"]:::io
        IO_StringFunc["StringFunction"]:::io
        IO_ArrayFunc["ArrayFunction"]:::io
    end

    %% External Source
    External_Game["Game Project src/ folder"]:::external

    %% Entry Point
    App["P_L_Level_EditorApp"]:::ui

    %% Connections
    App -->|"launches"| UI_Content
    UI_Content -->|"selectSrc(folder)"| IO_FileMonitor
    IO_FileMonitor -->|"scanAssets()"| IO_JSONFunc
    IO_JSONFunc -->|"parseJSON()"| Logic_AssetsModel
    IO_ImageFunc -->|"processImages()"| Logic_AssetsModel
    IO_StringFunc -->|"formatNames()"| Logic_AssetsModel
    IO_ArrayFunc -->|"arrayHelpers()"| Logic_AssetsModel

    Logic_AssetsModel -->|"publishUpdates()"| UI_AssetsCollection
    Logic_AssetsTypeModel -->|"publishUpdates()"| UI_AssetsTyped
    Logic_GridModel -->|"publishUpdates()"| UI_LevelEditor
    Logic_SavedLevelsModel -->|"publishUpdates()"| UI_SavedLevels

    UI_LevelEditor -->|"editLevel()"| Logic_GridItemModel
    UI_EditLevel -->|"modifyItem()"| Logic_GridItemModel
    UI_SoundEditor -->|"editSound()"| Logic_APTModel

    UI_NewLevel -->|"createLevel()"| Logic_SavedLevelsModel
    UI_SavedLevels -->|"loadLevel()"| Logic_GridModel

    UI_LevelEditor -->|"saveLevel()"| Logic_DataController
    Logic_DataController -->|"writeJSON()/SwiftData"| Logic_AssetsData

    External_Game -->|"fileChanged()"| IO_FileMonitor
    External_Game -->|"sceneChanged()"| Logic_LevelsGraphMonitor
    Logic_LevelsGraphMonitor -->|"updateGraph()"| Logic_GraphModel
    Logic_GraphModel -->|"publishGraph()"| UI_LevelsGraph

    %% Click Events
    click UI_Content "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/ContentView.swift"
    click UI_LevelEditor "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/LevelEditorView.swift"
    click UI_EditLevel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/EditLevelView.swift"
    click UI_LevelsGraph "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/LevelsGraphView.swift"
    click UI_NewLevel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/NewLevelView.swift"
    click UI_SavedLevels "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/SavedLevelsView.swift"
    click UI_SoundEditor "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/SoundEditorView.swift"
    click UI_AssetsCollection "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/AssetsCollectionView.swift"
    click UI_AssetsTyped "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/AssetsCollectionTypedView.swift"
    click UI_Arrow "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Views/ArrowView.swift"
    click App "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/P_L_Level_EditorApp.swift"
    click IO_FileMonitor "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Helpers/FileMonitor.swift"
    click IO_JSONFunc "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Helpers/Functions/JSONFunction.swift"
    click IO_ImageFunc "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Helpers/Functions/ImageFunction.swift"
    click IO_StringFunc "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Helpers/Functions/StringFunction.swift"
    click IO_ArrayFunc "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Helpers/Functions/ArrayFunction.swift"
    click Logic_GraphModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/GraphModel.swift"
    click Logic_LevelsGraphMonitor "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/LevelsGraphMonitor.swift"
    click Logic_AssetsModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/AssetsModel.swift"
    click Logic_AssetsTypeModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/AssetsTypeModel.swift"
    click Logic_GridModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/GridModel.swift"
    click Logic_GridItemModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/GridItemModel.swift"
    click Logic_SavedLevelsModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/SavedLevelsModel.swift"
    click Logic_APTModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/APTModel.swift"
    click Logic_LevelGridModel "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/LevelGridForSwiftDataModel.swift"
    click Logic_AssetsData "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/Data/AssetsDataModel.swift"
    click Logic_DataController "https://github.com/moise7000/p-l-level-editor/blob/main/P-L-Level-Editor/Models/Data/DataController.swift"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef io fill:#FFFFE0,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
