# square/okio architecture

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

- Interactive diagram: https://gitdiagram.com/square/okio
- Repository: https://github.com/square/okio

## Overview

##### Project type and purpose
- This is a Kotlin Multiplatform library (not an application) named Okio.
- Purpose: provide a modern, multiplatform abstraction over byte streams, file systems, and buffers to complement java.io and java.nio.
- It consists of a core API plus multiple platform‐specific implementations (JVM, JS, native, Android, WASI, Node.js, assets, fake filesystems), testing harnesses, benchmarks, and samples.

##### File structure
- Top‐level build & infra:
– Gradle wrapper & settings (gradle/, gradlew, settings.gradle.kts, libs.versions.toml)
– build-support module: helper code to generate BOMs, coordinate targets, share version logic
– .github workflows, .buildscript for docs and release
- Core module “okio”:
– src/commonMain: core interfaces (Buffer, ByteString, FileSystem, Path, Source, Sink, Timeout…)
– src/{jvm,js,native,…}Main: platform‐specific extensions & implementations
– src/commonTest & src/{jvm,js,native,…}Test: unit tests
- Platform modules:
– okio-fakefilesystem: in-memory FileSystem for testing
– okio-assetfilesystem: Android assets FS
– okio-nodefilesystem: Node.js FS adapter
– okio-wasifilesystem: WASI FS adapter
– okio-testing-support: reusable test fixtures & helpers for file systems
- Auxiliary modules:
– okio-bom: Bill of Materials for dependency management
– kotlin-js-store: ? (likely sample or plugin for JS)
– android-test: integration tests on Android
– samples: example code illustrating library usage
– jvm/jmh: benchmarks module

