# openysm/ysmparser architecture

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

- Interactive diagram: https://gitdiagram.com/openysm/ysmparser
- Repository: https://github.com/openysm/ysmparser

## Overview

#### Purpose and entry points
YSMParser is a C++20 offline converter/decryptor for encrypted Yes Steve Model (`.ysm`) assets. It restores Blockbench-compatible project content, including models, animations, textures, sounds, metadata, and reconstructed editable geometry. The native CLI entry point is `YSMParser/main.cpp`; parser APIs are exposed through `YSMParser/parsers/YSMParser.hpp`. Java and browser consumers are supported through JNI and a small web wrapper: `java/com/ysm/parser/YSMParser.java`, `web/app.js`.

#### Build and delivery boundary
CMake is the build orchestrator for native and Emscripten/WASM targets. Root build definitions and target presets are in `CMakeLists.txt`, `CMakePresets.json`, and `YSMParser/CMakeLists.txt`. The repository ships vendored native dependencies rather than relying on runtime package services. Release automation is GitHub Actions at `.github/workflows/release.yml`; no backend or database service is represented.

#### CLI orchestration
The CLI accepts input/output directories, verbosity, and thread-count controls, then processes `.ysm` files in an input directory. `YSMParser/main.cpp` is the application boundary and uses the bundled command-line parser in `YSMParser/CLI11.hpp`. Control moves from filesystem-oriented batch orchestration into the parser facade, which should isolate callers from format-specific implementations.

#### Parser facade and binary reading
`YSMParser/parsers/YSMParser.cpp` / `YSMParser/parsers/YSMParser.hpp` form the central dispatch layer. They receive encrypted model input, identify/select the applicable format parser, and produce restored project output. `YSMParser/parsers/BufferReader.hpp` is the low-level binary boundary: format decoders should consume structured values through it rather than manipulate raw buffers throughout the stack. Parse failures cross a dedicated error boundary at `YSMParser/parsers/exceptions/ParserException.hpp`.

#### Versioned format pipeline
Separate implementations preserve format-specific encryption and serialization behavior:
- V1: `YSMParser/parsers/YSMParserV1.cpp`, `YSMParser/parsers/YSMParserV1.hpp`
- V2: `YSMParser/parsers/YSMParserV2.cpp`, `YSMParser/parsers/YSMParserV2.hpp`
- V3: `YSMParser/parsers/v3/YSMParserV3.cpp`, `YSMParser/parsers/v3/YSMParserV3.hpp`

V3 further separates header interpretation and player texture extraction into `YSMParser/parsers/v3/YSGPHeaderParser.hpp` and `YSMParser/parsers/v3/PlayerTextureCollector.hpp`. The principal flow is encrypted bytes → version/header interpretation → version-specific decryption/decompression → decoded project assets and JSON/Blockbench reconstruction.

#### Cryptography, compression, and asset codecs
Shared cryptographic operations are centralized in `YSMParser/algorithms/CryptoAlgorithms.cpp` and `YSMParser/algorithms/CryptoAlgorithms.hpp`, keeping cipher/key derivation behavior outside version parsers. Compression support is wrapped by `YSMParser/algorithms/YsmZstd.hpp`. Vendored implementations include AES, XChaCha20, CityHash, MD5, zlib, zstd, base64, fast PNG, and JSON—for example `external/AES/src/AES.cpp`, `external/xchacha20/src/xchacha20.cc`, and `external/zstd/lib/zstd.h`.

#### Native interop and platform targets
JNI adapters expose parser and algorithm capabilities to Java: `YSMParser/parsers/YSMParserJNI.cpp` and `YSMParser/algorithms/NativeAlgorithmsJNI.cpp`, with Java-facing declarations in `java/com/ysm/parser/YSMNative.java`. Platform portability is consolidated in `YSMParser/platform/PlatformCompat.hpp`. Emscripten builds make the same core suitable for Node/WASM and browser use; `web/index.html` and `web/app.js` are the browser-facing host layer rather than a server application.

