# steamre/steamkit architecture

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

- Interactive diagram: https://gitdiagram.com/steamre/steamkit
- Repository: https://github.com/steamre/steamkit

## Overview

##### Project type and purpose
- Project type: an open-source, modular .NET library (SteamKit2) for interfacing with Valve’s Steam network.
- Purpose: expose a simple, extensible API for .NET applications to authenticate, send/receive protocol messages, and consume Steam WebAPI endpoints.

##### High-level architectural components
a. Consumer Application (your code or sample apps)
b. SteamKit2 Library
- Core API (SteamClient)
- Message Definitions (Base/Generated)
- Protocol Handlers (Steam/Handlers)
- Networking Layer (Networking/Steam3)
- WebAPI Client (Steam/WebAPI)
- Supporting Modules
- Types (SteamIDs, Manifests, JobIDs, etc.)
- Utilities (Crypto, LZMA, Logging, Helpers)
c. External Dependencies
- .NET 8.0 Runtime
- Protobuf (for message serialization)
- Steam network endpoints (TCP, UDP, WebSocket)

##### Component relationships and data flow
- The Consumer App instantiates SteamClient (Core API).
- SteamClient uses Configuration → CallbackMgr → AsyncJobManager.
- SteamClient dispatches/receives ClientMsg through Protocol Handlers.
- Handlers package/unpackage messages defined in Base/Generated (Protobuf).
- Serialized messages flow into Networking Layer which manages connections (TCP/UDP/WebSocket) to Steam servers.
- Responses traverse back up: Networking → Deserialization → Handler callbacks → Consumer callbacks.
- WebAPI Client component can be invoked directly by Consumer or by SteamClient for HTTP REST calls.

##### Key architectural patterns and design principles
- Modular layering: clear separation of Core API, Message Definitions, Handlers, Networking, and Utils.
- Plug-in style extensibility: add new handlers under Steam/Handlers without modifying core.
- Asynchronous job/callback model: AsyncJobManager and CallbackMgr decouple network I/O from application logic.
- Generated code for protocol messages (Protobuf) ensures consistency and reduces manual coding.
- Dependency injection points: configuration builders, machine info providers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer Application
    Samples["Consumer Application\n(Samples)"]:::external
    click Samples "https://github.com/steamre/steamkit/tree/master/Samples/"

    %% SteamKit2 Library cluster
    subgraph "SteamKit2 Library"
        direction TB
        SteamClient["SteamClient\n(Core API)"]:::core
        click SteamClient "https://github.com/steamre/steamkit/blob/master/SteamKit2/SteamKit2/Steam/SteamClient/SteamClient.cs"

        CallbackMgr["CallbackMgr"]:::core
        click CallbackMgr "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Steam/SteamClient/CallbackMgr/"

        AsyncJobManager["AsyncJobManager"]:::core
        click AsyncJobManager "https://github.com/steamre/steamkit/blob/master/SteamKit2/SteamKit2/Steam/SteamClient/AsyncJobManager.cs"

        subgraph "Protocol Handlers"
            direction TB
            ProtocolHandlers["Handlers"]:::core
            click ProtocolHandlers "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Steam/Handlers/"
        end

        subgraph "Message Definitions"
            direction TB
            Base["Base"]:::generated
            click Base "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Base/"
            Generated["Generated"]:::generated
            click Generated "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Base/Generated/"
        end

        subgraph "Networking Layer"
            direction TB
            Networking["Steam3\n(TCP/UDP/WS)"]:::core
            click Networking "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Networking/Steam3/"
        end

        WebAPI["WebAPI Client"]:::core
        click WebAPI "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Steam/WebAPI/"

        Types["Types"]:::support
        click Types "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Types/"

        Utils["Utilities"]:::support
        click Utils "https://github.com/steamre/steamkit/tree/master/SteamKit2/SteamKit2/Util/"
    end

    %% External Systems
    subgraph "Valve Steam Network"
        direction TB
        SteamNetTCP["TCP Endpoint"]:::external
        SteamNetUDP["UDP Endpoint"]:::external
        SteamNetWS["WebSocket Endpoint"]:::external
    end

    subgraph "External Dependencies"
        direction TB
        DotNet[".NET 8.0 Runtime"]:::external
        Protobuf["Protobuf"]:::external
    end

    %% Connections
    Samples -->|"Instantiate/Call"| SteamClient
    SteamClient -->|"uses"| CallbackMgr
    SteamClient -->|"uses"| AsyncJobManager
    SteamClient -->|"routes messages to"| ProtocolHandlers
    ProtocolHandlers -->|"serialize/unpack messages"| Base
    ProtocolHandlers -->|"serialize/unpack messages"| Generated
    ProtocolHandlers -->|"Serialize/Send EMsg"| Networking
    Networking -->|"Send over"| SteamNetTCP
    Networking -->|"Send over"| SteamNetUDP
    Networking -->|"Send over"| SteamNetWS
    SteamNetTCP -->|"Receive"| Networking
    SteamNetUDP -->|"Receive"| Networking
    SteamNetWS -->|"Receive"| Networking
    Networking -->|"Deserialize"| ProtocolHandlers
    ProtocolHandlers -->|"Invoke Callback"| CallbackMgr
    CallbackMgr -->|"App Callback"| Samples
    Samples -->|"HTTP GET/POST"| WebAPI
    SteamClient -->|"invoke REST"| WebAPI
    WebAPI -->|"HTTP(S)"| SteamNetWS

    %% Support usage
    SteamClient -.->|"uses types/utilities"| Types
    ProtocolHandlers -.->|"uses types/utilities"| Utils

    %% External deps
    SteamClient -.-> DotNet
    ProtocolHandlers -.-> Protobuf

    %% Styles
    classDef core fill:#E0F3FF,stroke:#007ACC,stroke-width:2px,color:#000
    classDef support fill:#E8F5E9,stroke:#388E3C,stroke-width:2px,color:#000
    classDef external fill:#FFF3E0,stroke:#F57C00,stroke-width:2px,color:#000
    classDef generated fill:#F5F5F5,stroke:#9E9E9E,stroke-width:2px,color:#000
```