##### README for additional insights
- Confirms this is a library for data I/O, originally part of OkHttp.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure Layer
    subgraph "Infrastructure" 
        direction TB
        GS["gradlew"]:::infra
        GB["gradlew.bat"]:::infra
        GV["gradle/libs.versions.toml"]:::infra
        BSup["build-support"]:::infra
        DOCS["docs/ & .buildscript"]:::infra
        MK["mkdocs.yml"]:::infra
        CI[".github/workflows"]:::infra
    end

    %% BOM Module
    subgraph "BOM Module" 
        direction TB
        BOM["okio-bom"]:::infra
    end

    %% Core API Module
    subgraph "Core API Module" 
        direction TB
        Core["okio (Core API)"]:::core
        CM["okio/src/commonMain"]:::core
        CT["okio/src/commonTest"]:::test
    end

    %% Core JVM Implementation
    subgraph "Core JVM Implementation" 
        direction TB
        JVMI["okio/src/jvmMain"]:::platform
        JVT["okio/src/jvmTest"]:::test
    end

    %% Core JS Implementation
    subgraph "Core JS Implementation" 
        direction TB
        JSI["okio/src/jsMain"]:::platform
        NJS["okio/src/nonJsMain"]:::platform
    end

    %% Core Native Implementation
    subgraph "Core Native Implementation" 
        direction TB
        NI["okio/src/nativeMain"]:::platform
        NT["okio/src/nativeTest"]:::test
    end

    %% Platform Filesystems
    subgraph "Filesystem Implementations" 
        direction TB
        FakeFS["okio-fakefilesystem"]:::platform
        AssetFS["okio-assetfilesystem"]:::platform
        NodeFS["okio-nodefilesystem"]:::platform
        WasiFS["okio-wasifilesystem"]:::platform
    end

    %% Testing Support
    subgraph "Testing & Samples" 
        direction TB
        TestSup["okio-testing-support"]:::test
        AndroidT["android-test"]:::test
        Samples["samples"]:::samples
        Bench["okio/jvm/jmh"]:::samples
    end

    %% Relationships
    GS -->|triggers build| Core
    GS -->|triggers build| JVMI
    GS -->|triggers build| JSI
    GS -->|triggers build| NI
    GS -->|triggers build| FakeFS
    GS -->|triggers build| AssetFS
    GS -->|triggers build| NodeFS
    GS -->|triggers build| WasiFS
    GS -->|triggers build| TestSup
    GS -->|triggers build| AndroidT
    GS -->|triggers build| Samples
    GS -->|triggers build| Bench
    BSup -->|provides version info| Core
    BSup -->|provides version info| JVMI
    BSup -->|provides version info| JSI
    BSup -->|provides version info| NI
    BSup -->|provides version info| FakeFS
    BSup -->|provides version info| AssetFS
    BSup -->|provides version info| NodeFS
    BSup -->|provides version info| WasiFS
    Core -->|expect/actual implementation| JVMI
    Core -->|expect/actual implementation| JSI
    Core -->|expect/actual implementation| NI
    Core -->|uses| FakeFS
    Core -->|uses| AssetFS
    Core -->|uses| NodeFS
    Core -->|uses| WasiFS
    TestSup -->|tests| Core
    TestSup -->|tests| FakeFS
    TestSup -->|tests| AssetFS
    AndroidT -->|integration tests| AssetFS
    Samples -->|depends on| Core
    Samples -->|depends on| JVMI
    Bench -->|benchmarks| JVMI
    BOM -->|aggregates versions| Core
    BOM -->|aggregates versions| JVMI
    BOM -->|aggregates versions| JSI
    BOM -->|aggregates versions| NI
    BOM -->|aggregates versions| FakeFS
    BOM -->|aggregates versions| AssetFS
    BOM -->|aggregates versions| NodeFS
    BOM -->|aggregates versions| WasiFS

    %% Click Events
    click GS "https://github.com/square/okio/tree/master/gradlew"
    click GB "https://github.com/square/okio/blob/master/gradlew.bat"
    click GV "https://github.com/square/okio/blob/master/gradle/libs.versions.toml"
    click BSup "https://github.com/square/okio/tree/master/build-support/"
    click Core "https://github.com/square/okio/blob/master/okio/build.gradle.kts"
    click CM "https://github.com/square/okio/tree/master/okio/src/commonMain/kotlin/okio/"
    click CT "https://github.com/square/okio/tree/master/okio/src/commonTest/"
    click JVMI "https://github.com/square/okio/tree/master/okio/src/jvmMain/kotlin/okio/"
    click JVT "https://github.com/square/okio/tree/master/okio/src/jvmTest/"
    click JSI "https://github.com/square/okio/tree/master/okio/src/jsMain/kotlin/okio/"
    click NJS "https://github.com/square/okio/tree/master/okio/src/nonJsMain/"
    click NI "https://github.com/square/okio/tree/master/okio/src/nativeMain/kotlin/okio/"
    click NT "https://github.com/square/okio/tree/master/okio/src/nativeTest/"
    click FakeFS "https://github.com/square/okio/blob/master/okio-fakefilesystem/build.gradle.kts"
    click AssetFS "https://github.com/square/okio/blob/master/okio-assetfilesystem/build.gradle.kts"
    click NodeFS "https://github.com/square/okio/blob/master/okio-nodefilesystem/build.gradle.kts"
    click WasiFS "https://github.com/square/okio/blob/master/okio-wasifilesystem/build.gradle.kts"
    click TestSup "https://github.com/square/okio/blob/master/okio-testing-support/build.gradle.kts"
    click AndroidT "https://github.com/square/okio/tree/master/android-test/"
    click Samples "https://github.com/square/okio/blob/master/samples/build.gradle.kts"
    click Bench "https://github.com/square/okio/blob/master/okio/jvm/jmh/build.gradle.kts"
    click BOM "https://github.com/square/okio/blob/master/okio-bom/build.gradle.kts"
    click DOCS "https://github.com/square/okio/tree/master/docs/"
    click MK "https://github.com/square/okio/blob/master/mkdocs.yml"
    click CI "https://github.com/square/okio/tree/master/.github/workflows/"

    %% Styles
    classDef infra fill:#cccccc,stroke:#333,stroke-width:1px;
    classDef core fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef platform fill:#90ee90,stroke:#333,stroke-width:1px;
    classDef test fill:#ffcc99,stroke:#333,stroke-width:1px;
    classDef samples fill:#ffa500,stroke:#333,stroke-width:1px;
```