Main entry points: [`YSMParser/parsers/YSMParser.cpp`](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParser.cpp) (Parser facade), [`CMakeLists.txt`](https://github.com/openysm/ysmparser/blob/main/CMakeLists.txt) (CMake targets), [`YSMParser/parsers/YSMParserV1.cpp`](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserV1.cpp) (V1 decoder), [`YSMParser/parsers/YSMParserV2.cpp`](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserV2.cpp) (V2 decoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_delivery["Build &amp; Delivery"]
  node_cmake["CMake targets<br/>build orchestration<br/>[CMakeLists.txt]"]
  node_release["Release workflow<br/>CI delivery<br/>[release.yml]"]
end

subgraph group_hosts["Consumer Hosts"]
  node_cli["Native CLI<br/>C++ entry point<br/>[main.cpp]"]
  node_java["Java API<br/>Java consumer API<br/>[YSMParser.java]"]
  node_web["Browser wrapper<br/>web host<br/>[app.js]"]
  node_jni["JNI adapters<br/>native interop<br/>[YSMParserJNI.cpp]"]
end

subgraph group_core["Parser Core"]
  node_facade{{"Parser facade<br/>dispatch API<br/>[YSMParser.cpp]"}}
  node_reader["Buffer reader<br/>binary reader<br/>[BufferReader.hpp]"]
  node_errors["Parser errors<br/>error boundary"]
end

subgraph group_formats["Versioned Decoders"]
  node_v1["V1 decoder<br/>format parser<br/>[YSMParserV1.cpp]"]
  node_v2["V2 decoder<br/>format parser<br/>[YSMParserV2.cpp]"]
  node_v3["V3 decoder<br/>format parser<br/>[YSMParserV3.cpp]"]
end

subgraph group_shared["Shared Native Services"]
  node_crypto["Crypto algorithms<br/>crypto service"]
  node_zstd["Zstd wrapper<br/>compression service<br/>[YsmZstd.hpp]"]
  node_platform["Platform compatibility<br/>portability layer<br/>[PlatformCompat.hpp]"]
  node_deps["Vendored codecs<br/>native dependencies<br/>[AES.cpp]"]
end

node_release -->|"builds releases"| node_cmake
node_cmake -->|"builds native"| node_cli
node_cmake -->|"builds WASM host"| node_web
node_cmake -->|"selects targets"| node_platform
node_cli -->|"converts batch inputs"| node_facade
node_java -->|"calls native"| node_jni
node_jni -->|"invokes parser"| node_facade
node_web -->|"uses WASM core"| node_facade
node_facade -->|"dispatches V1"| node_v1
node_facade -->|"dispatches V2"| node_v2
node_facade -->|"dispatches V3"| node_v3
node_facade -.->|"reports failures"| node_errors
node_v1 -->|"reads bytes"| node_reader
node_v2 -->|"reads bytes"| node_reader
node_v3 -->|"reads bytes"| node_reader
node_v1 -->|"decrypts"| node_crypto
node_v2 -->|"decrypts"| node_crypto
node_v3 -->|"decrypts"| node_crypto
node_v1 -->|"decompresses"| node_zstd
node_v2 -->|"decompresses"| node_zstd
node_v3 -->|"decompresses"| node_zstd
node_crypto -->|"uses implementations"| node_deps
node_zstd -->|"uses zstd"| node_deps

click node_cmake "https://github.com/openysm/ysmparser/blob/main/CMakeLists.txt"
click node_release "https://github.com/openysm/ysmparser/blob/main/.github/workflows/release.yml"
click node_cli "https://github.com/openysm/ysmparser/blob/main/YSMParser/main.cpp"
click node_java "https://github.com/openysm/ysmparser/blob/main/java/com/ysm/parser/YSMParser.java"
click node_web "https://github.com/openysm/ysmparser/blob/main/web/app.js"
click node_jni "https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserJNI.cpp"
click node_facade "https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParser.cpp"
click node_reader "https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/BufferReader.hpp"
click node_errors "https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/exceptions/ParserException.hpp"
click node_v1 "https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserV1.cpp"
click node_v2 "https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserV2.cpp"
click node_v3 "https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/v3/YSMParserV3.cpp"
click node_crypto "https://github.com/openysm/ysmparser/blob/main/YSMParser/algorithms/CryptoAlgorithms.cpp"
click node_zstd "https://github.com/openysm/ysmparser/blob/main/YSMParser/algorithms/YsmZstd.hpp"
click node_platform "https://github.com/openysm/ysmparser/blob/main/YSMParser/platform/PlatformCompat.hpp"
click node_deps "https://github.com/openysm/ysmparser/blob/main/external/AES/src/AES.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_cmake,node_release toneBlue
class node_cli,node_java,node_web,node_jni toneAmber
class node_facade,node_reader,node_errors toneMint
class node_v1,node_v2,node_v3 toneRose
class node_crypto,node_zstd,node_platform,node_deps toneIndigo
```

## Components

### Build & Delivery

- [CMake targets](https://github.com/openysm/ysmparser/blob/main/CMakeLists.txt): build orchestration · Builds native and Emscripten/WASM targets. · `CMakeLists.txt`
- [Release workflow](https://github.com/openysm/ysmparser/blob/main/.github/workflows/release.yml): CI delivery · `.github/workflows/release.yml`

### Consumer Hosts

- [Native CLI](https://github.com/openysm/ysmparser/blob/main/YSMParser/main.cpp): C++ entry point · Batch-converts .ysm files from input directories. · `YSMParser/main.cpp`
- [Java API](https://github.com/openysm/ysmparser/blob/main/java/com/ysm/parser/YSMParser.java): Java consumer API · `java/com/ysm/parser/YSMParser.java`
- [Browser wrapper](https://github.com/openysm/ysmparser/blob/main/web/app.js): web host · `web/app.js`
- [JNI adapters](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserJNI.cpp): native interop · Exposes parser and algorithm capabilities to Java. · `YSMParser/parsers/YSMParserJNI.cpp`

### Parser Core

- [Parser facade](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParser.cpp): dispatch API · Selects a format decoder and returns restored project output. · `YSMParser/parsers/YSMParser.cpp`
- [Buffer reader](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/BufferReader.hpp): binary reader · `YSMParser/parsers/BufferReader.hpp`
- [Parser errors](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/exceptions/ParserException.hpp): error boundary · `YSMParser/parsers/exceptions/ParserException.hpp`

### Versioned Decoders

- [V1 decoder](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserV1.cpp): format parser · `YSMParser/parsers/YSMParserV1.cpp`
- [V2 decoder](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/YSMParserV2.cpp): format parser · `YSMParser/parsers/YSMParserV2.cpp`
- [V3 decoder](https://github.com/openysm/ysmparser/blob/main/YSMParser/parsers/v3/YSMParserV3.cpp): format parser · Interprets headers and extracts player textures before reconstruction. · `YSMParser/parsers/v3/YSMParserV3.cpp`

### Shared Native Services

- [Crypto algorithms](https://github.com/openysm/ysmparser/blob/main/YSMParser/algorithms/CryptoAlgorithms.cpp): crypto service · Centralizes cipher and key-derivation operations. · `YSMParser/algorithms/CryptoAlgorithms.cpp`
- [Zstd wrapper](https://github.com/openysm/ysmparser/blob/main/YSMParser/algorithms/YsmZstd.hpp): compression service · `YSMParser/algorithms/YsmZstd.hpp`
- [Platform compatibility](https://github.com/openysm/ysmparser/blob/main/YSMParser/platform/PlatformCompat.hpp): portability layer · `YSMParser/platform/PlatformCompat.hpp`
- [Vendored codecs](https://github.com/openysm/ysmparser/blob/main/external/AES/src/AES.cpp): native dependencies · Bundled AES, XChaCha20, zstd, image, hash, and JSON implementations. · `external/AES/src/AES.cpp`

## Connections

- Release workflow → CMake targets: builds releases
- CMake targets → Native CLI: builds native
- CMake targets → Browser wrapper: builds WASM host
- CMake targets → Platform compatibility: selects targets
- Native CLI → Parser facade: converts batch inputs
- Java API → JNI adapters: calls native
- JNI adapters → Parser facade: invokes parser
- Browser wrapper → Parser facade: uses WASM core
- Parser facade → V1 decoder: dispatches V1
- Parser facade → V2 decoder: dispatches V2
- Parser facade → V3 decoder: dispatches V3
- Parser facade → Parser errors: reports failures
- V1 decoder → Buffer reader: reads bytes
- V2 decoder → Buffer reader: reads bytes
- V3 decoder → Buffer reader: reads bytes
- V1 decoder → Crypto algorithms: decrypts
- V2 decoder → Crypto algorithms: decrypts
- V3 decoder → Crypto algorithms: decrypts
- V1 decoder → Zstd wrapper: decompresses
- V2 decoder → Zstd wrapper: decompresses
- V3 decoder → Zstd wrapper: decompresses
- Crypto algorithms → Vendored codecs: uses implementations
- Zstd wrapper → Vendored codecs: uses zstd
