# florrain/locale architecture

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

- Interactive diagram: https://gitdiagram.com/florrain/locale
- Repository: https://github.com/florrain/locale

## Overview

`locale` is a small Node.js library for choosing a locale from an HTTP request’s `Accept-Language` header. Its main workflow parses the request and supported locales, selects the best match, and attaches that result to the request for downstream middleware. The same module also exposes Locale and Locales APIs for standalone use. Runtime relationships are supported by the excerpted `lib/index.js`; the README documents standalone and Express/Connect use.

Main entry points: [`lib/index.js`](https://github.com/florrain/locale/blob/master/lib/index.js) (Locale middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_request(("HTTP request"))
node_middleware["Locale middleware<br/>[index.js]"]
node_locales["Locales parser<br/>[index.js]"]
node_matcher["Best-match selector<br/>[index.js]"]
node_locale["Locale value<br/>[index.js]"]
node_downstream(("Downstream handler"))

node_request -->|"provides header"| node_middleware
node_middleware -->|"parses header"| node_locales
node_middleware -->|"parses supported"| node_locales
node_locales -->|"constructs tags"| node_locale
node_middleware -->|"selects match"| node_matcher
node_matcher -->|"checks supported"| node_locales
node_matcher -->|"uses fallback"| node_locale
node_middleware -->|"sets locale"| node_request
node_middleware -->|"calls next"| node_downstream

click node_middleware "https://github.com/florrain/locale/blob/master/lib/index.js"
click node_locales "https://github.com/florrain/locale/blob/master/lib/index.js"
click node_matcher "https://github.com/florrain/locale/blob/master/lib/index.js"
click node_locale "https://github.com/florrain/locale/blob/master/lib/index.js"

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_request,node_downstream toneMint
class node_middleware,node_locales,node_matcher,node_locale toneTeal
```

## Components

### Other components

- **HTTP request**
- [Locale middleware](https://github.com/florrain/locale/blob/master/lib/index.js): `lib/index.js`
- [Locales parser](https://github.com/florrain/locale/blob/master/lib/index.js): `lib/index.js`
- [Best-match selector](https://github.com/florrain/locale/blob/master/lib/index.js): `lib/index.js`
- [Locale value](https://github.com/florrain/locale/blob/master/lib/index.js): `lib/index.js`
- **Downstream handler**

## Connections

- HTTP request → Locale middleware: provides header (evidence: `lib/index.js`)
- Locale middleware → Locales parser: parses header (evidence: `lib/index.js`)
- Locale middleware → Locales parser: parses supported (evidence: `lib/index.js`)
- Locales parser → Locale value: constructs tags (evidence: `lib/index.js`)
- Locale middleware → Best-match selector: selects match (evidence: `lib/index.js`)
- Best-match selector → Locales parser: checks supported (evidence: `lib/index.js`)
- Best-match selector → Locale value: uses fallback (evidence: `lib/index.js`)
- Locale middleware → HTTP request: sets locale (evidence: `lib/index.js`)
- Locale middleware → Downstream handler: calls next (evidence: `lib/index.js`)
