# dustinlacewell/steamworks-ts architecture

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

- Interactive diagram: https://gitdiagram.com/dustinlacewell/steamworks-ts
- Repository: https://github.com/dustinlacewell/steamworks-ts

## Overview

##### Project type and purpose
- This is a language‐binding library: a NodeJS package (“steamworks-ts”) that provides TypeScript‐typed bindings to Valve’s Steamworks SDK.
- It’s built in Rust (via the `steamworks-rs` crate) and exposed to NodeJS through the N-API using `napi-rs`. Consumers call into the native addon from JavaScript/TypeScript.

##### File structure
Top-level:
- Cargo.toml, build.rs, src/… → Rust code defining the Steamworks wrapper
- index.js, index.d.ts → JS/TS entry points to the compiled native addon
- npm/… → folder of prebuilt binaries per platform (darwin, linux, win32)
- bin/build.ts → custom build script to orchestrate the Rust → .node build and packaging
- app/… and examples/… → sample TypeScript apps showing how to use the module
- .github/workflows → CI pipelines for build & docs

##### README for additional insights
- Confirms that you need Rust+NodeJS toolchains
- Describes build command producing `steamworks-ts.<platform>-<arch>.node`
- Mentions Steam’s `steam_appid.txt` mechanism, external dependency to the Steam client

##### Main components & interactions
a. Rust Library Layer
- `src/lib.rs` plus submodules (`friends.rs`, `ugc/...`)
- Depends on `steamworks-rs` (external crate binding to Steamworks SDK)
b. Build & N-API Layer
- `build.rs` and `napi-rs` code glue that compiles Rust to a `.node` addon
- `bin/build.ts` orchestrates cross-platform builds and packaging into npm/… directories
c. NodeJS Module Interface
- `index.js` (CommonJS wrapper)
- `index.d.ts` (TypeScript definitions)
d. Distribution Artifacts
- Prebuilt binaries under npm/darwin-x64, linux-x64-gnu, win32-x64-msvc
- Published to NPM as `@ldlework/steamworks-ts`
e. Consumer Code
- Example apps under `app/` and `examples/`
- They import `SteamClient` from the package and invoke Steamworks API methods
f. External Dependencies
- Steamworks SDK dynamic libs (.dll, .dylib) loaded at runtime
- The Steam client (via `steam_appid.txt`)

##### Architectural patterns & design principles
- Layered architecture:
1. Native Rust layer (interfaces Steamworks SDK)
2. N-API binding layer (napi-rs)
3. JavaScript API surface (index.js + .d.ts)
4. Consumer layer (TS/JS apps)
- Packaging/multi-target distribution: precompilation per platform
- Separation of concerns: Rust modules for feature areas (friends, ugc, errors)

