# google/ngx_brotli architecture

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

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

## Overview

ngx_brotli adds two response-serving capabilities to Nginx: dynamic Brotli compression and delivery of pre-compressed `.br` files. In the dynamic path, Nginx response filtering checks request eligibility and configured compression settings, then uses the Brotli encoder; in the static path, the module checks eligibility, reads a compressed file, and prepares the response. The excerpts show these paths and filesystem access, while the README documents the user-facing capabilities and directives; wiring details beyond that evidence are omitted.

Main entry points: [`filter/ngx_http_brotli_filter_module.c`](https://github.com/google/ngx_brotli/blob/master/filter/ngx_http_brotli_filter_module.c) (Brotli filter), [`static/ngx_http_brotli_static_module.c`](https://github.com/google/ngx_brotli/blob/master/static/ngx_http_brotli_static_module.c) (Static handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dynamic["Dynamic compression"]
  node_filter["Brotli filter"]
  node_encoder["Brotli encoder"]
end

subgraph group_static["Static delivery"]
  node_static_module["Static handler"]
  node_files[("Compressed files")]
end

node_client(("HTTP client"))
node_nginx["Nginx HTTP"]

node_client -->|"sends request"| node_nginx
node_nginx -->|"filters responses"| node_filter
node_filter -->|"compresses with"| node_encoder
node_filter -->|"passes response"| node_nginx
node_nginx -->|"serves files via"| node_static_module
node_static_module -->|"reads &#96;.br&#96; file"| node_files
node_static_module -->|"sends compressed response"| node_client

click node_filter "https://github.com/google/ngx_brotli/blob/master/filter/ngx_http_brotli_filter_module.c"
click node_static_module "https://github.com/google/ngx_brotli/blob/master/static/ngx_http_brotli_static_module.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_filter,node_encoder,node_client toneBlue
class node_static_module,node_files toneAmber
class node_nginx toneIndigo
```

## Components

### Dynamic compression

- [Brotli filter](https://github.com/google/ngx_brotli/blob/master/filter/ngx_http_brotli_filter_module.c): `filter/ngx_http_brotli_filter_module.c`
- **Brotli encoder**

### Static delivery

- [Static handler](https://github.com/google/ngx_brotli/blob/master/static/ngx_http_brotli_static_module.c): `static/ngx_http_brotli_static_module.c`
- **Compressed files**

### Other components

- **HTTP client**
- **Nginx HTTP**

## Connections

- HTTP client → Nginx HTTP: sends request (evidence: `README.md`)
- Nginx HTTP → Brotli filter: filters responses (evidence: `README.md`)
- Brotli filter → Brotli encoder: compresses with (evidence: `filter/ngx_http_brotli_filter_module.c`)
- Brotli filter → Nginx HTTP: passes response (evidence: `filter/ngx_http_brotli_filter_module.c`)
- Nginx HTTP → Static handler: serves files via (evidence: `README.md`)
- Static handler → Compressed files: reads `.br` file (evidence: `static/ngx_http_brotli_static_module.c`)
- Static handler → HTTP client: sends compressed response (evidence: `static/ngx_http_brotli_static_module.c`)
