# ch-jack/fxap_only architecture

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

- Interactive diagram: https://gitdiagram.com/ch-jack/fxap_only
- Repository: https://github.com/ch-jack/fxap_only

## Overview

#### Purpose and Entry Point
FXAP Decryptor is a Node.js 18+ CLI for decrypting authorized FiveM FXAP resources, copying plaintext assets, and optionally decompiling Lua bytecode and repairing selected model vertex data. The executable entry point is `index.js`; orchestration implementation is centered in `src/decryptor.js`.

#### CLI Orchestration and Resource Discovery
Argument handling supports optional CFX Key, resource/root directory, Java path, and `--vertex-fix`. The tool discovers either a single FXAP-containing resource or multiple child resources, writes output beside the input as `<name>_decrypted`, and aggregates resource/file outcomes into documented exit codes.
Paths: `index.js`, `src/discover.js`, `src/decryptor.js`.

#### Key Acquisition Boundary
Key material is resolved per FXAP resource ID. An optional CFX Key is validated through official Cfx.re Keymaster; valid keys are imported into the grants service. Missing local `grants` or `grants_clk` triggers a grants API lookup. Existing usable material permits continued processing if lookup fails.
Paths: `src/keymaster.js`, `src/grants-api.js`, `src/constants.js`.

#### Cloudflare Client-Key Derivation
Client-side encrypted content requires `grants_clk`. The repository delegates derivation to Cloudflare’s external `/v1/derive` endpoint and consumes its returned 32-byte key; the actual derivation algorithm is deliberately not local. API URLs and credentials can be overridden through environment variables.
Paths: `src/cloudflare-grants.js`, `src/crypto.js`, `.env.example`.

#### FXAP Parsing and Decryption Pipeline
The decryptor reads FXAP/resource metadata, obtains server grants and derived client keys, and decrypts standard FXAP and RSC stream paths while preserving directory layout. Non-encrypted files are copied. Per-file failures are separated from total resource failure so callers can distinguish partial output from failed resources.
Paths: `src/decryptor.js`, `src/crypto.js`, `src/constants.js`.

#### Lua Bytecode Post-Processing
After decryption, Lua 5.4 bytecode may be passed to the bundled `unluac54.jar` through an externally supplied or discovered Java runtime. Failure to find Java or decompile does not invalidate the decrypted artifact: `.luac` remains, with assembly output retained when available.
Paths: `src/java-decompiler.js`, `tools/unluac54.jar`, `src/decryptor.js`.

#### Optional Vertex-Fix Isolation
`--vertex-fix` operates only on fully decrypted FXAP resources. It creates a separate sibling copy of the decrypted output and invokes the packaged Windows/.NET 8 CLI against `.ydr`, `.yft`, and `.ydd` assets; it never overwrites the base decrypted directory.
Paths: `src/vertex-fixer.js`, `tools/vertex-fixer/FivemDecryptFixer.Cli.exe`, `src/decryptor.js`.

#### Distribution and Runtime Dependencies
There are no npm runtime dependencies. Required runtime is Node.js; Java is optional for Lua processing; .NET 8 is externally required for vertex fixing. GitHub Actions builds/tests/releases a component package consumed on demand by CK Free Toolbox, with release contents defined by the PowerShell build process and component manifest.
Paths: `component-manifest.json`, `tools/Build-Release.ps1`, `.github/workflows/release.yml`.

