# google/brotli architecture

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

- Interactive diagram: https://gitdiagram.com/google/brotli
- Repository: https://github.com/google/brotli

## Overview

##### Project type and purpose
- This is an open-source, multi-language compression library implementing the Brotli algorithm (RFC 7932).
- It provides a high-performance core in C (encode/decode), a command-line tool, fuzz & research harnesses, and language bindings (C#, Java, Go, JS, Python).

##### File structure
- Top-level:
- BUILD.bazel, CMakeLists.txt, scripts/ → build & install (Bazel, CMake, scripts for pkgconfig)
- c/ → core C implementation, subdivided into common/, enc/, dec/
- c/include/brotli/ → public C API headers
- c/tools/ → brotli CLI tool based on the core
- c/fuzz/ → fuzzing harness targeting the C core
- research/ → experimental tools, dumps, generators
- {csharp, java, go, js, python}/ → language wrappers & pure-language ports
- tests/ → compatibility & round-trip tests for the C core and testdata
- Each language folder contains its own BUILD/MODULE files (Bazel), tests, and binding code.

##### README
- Confirms Brotli’s algorithmic building blocks (LZ77 variant, Huffman, context modeling).
- Lists build instructions (vcpkg, Bazel, CMake, pip).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & CI
    subgraph "Build & CI"
        BUILD["BUILD.bazel"]:::build
        CMAKE["CMakeLists.txt"]:::build
        Scripts["scripts/"]:::build
        GH[".github/workflows/"]:::build
    end

    %% Core Engine
    subgraph "Brotli C Core"
        Common["common/"]:::core
        Enc["enc/"]:::core
        Dec["dec/"]:::core
        API["include/brotli/"]:::core
    end

    %% Tools
    CLI["CLI Tool (brotli)"]:::tool
    Fuzz["Fuzz Harness"]:::tool
    Research["Research Tools"]:::tool

    %% Bindings & Ports
    subgraph "Bindings & Ports"
        CSharp["C# Pure Port"]:::wrapper
        JavaPure["Java Pure Port"]:::wrapper
        JavaJNI["Java JNI Wrapper"]:::wrapper
        GoPure["Go Pure Port"]:::wrapper
        GoCGO["Go cgo Wrapper"]:::wrapper
        JS["JS/TS Port"]:::wrapper
        Python["Python Extension & Pure"]:::wrapper
    end

    %% Tests
    TestsC["C Core Tests"]:::test

    %% Relationships
    BUILD -->|"builds"|Common
    CMAKE -->|"builds"|Common
    Scripts -->|"builds"|Common
    GH -->|"builds"|Common

    CLI -->|"uses API"|API
    Fuzz -->|"drives"|API
    Research -->|"depends on"|API

    CSharp -->|"calls API"|API
    JavaPure -->|"reimplements"|Enc
    JavaPure -->|"reimplements"|Dec
    JavaJNI -->|"JNI bridge to"|API
    GoPure -->|"reimplements"|Enc
    GoPure -->|"reimplements"|Dec
    GoCGO -->|"cgo bridge to"|API
    JS -->|"pure implementation"|Enc
    JS -->|"pure implementation"|Dec
    Python -->|"C-API bridge to"|API

    TestsC -->|"tests"|API

    %% Click Events
    click Common "https://github.com/google/brotli/tree/master/c/common/"
    click Enc "https://github.com/google/brotli/tree/master/c/enc/"
    click Dec "https://github.com/google/brotli/tree/master/c/dec/"
    click API "https://github.com/google/brotli/tree/master/c/include/brotli/"
    click BUILD "https://github.com/google/brotli/blob/master/BUILD.bazel"
    click CMAKE "https://github.com/google/brotli/blob/master/CMakeLists.txt"
    click Scripts "https://github.com/google/brotli/tree/master/scripts/"
    click GH "https://github.com/google/brotli/tree/master/.github/workflows/"
    click CLI "https://github.com/google/brotli/blob/master/c/tools/brotli.c"
    click Fuzz "https://github.com/google/brotli/tree/master/c/fuzz/"
    click Research "https://github.com/google/brotli/tree/master/research/"
    click CSharp "https://github.com/google/brotli/tree/master/csharp/org/brotli/dec/"
    click JavaPure "https://github.com/google/brotli/tree/master/java/org/brotli/dec/"
    click JavaJNI "https://github.com/google/brotli/tree/master/java/org/brotli/wrapper/"
    click GoPure "https://github.com/google/brotli/tree/master/go/brotli/"
    click GoCGO "https://github.com/google/brotli/tree/master/go/cbrotli/"
    click JS "https://github.com/google/brotli/tree/master/js/"
    click Python "https://github.com/google/brotli/blob/master/python/_brotli.c"
    click TestsC "https://github.com/google/brotli/tree/master/tests/"

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:1px;
    classDef wrapper fill:#9f9,stroke:#333,stroke-width:1px;
    classDef tool fill:#ff9,stroke:#333,stroke-width:1px;
    classDef build fill:#9ff,stroke:#333,stroke-width:1px;
    classDef test fill:#f99,stroke:#333,stroke-width:1px;
```
