# james7132/danmakufu-ph3 architecture

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

- Interactive diagram: https://gitdiagram.com/james7132/danmakufu-ph3
- Repository: https://github.com/james7132/danmakufu-ph3

## Overview

##### Project Type and Purpose
- This is a Windows‐based game scripting framework (Touhou Danmakufu ph3) plus three companion GUI tools:
- DnhConfig – a configuration editor for scripts
- DnhExecutor – the runtime “engine” that loads scripts and runs the game
- DnhViewer – a scene/script previewer and debugger
- FileArchiver – a utility to package/unpackage script/resource bundles
- All components are written in C++/Win32 using DirectX 9 (graphics, input, sound) and share common libraries (GcLib and the Danmakufu “Common” core).

##### High-Level File/Directory Structure
- root
– DirectX9c/{Include,Lib}
– source/
· GcLib/… (Graphics, Input, Sound, Script manager, utility classes)
· TouhouDanmakufu/
· Common/… (engine core: script interpreter, stage/item/player logic)
· DnhConfig/… (UI layer for configuration)
· DnhExecutor/… (UI + game loop + scene management)
· DnhViewer/… (UI + preview scenes)
· FileArchiver/… (UI + archive library implementation)
– bin_th_dnh/… (packaged scripts & resources)
– bin_ext/… (compiled FileArchiver executable)
– *.vcxproj & GcProject.sln

##### Key Components and Their Interactions
A. Applications (executables)
1. DnhConfig.exe
2. DnhExecutor.exe (th_dnh.exe)
3. DnhViewer.exe
4. FileArchiver.exe
B. Shared Libraries
1. GcLib
- DirectX wrappers (DirectGraphics, DirectInput, DirectSound)
- ScriptManager, Texture, Shader, Effect, Window, Utility, etc.
2. Danmakufu Common
- Script execution engine (DnhScript, StgSystem, StgEnemy, StgPlayer, StgShot, etc.)
C. External Dependencies
– DirectX9c SDK (headers + .lib)
– Ogg/Vorbis static libs
– Win32 (user32, gdi32, kernel32)

##### Architectural Patterns & Design Principles
- Modular layering:
- UI Layer (WinMain + MainWindow/Scene panels)
- Engine Layer (Common script engine + GcLib)
- External platform layer (DirectX, OS APIs)
- Shared-library reuse: each executable links against GcLib + Common → avoids code duplication
- Data‐driven scripting: script files drive stage, enemy, item, effect definitions

– Rectangles for executables (Config, Executor, Viewer, Archiver)
– Rounded rectangles for shared libraries (GcLib, Common, ext libs)
– Clouds for external systems (DirectX9 runtime, OS)
b. Relationships & Data Flows
– Config ↔ (reads/writes) Script files
– Executor → Script files (load at runtime)
– Viewer → Script files (load preview)
– Archiver ↔ Script+Resource folders (package/unpackage)
– All executables → GcLib + Common (link‐time dependency)
– GcLib → DirectX9, Ogg/Vorbis libs, Win32 APIs
c. Important Patterns
– Layered architecture: UI → Engine → Platform
– Shared libraries for core logic
– Data/script‐driven design
d. Technologies & Frameworks
– C++/Win32 application framework
– DirectX9 (d3d9, d3dx9, dinput8, dsound)
– HLSL shaders (in GcLib)
– Metasequoia mesh loader, Ogg/Vorbis audio

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Executables Layer
    subgraph "Executables"
        direction TB
        DnhConfig["DnhConfig.exe"] 
        DnhExecutor["DnhExecutor.exe (th_dnh.exe)"]
        DnhViewer["DnhViewer.exe"]
        FileArchiverExe["FileArchiver.exe"]
    end

    %% Shared Libraries Layer
    subgraph "Shared Libraries"
        direction TB
        GcLib["GcLib"] 
        Common["Danmakufu Common"]
    end

    %% Data Store
    scriptStore["Packaged Scripts & Resources"] 

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        DirectX["DirectX9c SDK"]
        Ogg["Ogg/Vorbis Libs"]
        WinAPI["Win32 APIs"]
    end

    %% Relationships: Executables to Shared Libraries
    DnhConfig -->|"links"| GcLib
    DnhConfig -->|"links"| Common
    DnhExecutor -->|"links"| GcLib
    DnhExecutor -->|"links"| Common
    DnhViewer -->|"links"| GcLib
    DnhViewer -->|"links"| Common
    FileArchiverExe -->|"links"| GcLib
    FileArchiverExe -->|"links"| Common

    %% Relationships: Executables to Data Store
    DnhConfig <-->|"reads/writes"| scriptStore
    DnhExecutor -->|"loads at runtime"| scriptStore
    DnhViewer -->|"loads preview"| scriptStore
    FileArchiverExe <-->|"packages/unpackages"| scriptStore

    %% Shared Libraries to External
    GcLib -->|"wraps"| DirectX
    GcLib -->|"uses"| Ogg
    GcLib -->|"uses"| WinAPI

    %% Click Events
    click DnhConfig "https://github.com/james7132/danmakufu-ph3/tree/master/source/TouhouDanmakufu/DnhConfig"
    click DnhExecutor "https://github.com/james7132/danmakufu-ph3/tree/master/source/TouhouDanmakufu/DnhExecutor"
    click DnhViewer "https://github.com/james7132/danmakufu-ph3/tree/master/source/TouhouDanmakufu/DnhViewer"
    click FileArchiverExe "https://github.com/james7132/danmakufu-ph3/tree/master/source/FileArchiver"
    click GcLib "https://github.com/james7132/danmakufu-ph3/tree/master/source/GcLib"
    click Common "https://github.com/james7132/danmakufu-ph3/tree/master/source/TouhouDanmakufu/Common"
    click DirectX "https://github.com/james7132/danmakufu-ph3/tree/master/DirectX9c/{Include, Lib}"
    click scriptStore "https://github.com/james7132/danmakufu-ph3/tree/master/bin_th_dnh/{script, resource}"
    click FileArchiverExe "https://github.com/james7132/danmakufu-ph3/blob/master/bin_ext/FileArchiver.exe"

    %% Styles
    classDef executables fill:#AED6F1,stroke:#21618C,stroke-width:1px
    classDef libraries fill:#A9DFBF,stroke:#1D8348,stroke-width:1px
    classDef datastore fill:#F9E79F,stroke:#B7950B,stroke-width:1px
    classDef external fill:#D5D8DC,stroke:#566573,stroke-width:1px

    class DnhConfig,DnhExecutor,DnhViewer,FileArchiverExe executables
    class GcLib,Common libraries
    class scriptStore datastore
    class DirectX,Ogg,WinAPI external
```