##### Detail
- CI workflows (build.yml, docs.yml) optionally as external automation
- `steam_appid.txt` file creation and warning path in examples

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Rust Library Layer
    subgraph "Rust Wrapper Layer"
        direction TB
        RL1["lib.rs"]:::rust
        RL2["errors.rs"]:::rust
        RL3["friends.rs"]:::rust
        subgraph "ugc Module"
            direction TB
            U1["mod.rs"]:::rust
            U2["query.rs"]:::rust
            U3["query_item.rs"]:::rust
            U4["query_user.rs"]:::rust
            U5["subscribe_item.rs"]:::rust
            U6["unsubscribe_item.rs"]:::rust
            U7["types.rs"]:::rust
        end
    end

    %% Build & N-API Layer
    subgraph "Build & N-API Layer"
        direction TB
        B1["build.rs"]:::rust
        B2["bin/build.ts"]:::js
        B1 --> B2
    end

    %% NodeJS Module Interface
    subgraph "NodeJS Module Interface"
        direction TB
        N1["index.js"]:::js
        N2["index.d.ts"]:::ts
    end

    %% Distribution Artifacts
    subgraph "Distribution Artifacts"
        direction TB
        D1["darwin-x64"]:::dist
        D2["linux-x64-gnu"]:::dist
        D3["win32-x64-msvc"]:::dist
    end

    %% Consumer Code
    subgraph "Consumer Applications"
        direction TB
        C1["app/src/main.ts"]:::ts
        C2["app/test-package.ts"]:::ts
        subgraph "Examples"
            direction TB
            E1["friends_info.ts"]:::ts
            E2["query_user.ts"]:::ts
            E3["user_info.ts"]:::ts
            E4["workshop/download.ts"]:::ts
            E5["workshop/invalid_workshop_item.ts"]:::ts
            E6["workshop/sub.ts"]:::ts
            E7["workshop/subscriptions.ts"]:::ts
            E8["workshop/unsub.ts"]:::ts
            E9["workshop/workshop_item_details.ts"]:::ts
        end
    end

    %% CI Workflows
    subgraph "CI Workflows"
        direction TB
        CI1["build.yml"]:::ext
        CI2["docs.yml"]:::ext
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        EX1["Steamworks SDK"]:::ext
        EX2["Steam Client"]:::ext
    end

    %% Build Pipeline Flow
    RL1 -->|"uses steamworks-rs"| B1
    RL2 --> B1
    RL3 --> B1
    U1 --> B1
    U2 --> B1
    U3 --> B1
    U4 --> B1
    U5 --> B1
    U6 --> B1
    U7 --> B1
    B1 -->|"napi-rs binding"| B2
    B2 -->|"produces .node binary"| D1
    B2 --> D2
    B2 --> D3
    CI1 --> B2
    CI2 --> CI1

    %% Runtime Flow
    C1 -->|"import SteamClient"| N1
    C2 --> N1
    E1 --> N1
    E2 --> N1
    E3 --> N1
    E4 --> N1
    E5 --> N1
    E6 --> N1
    E7 --> N1
    E8 --> N1
    E9 --> N1
    N1 -->|"calls N-API"| B2
    B2 -->|"executes Rust code"| RL1
    RL1 -->|"calls Steamworks API"| EX1
    EX1 -->|"requires steam_appid.txt"| EX2

    %% Distribution links
    D1 -->|"contains binaries & libs"| D1
    D2 --> D2
    D3 --> D3

    %% Click Events
    click RL1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/lib.rs"
    click RL2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/errors.rs"
    click RL3 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/friends.rs"
    click U1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/ugc/mod.rs"
    click U2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/ugc/query.rs"
    click U3 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/ugc/query_item.rs"
    click U4 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/ugc/query_user.rs"
    click U5 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/ugc/subscribe_item.rs"
    click U6 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/ugc/unsubscribe_item.rs"
    click U7 "https://github.com/dustinlacewell/steamworks-ts/blob/main/src/ugc/types.rs"
    click B1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/build.rs"
    click B2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/bin/build.ts"
    click N1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/index.js"
    click N2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/index.d.ts"
    click D1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/npm/darwin-x64/package.json"
    click D1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/npm/darwin-x64/libsteam_api.dylib"
    click D2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/npm/linux-x64-gnu/package.json"
    click D3 "https://github.com/dustinlacewell/steamworks-ts/blob/main/npm/win32-x64-msvc/package.json"
    click D3 "https://github.com/dustinlacewell/steamworks-ts/blob/main/npm/win32-x64-msvc/steam_api64.lib"
    click C1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/app/src/main.ts"
    click C2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/app/test-package.ts"
    click E1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/friends_info.ts"
    click E2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/query_user.ts"
    click E3 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/user_info.ts"
    click E4 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/workshop/download.ts"
    click E5 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/workshop/invalid_workshop_item.ts"
    click E6 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/workshop/sub.ts"
    click E7 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/workshop/subscriptions.ts"
    click E8 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/workshop/unsub.ts"
    click E9 "https://github.com/dustinlacewell/steamworks-ts/blob/main/examples/workshop/workshop_item_details.ts"
    click CI1 "https://github.com/dustinlacewell/steamworks-ts/blob/main/.github/workflows/build.yml"
    click CI2 "https://github.com/dustinlacewell/steamworks-ts/blob/main/.github/workflows/docs.yml"

    %% Styles
    classDef rust fill:#f0dbdb,stroke:#da3e52,color:#000;
    classDef js fill:#def,stroke:#5a9, color:#000;
    classDef ts fill:#ccf,stroke:#347, color:#000;
    classDef dist fill:#ffd,stroke:#fa0, color:#000;
    classDef ext fill:#efe,stroke:#393, color:#000;
```
