# 0721-daisuki/krkrz architecture

> Architecture diagram of the GitHub repository 0721-daisuki/krkrz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0721-daisuki/krkrz
- Repository: https://github.com/0721-daisuki/krkrz

## Overview

吉里吉里Z is the Windows-oriented runtime of the Kirikiri2 fork: it provides a TJS scripting engine and host services for storage, windows, graphics, sound, and video. The central user-facing flow is application startup into a script-capable runtime, with scripts using host services and presenting interactive content. The tree and excerpts establish several host integrations; they do not expose the full script execution or registration flow, so those links are marked unverified rather than inferred as direct calls.

Main entry points: [`environ/win32/Application.cpp`](https://github.com/0721-daisuki/krkrz/blob/master/environ/win32/Application.cpp) (Windows application), [`tjs2/tjs.cpp`](https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjs.cpp) (TJS engine), [`base/win32/PluginImpl.h`](https://github.com/0721-daisuki/krkrz/blob/master/base/win32/PluginImpl.h) (Plugin services), [`tjs2/tjsNative.cpp`](https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjsNative.cpp) (Native bindings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Application host"]
  node_application["Windows application<br/>[Application.cpp]"]
  node_system_init["System lifecycle<br/>[SysInitImpl.cpp]"]
  node_plugin["Plugin services<br/>[PluginImpl.h]"]
end

subgraph group_script["TJS runtime"]
  node_script_engine["TJS engine<br/>[tjs.cpp]"]
  node_script_compile["Script compilation"]
  node_script_exec["Bytecode execution"]
  node_native_api["Native bindings<br/>[tjsNative.cpp]"]
  node_messages["Messages and errors<br/>[MsgIntf.cpp]"]
end

subgraph group_content["Content and storage"]
  node_storage_api["Storage interface<br/>[StorageIntf.cpp]"]
  node_win_storage["Windows storage<br/>[StorageImpl.cpp]"]
  node_xp3["XP3 archives<br/>[XP3Archive.cpp]"]
end

subgraph group_presentation["Visual presentation"]
  node_window["Window integration<br/>[WindowImpl.cpp]"]
  node_layers["Layer manager<br/>[LayerManager.cpp]"]
  node_draw["Drawing and graphics<br/>[DrawDevice.cpp]"]
end

subgraph group_media["Media playback"]
  node_sound["Wave playback<br/>[WaveImpl.cpp]"]
  node_wave_loops["Wave loop handling"]
  node_video["Video playback<br/>[dsmovie.cpp]"]
end

node_user(("User"))

node_user -.->|"starts"| node_application
node_application -->|"initializes"| node_system_init
node_application -->|"uses"| node_plugin
node_application -.->|"hosts"| node_script_engine
node_script_engine -.->|"compiles"| node_script_compile
node_script_engine -.->|"executes"| node_script_exec
node_script_exec -.->|"dispatches"| node_native_api
node_script_engine -.->|"reports errors"| node_messages
node_native_api -.->|"exposes"| node_storage_api
node_storage_api -->|"implements"| node_win_storage
node_storage_api -->|"opens archives"| node_xp3
node_window -->|"uses"| node_layers
node_layers -.->|"renders through"| node_draw
node_native_api -.->|"exposes"| node_window
node_plugin -->|"provides plugin interface"| node_sound
node_sound -->|"uses"| node_wave_loops
node_plugin -->|"provides plugin interface"| node_video

click node_application "https://github.com/0721-daisuki/krkrz/blob/master/environ/win32/Application.cpp"
click node_system_init "https://github.com/0721-daisuki/krkrz/blob/master/base/win32/SysInitImpl.cpp"
click node_plugin "https://github.com/0721-daisuki/krkrz/blob/master/base/win32/PluginImpl.h"
click node_script_engine "https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjs.cpp"
click node_script_compile "https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjsInterCodeGen.cpp"
click node_script_exec "https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjsInterCodeExec.cpp"
click node_native_api "https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjsNative.cpp"
click node_messages "https://github.com/0721-daisuki/krkrz/blob/master/msg/MsgIntf.cpp"
click node_storage_api "https://github.com/0721-daisuki/krkrz/blob/master/base/StorageIntf.cpp"
click node_win_storage "https://github.com/0721-daisuki/krkrz/blob/master/base/win32/StorageImpl.cpp"
click node_xp3 "https://github.com/0721-daisuki/krkrz/blob/master/base/XP3Archive.cpp"
click node_window "https://github.com/0721-daisuki/krkrz/blob/master/visual/win32/WindowImpl.cpp"
click node_layers "https://github.com/0721-daisuki/krkrz/blob/master/visual/LayerManager.cpp"
click node_draw "https://github.com/0721-daisuki/krkrz/blob/master/visual/win32/DrawDevice.cpp"
click node_sound "https://github.com/0721-daisuki/krkrz/blob/master/sound/win32/WaveImpl.cpp"
click node_wave_loops "https://github.com/0721-daisuki/krkrz/blob/master/sound/WaveLoopManager.cpp"
click node_video "https://github.com/0721-daisuki/krkrz/blob/master/movie/win32/dsmovie.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_application,node_system_init,node_plugin,node_user toneBlue
class node_script_engine,node_script_compile,node_script_exec,node_native_api,node_messages toneAmber
class node_storage_api,node_win_storage,node_xp3 toneMint
class node_window,node_layers,node_draw toneRose
class node_sound,node_wave_loops,node_video toneIndigo
```

## Components

### Application host

- [Windows application](https://github.com/0721-daisuki/krkrz/blob/master/environ/win32/Application.cpp): `environ/win32/Application.cpp`
- [System lifecycle](https://github.com/0721-daisuki/krkrz/blob/master/base/win32/SysInitImpl.cpp): `base/win32/SysInitImpl.cpp`
- [Plugin services](https://github.com/0721-daisuki/krkrz/blob/master/base/win32/PluginImpl.h): `base/win32/PluginImpl.h`

### TJS runtime

- [TJS engine](https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjs.cpp): `tjs2/tjs.cpp`
- [Script compilation](https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjsInterCodeGen.cpp): `tjs2/tjsInterCodeGen.cpp`
- [Bytecode execution](https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjsInterCodeExec.cpp): `tjs2/tjsInterCodeExec.cpp`
- [Native bindings](https://github.com/0721-daisuki/krkrz/blob/master/tjs2/tjsNative.cpp): `tjs2/tjsNative.cpp`
- [Messages and errors](https://github.com/0721-daisuki/krkrz/blob/master/msg/MsgIntf.cpp): `msg/MsgIntf.cpp`

### Content and storage

- [Storage interface](https://github.com/0721-daisuki/krkrz/blob/master/base/StorageIntf.cpp): `base/StorageIntf.cpp`
- [Windows storage](https://github.com/0721-daisuki/krkrz/blob/master/base/win32/StorageImpl.cpp): `base/win32/StorageImpl.cpp`
- [XP3 archives](https://github.com/0721-daisuki/krkrz/blob/master/base/XP3Archive.cpp): `base/XP3Archive.cpp`

### Visual presentation

- [Window integration](https://github.com/0721-daisuki/krkrz/blob/master/visual/win32/WindowImpl.cpp): `visual/win32/WindowImpl.cpp`
- [Layer manager](https://github.com/0721-daisuki/krkrz/blob/master/visual/LayerManager.cpp): `visual/LayerManager.cpp`
- [Drawing and graphics](https://github.com/0721-daisuki/krkrz/blob/master/visual/win32/DrawDevice.cpp): `visual/win32/DrawDevice.cpp`

### Media playback

- [Wave playback](https://github.com/0721-daisuki/krkrz/blob/master/sound/win32/WaveImpl.cpp): `sound/win32/WaveImpl.cpp`
- [Wave loop handling](https://github.com/0721-daisuki/krkrz/blob/master/sound/WaveLoopManager.cpp): `sound/WaveLoopManager.cpp`
- [Video playback](https://github.com/0721-daisuki/krkrz/blob/master/movie/win32/dsmovie.cpp): `movie/win32/dsmovie.cpp`

### Other components

- **User**

## Connections

- User → Windows application: starts
- Windows application → System lifecycle: initializes (evidence: `environ/win32/Application.cpp`)
- Windows application → Plugin services: uses (evidence: `environ/win32/Application.cpp`)
- Windows application → TJS engine: hosts
- TJS engine → Script compilation: compiles
- TJS engine → Bytecode execution: executes
- Bytecode execution → Native bindings: dispatches
- TJS engine → Messages and errors: reports errors
- Native bindings → Storage interface: exposes
- Storage interface → Windows storage: implements (evidence: `base/win32/StorageImpl.cpp`)
- Storage interface → XP3 archives: opens archives (evidence: `base/StorageIntf.cpp`)
- Window integration → Layer manager: uses (evidence: `visual/win32/WindowImpl.cpp`)
- Layer manager → Drawing and graphics: renders through
- Native bindings → Window integration: exposes
- Plugin services → Wave playback: provides plugin interface (evidence: `sound/win32/WaveImpl.cpp`)
- Wave playback → Wave loop handling: uses (evidence: `sound/win32/WaveImpl.cpp`)
- Plugin services → Video playback: provides plugin interface (evidence: `movie/win32/dsmovie.cpp`)
