# jac3km4/redscript architecture

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

- Interactive diagram: https://gitdiagram.com/jac3km4/redscript
- Repository: https://github.com/jac3km4/redscript

## Overview

##### Project type and purpose
- This is an open-source compiler toolchain for REDscript (a statically-typed game-scripting language for CD Projekt’s REDengine).
- It provides several sub-tools (compiler, decompiler, formatter, CLI driver, C API, file I/O, etc.) all implemented as Rust crates in a single monorepository.

##### File structure
- Top-level “crates” directory groups individual Rust libraries and executables:
- `cli` – unified command-line entry point
- `compiler/{frontend,backend,api}` – parsing, static analysis → IR → bytecode
- `decompiler` – bytecode → REDscript source
- `syntax/{parser,ast,formatter}` – language grammar, AST definitions, code formatting
- `io` – reading/writing native REDengine binary files
- `scc/{cli,capi,core}` – drop-in replacement compiler (CLI and C API)
- `dotfile` – `.redscript` config parser
- `code-edit` – source‐level transformation utilities
- Build and CI configured via Cargo.toml files, GitHub workflows, and OS-specific asset directories.

##### Insights from the README
- Key patterns:
- Modular micro-crates for single responsibility (parser, AST, formatter).
- Layered compiler architecture (frontend → IR → backend).
- Dual entry points: Rust CLI and C API (`scc/capi`).
- Shared core logic in `scc/core` for both capi and cli.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Entry Points"
        CLI["CLI Driver"]:::entry
        SCC_CLI["SCC CLI"]:::entry
        SCC_C_API["SCC C API"]:::entry
    end

    subgraph "Configuration"
        Dotfile["Dotfile Parser"]:::syntax
    end

    subgraph "Syntax Layer"
        Parser["Syntax Parser"]:::syntax
        AST["Syntax AST"]:::syntax
        Formatter["Syntax Formatter"]:::syntax
    end

    subgraph "Compiler Pipeline"
        FE["Compiler Frontend"]:::compiler
        FE_IR["Frontend IR"]:::compiler
        BE["Compiler Backend"]:::compiler
        Assemble["Backend Assembly"]:::compiler
        API["Compiler API"]:::compiler
    end

    subgraph "I/O & Decompiler"
        IO["I/O Layer"]:::io
        Decomp["Decompiler"]:::io
    end

    subgraph "SCC Toolchain"
        SCC_Core["SCC Core"]:::scc
    end

    subgraph "Utilities"
        CodeEdit["Code-Edit Utilities"]:::compiler
    end

    subgraph "External Systems"
        UserIDE["User/IDE"]:::external
        Game["Game Engine Folder"]:::external
    end

    %% Data flows
    UserIDE -->|"invoke"| CLI
    UserIDE -->|"IDE integration"| API
    UserIDE -->|"use transformations"| CodeEdit
    CLI -->|"reads config"| Dotfile
    CLI -->|"parses source"| Parser
    Parser -->|"AST"| AST
    AST -->|"analysis"| FE
    FE -->|"generate IR"| FE_IR
    FE_IR -->|"IR"| BE
    BE -->|"produce bytecode"| Assemble
    Assemble -->|"bytecode"| IO
    IO -->|".reds files"| Game
    CLI -->|"decompile path"| IO
    IO -->|"read bytecode"| Decomp
    Decomp -->|"AST output"| AST
    AST -->|"format"| Formatter
    Formatter -->|"writes formatted source"| CLI

    SCC_CLI -->|"calls core"| SCC_Core
    SCC_C_API -->|"calls core"| SCC_Core
    SCC_Core -->|"uses I/O"| IO
    SCC_Core -->|"uses compiler API"| API

    CodeEdit -->|"transforms AST"| AST

    %% Click Events
    click CLI "https://github.com/jac3km4/redscript/blob/1.0.x/crates/cli/src/main.rs"
    click SCC_CLI "https://github.com/jac3km4/redscript/blob/1.0.x/crates/scc/cli/src/main.rs"
    click SCC_C_API "https://github.com/jac3km4/redscript/blob/1.0.x/crates/scc/capi/include/scc.h"
    click SCC_Core "https://github.com/jac3km4/redscript/blob/1.0.x/crates/scc/core/src/lib.rs"
    click Dotfile "https://github.com/jac3km4/redscript/blob/1.0.x/crates/dotfile/src/lib.rs"
    click Parser "https://github.com/jac3km4/redscript/blob/1.0.x/crates/syntax/parser/src/lib.rs"
    click AST "https://github.com/jac3km4/redscript/blob/1.0.x/crates/syntax/ast/src/ast.rs"
    click Formatter "https://github.com/jac3km4/redscript/blob/1.0.x/crates/syntax/formatter/src/lib.rs"
    click FE "https://github.com/jac3km4/redscript/blob/1.0.x/crates/compiler/frontend/src/lib.rs"
    click FE_IR "https://github.com/jac3km4/redscript/blob/1.0.x/crates/compiler/frontend/src/ir.rs"
    click BE "https://github.com/jac3km4/redscript/blob/1.0.x/crates/compiler/backend/src/lib.rs"
    click Assemble "https://github.com/jac3km4/redscript/blob/1.0.x/crates/compiler/backend/src/assemble.rs"
    click API "https://github.com/jac3km4/redscript/blob/1.0.x/crates/compiler/api/src/lib.rs"
    click Decomp "https://github.com/jac3km4/redscript/blob/1.0.x/crates/decompiler/src/decompiler.rs"
    click IO "https://github.com/jac3km4/redscript/blob/1.0.x/crates/io/src/lib.rs"
    click CodeEdit "https://github.com/jac3km4/redscript/blob/1.0.x/crates/code-edit/src/lib.rs"

    %% Styles
    classDef entry fill:#cce5ff,stroke:#000,stroke-width:1px
    classDef syntax fill:#ffe5b4,stroke:#000,stroke-width:1px
    classDef compiler fill:#d4edda,stroke:#000,stroke-width:1px
    classDef io fill:#f0e6fa,stroke:#000,stroke-width:1px
    classDef scc fill:#e2e3e5,stroke:#000,stroke-width:1px
    classDef external fill:#f8d7da,stroke:#000,stroke-width:1px
```