Main entry points: [`src/decryptor.js`](https://github.com/ch-jack/fxap_only/blob/main/src/decryptor.js) (Decryptor orchestrator), [`src/crypto.js`](https://github.com/ch-jack/fxap_only/blob/main/src/crypto.js) (Crypto pipeline), [`src/vertex-fixer.js`](https://github.com/ch-jack/fxap_only/blob/main/src/vertex-fixer.js) (Vertex-fix adapter), [`src/java-decompiler.js`](https://github.com/ch-jack/fxap_only/blob/main/src/java-decompiler.js) (Lua decompiler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI &amp; Discovery"]
  node_entry["CLI entry point<br/>Node.js CLI<br/>[index.js]"]
  node_discovery["Resource discovery<br/>resource scanner<br/>[discover.js]"]
end

subgraph group_keys["Key Resolution"]
  node_keymaster["Cfx.re Keymaster<br/>key validation client<br/>[keymaster.js]"]
  node_grants_api["Grants API<br/>remote grants client<br/>[grants-api.js]"]
  node_cloudflare["Cloudflare derive API<br/>external key derivation"]
end

subgraph group_pipeline["FXAP Processing"]
  node_orchestrator["Decryptor orchestrator<br/>processing coordinator<br/>[decryptor.js]"]
  node_crypto["Crypto pipeline<br/>FXAP/RSC decryptor<br/>[crypto.js]"]
  node_constants["Protocol constants<br/>shared definitions<br/>[constants.js]"]
  node_decrypted_output["Decrypted output<br/>resource directory"]
end

subgraph group_post["Optional Post-Processing"]
  node_java_decompiler["Lua decompiler<br/>Java subprocess adapter<br/>[java-decompiler.js]"]
  node_unluac["unluac54<br/>bundled JAR<br/>[unluac54.jar]"]
  node_java["Java runtime<br/>external runtime"]
  node_vertex_fixer["Vertex-fix adapter<br/>optional post-processor<br/>[vertex-fixer.js]"]
  node_fixer_cli["FivemDecryptFixer CLI<br/>packaged Windows CLI"]
  node_dotnet[".NET 8 runtime<br/>external runtime"]
  node_fixed_output["Vertex-fixed copy<br/>sibling resource directory"]
end

subgraph group_distribution["Distribution"]
  node_component_manifest["Component manifest<br/>package manifest"]
  node_release_build["Release build<br/>PowerShell packaging<br/>[Build-Release.ps1]"]
  node_release_workflow["Release workflow<br/>GitHub Actions<br/>[release.yml]"]
end

node_entry -->|"selects resources"| node_discovery
node_entry -->|"starts"| node_orchestrator
node_discovery -->|"resource inputs"| node_orchestrator
node_orchestrator -->|"optional CFX Key"| node_keymaster
node_keymaster -->|"imports validated key"| node_grants_api
node_orchestrator -->|"missing local grants lookup"| node_grants_api
node_orchestrator -->|"requests grants_clk key"| node_cloudflare
node_grants_api -->|"server grants"| node_crypto
node_cloudflare -->|"derived client key"| node_crypto
node_constants -->|"formats and metadata"| node_crypto
node_orchestrator -->|"file streams"| node_crypto
node_crypto -->|"decrypts or copies"| node_decrypted_output
node_decrypted_output -.->|"Lua bytecode"| node_java_decompiler
node_java_decompiler -->|"launches"| node_java
node_java_decompiler -->|"executes"| node_unluac
node_decrypted_output -.->|"fully decrypted only"| node_vertex_fixer
node_vertex_fixer -->|"invokes"| node_fixer_cli
node_vertex_fixer -->|"requires"| node_dotnet
node_vertex_fixer -->|"creates sibling copy"| node_fixed_output
node_release_workflow -->|"runs"| node_release_build
node_release_build -->|"packages per manifest"| node_component_manifest

click node_entry "https://github.com/ch-jack/fxap_only/blob/main/index.js"
click node_discovery "https://github.com/ch-jack/fxap_only/blob/main/src/discover.js"
click node_orchestrator "https://github.com/ch-jack/fxap_only/blob/main/src/decryptor.js"
click node_keymaster "https://github.com/ch-jack/fxap_only/blob/main/src/keymaster.js"
click node_grants_api "https://github.com/ch-jack/fxap_only/blob/main/src/grants-api.js"
click node_cloudflare "https://github.com/ch-jack/fxap_only/blob/main/src/cloudflare-grants.js"
click node_crypto "https://github.com/ch-jack/fxap_only/blob/main/src/crypto.js"
click node_constants "https://github.com/ch-jack/fxap_only/blob/main/src/constants.js"
click node_java_decompiler "https://github.com/ch-jack/fxap_only/blob/main/src/java-decompiler.js"
click node_unluac "https://github.com/ch-jack/fxap_only/blob/main/tools/unluac54.jar"
click node_vertex_fixer "https://github.com/ch-jack/fxap_only/blob/main/src/vertex-fixer.js"
click node_fixer_cli "https://github.com/ch-jack/fxap_only/blob/main/tools/vertex-fixer/FivemDecryptFixer.Cli.exe"
click node_component_manifest "https://github.com/ch-jack/fxap_only/blob/main/component-manifest.json"
click node_release_build "https://github.com/ch-jack/fxap_only/blob/main/tools/Build-Release.ps1"
click node_release_workflow "https://github.com/ch-jack/fxap_only/blob/main/.github/workflows/release.yml"

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_entry,node_discovery toneBlue
class node_keymaster,node_grants_api,node_cloudflare toneAmber
class node_orchestrator,node_crypto,node_constants,node_decrypted_output toneMint
class node_java_decompiler,node_unluac,node_java,node_vertex_fixer,node_fixer_cli,node_dotnet,node_fixed_output toneRose
class node_component_manifest,node_release_build,node_release_workflow toneIndigo
```

## Components

### CLI & Discovery

- [CLI entry point](https://github.com/ch-jack/fxap_only/blob/main/index.js): Node.js CLI · `index.js`
- [Resource discovery](https://github.com/ch-jack/fxap_only/blob/main/src/discover.js): resource scanner · Finds one FXAP resource or child resources. · `src/discover.js`

### Key Resolution

- [Cfx.re Keymaster](https://github.com/ch-jack/fxap_only/blob/main/src/keymaster.js): key validation client · Validates and imports an optional CFX Key. · `src/keymaster.js`
- [Grants API](https://github.com/ch-jack/fxap_only/blob/main/src/grants-api.js): remote grants client · Looks up missing grants material by resource ID. · `src/grants-api.js`
- [Cloudflare derive API](https://github.com/ch-jack/fxap_only/blob/main/src/cloudflare-grants.js): external key derivation · Returns the 32-byte client key; derivation is not local. · `src/cloudflare-grants.js`

### FXAP Processing

- [Decryptor orchestrator](https://github.com/ch-jack/fxap_only/blob/main/src/decryptor.js): processing coordinator · Aggregates resource and file outcomes into exit codes. · `src/decryptor.js`
- [Crypto pipeline](https://github.com/ch-jack/fxap_only/blob/main/src/crypto.js): FXAP/RSC decryptor · Decrypts encrypted streams and copies plaintext files. · `src/crypto.js`
- [Protocol constants](https://github.com/ch-jack/fxap_only/blob/main/src/constants.js): shared definitions · `src/constants.js`
- **Decrypted output**: resource directory · Written beside input as <name>_decrypted.

### Optional Post-Processing

- [Lua decompiler](https://github.com/ch-jack/fxap_only/blob/main/src/java-decompiler.js): Java subprocess adapter · Keeps .luac when Java discovery or decompilation fails. · `src/java-decompiler.js`
- [unluac54](https://github.com/ch-jack/fxap_only/blob/main/tools/unluac54.jar): bundled JAR · `tools/unluac54.jar`
- **Java runtime**: external runtime · Supplied or discovered for Lua post-processing.
- [Vertex-fix adapter](https://github.com/ch-jack/fxap_only/blob/main/src/vertex-fixer.js): optional post-processor · Runs only after a fully decrypted resource succeeds. · `src/vertex-fixer.js`
- [FivemDecryptFixer CLI](https://github.com/ch-jack/fxap_only/blob/main/tools/vertex-fixer/FivemDecryptFixer.Cli.exe): packaged Windows CLI · Repairs .ydr, .yft, and .ydd assets. · `tools/vertex-fixer/FivemDecryptFixer.Cli.exe`
- **.NET 8 runtime**: external runtime
- **Vertex-fixed copy**: sibling resource directory · Separate copy; never overwrites decrypted output.

### Distribution

- [Component manifest](https://github.com/ch-jack/fxap_only/blob/main/component-manifest.json): package manifest · `component-manifest.json`
- [Release build](https://github.com/ch-jack/fxap_only/blob/main/tools/Build-Release.ps1): PowerShell packaging · Defines release contents. · `tools/Build-Release.ps1`
- [Release workflow](https://github.com/ch-jack/fxap_only/blob/main/.github/workflows/release.yml): GitHub Actions · Builds, tests, and releases the component package. · `.github/workflows/release.yml`

## Connections

- CLI entry point → Resource discovery: selects resources
- CLI entry point → Decryptor orchestrator: starts
- Resource discovery → Decryptor orchestrator: resource inputs
- Decryptor orchestrator → Cfx.re Keymaster: optional CFX Key
- Cfx.re Keymaster → Grants API: imports validated key
- Decryptor orchestrator → Grants API: missing local grants lookup
- Decryptor orchestrator → Cloudflare derive API: requests grants_clk key
- Grants API → Crypto pipeline: server grants
- Cloudflare derive API → Crypto pipeline: derived client key
- Protocol constants → Crypto pipeline: formats and metadata
- Decryptor orchestrator → Crypto pipeline: file streams
- Crypto pipeline → Decrypted output: decrypts or copies
- Decrypted output → Lua decompiler: Lua bytecode
- Lua decompiler → Java runtime: launches
- Lua decompiler → unluac54: executes
- Decrypted output → Vertex-fix adapter: fully decrypted only
- Vertex-fix adapter → FivemDecryptFixer CLI: invokes
- Vertex-fix adapter → .NET 8 runtime: requires
- Vertex-fix adapter → Vertex-fixed copy: creates sibling copy
- Release workflow → Release build: runs
- Release build → Component manifest: packages per manifest
