# doctrine/inflector architecture

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

- Interactive diagram: https://gitdiagram.com/doctrine/inflector
- Repository: https://github.com/doctrine/inflector

## Overview

Doctrine Inflector is a PHP library for word singularization/pluralization and related string formatting. A caller selects a language factory (or configures one directly), builds an Inflector, and invokes transformations such as singularize or pluralize. The runtime combines language-specific regular, irregular, and uninflected rules, with general-purpose transformations and an optional cache. Language rule directories define the supported linguistic behavior. Edges reflect the shown excerpts, source-index references, or README; unsampled implementation details are not inferred.

Main entry points: [`src/Rules`](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules) (Rule Primitives), [`src/Inflector.php`](https://github.com/doctrine/inflector/blob/2.1.x/src/Inflector.php) (String Inflector), [`src/GenericLanguageInflectorFactory.php`](https://github.com/doctrine/inflector/blob/2.1.x/src/GenericLanguageInflectorFactory.php) (Generic Factory), [`src/WordInflector.php`](https://github.com/doctrine/inflector/blob/2.1.x/src/WordInflector.php) (Word Inflector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_public_factory["Inflector Factory"]
  node_language["Language<br/>[Language.php]"]
  node_language_factory["Language Factory"]
  node_generic_factory["Generic Factory"]
  node_inflector["String Inflector<br/>[Inflector.php]"]
  node_cache["Cached Inflector"]
  node_noop["No-op Inflector"]
end

subgraph group_engine["Inflection Engine"]
  node_word_interface["Word Inflector<br/>[WordInflector.php]"]
  node_ruleset_inflector["Ruleset Inflector"]
  node_ruleset["Ruleset<br/>[Ruleset.php]"]
  node_rule_primitives["Rule Primitives"]
end

subgraph group_languages["Language Rules"]
  node_english_rules["English Rules"]
  node_esperanto_rules["Esperanto Rules"]
  node_french_rules["French Rules"]
  node_italian_rules["Italian Rules"]
  node_norwegian_rules["Norwegian Bokmål Rules"]
  node_portuguese_rules["Portuguese Rules"]
  node_spanish_rules["Spanish Rules"]
  node_turkish_rules["Turkish Rules"]
end

node_caller(("Library Caller"))

node_caller -->|"requests inflector"| node_public_factory
node_public_factory -->|"selects language"| node_language
node_public_factory -->|"creates factory"| node_language_factory
node_generic_factory -->|"implements"| node_language_factory
node_generic_factory -->|"builds"| node_ruleset_inflector
node_generic_factory -->|"builds"| node_inflector
node_generic_factory -->|"wraps inflector"| node_cache
node_caller -->|"inflects words"| node_inflector
node_inflector -->|"delegates singular/plural"| node_word_interface
node_cache -->|"implements"| node_word_interface
node_noop -->|"implements"| node_word_interface
node_ruleset_inflector -->|"uses rules"| node_ruleset
node_ruleset_inflector -->|"implements"| node_word_interface
node_ruleset -->|"contains rule sets"| node_rule_primitives
node_english_rules -->|"defines transformations"| node_rule_primitives
node_esperanto_rules -->|"defines transformations"| node_rule_primitives
node_french_rules -->|"defines transformations"| node_rule_primitives
node_italian_rules -->|"defines transformations"| node_rule_primitives
node_norwegian_rules -->|"defines transformations"| node_rule_primitives
node_portuguese_rules -->|"defines transformations"| node_rule_primitives
node_spanish_rules -->|"defines transformations"| node_rule_primitives
node_turkish_rules -->|"defines transformations"| node_rule_primitives
node_english_rules -->|"provides English rules"| node_inflector
node_italian_rules -->|"provides Italian rules"| node_inflector

click node_public_factory "https://github.com/doctrine/inflector/blob/2.1.x/src/InflectorFactory.php"
click node_language "https://github.com/doctrine/inflector/blob/2.1.x/src/Language.php"
click node_language_factory "https://github.com/doctrine/inflector/blob/2.1.x/src/LanguageInflectorFactory.php"
click node_generic_factory "https://github.com/doctrine/inflector/blob/2.1.x/src/GenericLanguageInflectorFactory.php"
click node_inflector "https://github.com/doctrine/inflector/blob/2.1.x/src/Inflector.php"
click node_cache "https://github.com/doctrine/inflector/blob/2.1.x/src/CachedWordInflector.php"
click node_noop "https://github.com/doctrine/inflector/blob/2.1.x/src/NoopWordInflector.php"
click node_word_interface "https://github.com/doctrine/inflector/blob/2.1.x/src/WordInflector.php"
click node_ruleset_inflector "https://github.com/doctrine/inflector/blob/2.1.x/src/RulesetInflector.php"
click node_ruleset "https://github.com/doctrine/inflector/blob/2.1.x/src/Rules/Ruleset.php"
click node_rule_primitives "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules"
click node_english_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/English"
click node_esperanto_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Esperanto"
click node_french_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/French"
click node_italian_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Italian"
click node_norwegian_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/NorwegianBokmal"
click node_portuguese_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Portuguese"
click node_spanish_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Spanish"
click node_turkish_rules "https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Turkish"

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_public_factory,node_language,node_language_factory,node_generic_factory,node_inflector,node_cache,node_noop toneBlue
class node_word_interface,node_ruleset_inflector,node_ruleset,node_rule_primitives toneAmber
class node_english_rules,node_esperanto_rules,node_french_rules,node_italian_rules,node_norwegian_rules,node_portuguese_rules,node_spanish_rules,node_turkish_rules toneMint
class node_caller toneIndigo
```

## Components

### Public API

- [Inflector Factory](https://github.com/doctrine/inflector/blob/2.1.x/src/InflectorFactory.php): `src/InflectorFactory.php`
- [Language](https://github.com/doctrine/inflector/blob/2.1.x/src/Language.php): `src/Language.php`
- [Language Factory](https://github.com/doctrine/inflector/blob/2.1.x/src/LanguageInflectorFactory.php): `src/LanguageInflectorFactory.php`
- [Generic Factory](https://github.com/doctrine/inflector/blob/2.1.x/src/GenericLanguageInflectorFactory.php): `src/GenericLanguageInflectorFactory.php`
- [String Inflector](https://github.com/doctrine/inflector/blob/2.1.x/src/Inflector.php): `src/Inflector.php`
- [Cached Inflector](https://github.com/doctrine/inflector/blob/2.1.x/src/CachedWordInflector.php): `src/CachedWordInflector.php`
- [No-op Inflector](https://github.com/doctrine/inflector/blob/2.1.x/src/NoopWordInflector.php): `src/NoopWordInflector.php`

### Inflection Engine

- [Word Inflector](https://github.com/doctrine/inflector/blob/2.1.x/src/WordInflector.php): `src/WordInflector.php`
- [Ruleset Inflector](https://github.com/doctrine/inflector/blob/2.1.x/src/RulesetInflector.php): `src/RulesetInflector.php`
- [Ruleset](https://github.com/doctrine/inflector/blob/2.1.x/src/Rules/Ruleset.php): `src/Rules/Ruleset.php`
- [Rule Primitives](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules): `src/Rules`

### Language Rules

- [English Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/English): `src/Rules/English`
- [Esperanto Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Esperanto): `src/Rules/Esperanto`
- [French Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/French): `src/Rules/French`
- [Italian Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Italian): `src/Rules/Italian`
- [Norwegian Bokmål Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/NorwegianBokmal): `src/Rules/NorwegianBokmal`
- [Portuguese Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Portuguese): `src/Rules/Portuguese`
- [Spanish Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Spanish): `src/Rules/Spanish`
- [Turkish Rules](https://github.com/doctrine/inflector/tree/2.1.x/src/Rules/Turkish): `src/Rules/Turkish`

### Other components

- **Library Caller**

## Connections

- Library Caller → Inflector Factory: requests inflector
- Inflector Factory → Language: selects language (evidence: `src/InflectorFactory.php`)
- Inflector Factory → Language Factory: creates factory (evidence: `src/InflectorFactory.php`)
- Generic Factory → Language Factory: implements (evidence: `src/GenericLanguageInflectorFactory.php`)
- Generic Factory → Ruleset Inflector: builds (evidence: `src/GenericLanguageInflectorFactory.php`)
- Generic Factory → String Inflector: builds (evidence: `src/GenericLanguageInflectorFactory.php`)
- Generic Factory → Cached Inflector: wraps inflector (evidence: `src/GenericLanguageInflectorFactory.php`)
- Library Caller → String Inflector: inflects words (evidence: `README.md`)
- String Inflector → Word Inflector: delegates singular/plural (evidence: `src/Inflector.php`)
- Cached Inflector → Word Inflector: implements (evidence: `src/CachedWordInflector.php`)
- No-op Inflector → Word Inflector: implements (evidence: `src/NoopWordInflector.php`)
- Ruleset Inflector → Ruleset: uses rules (evidence: `src/RulesetInflector.php`)
- Ruleset Inflector → Word Inflector: implements (evidence: `src/RulesetInflector.php`)
- Ruleset → Rule Primitives: contains rule sets (evidence: `src/Rules/Ruleset.php`)
- English Rules → Rule Primitives: defines transformations (evidence: `src/Rules/English/Rules.php`)
- Esperanto Rules → Rule Primitives: defines transformations (evidence: `src/Rules/Esperanto/Rules.php`)
- French Rules → Rule Primitives: defines transformations (evidence: `src/Rules/French/Rules.php`)
- Italian Rules → Rule Primitives: defines transformations (evidence: `src/Rules/Italian/Rules.php`)
- Norwegian Bokmål Rules → Rule Primitives: defines transformations (evidence: `src/Rules/NorwegianBokmal/Rules.php`)
- Portuguese Rules → Rule Primitives: defines transformations (evidence: `src/Rules/Portuguese/Rules.php`)
- Spanish Rules → Rule Primitives: defines transformations (evidence: `src/Rules/Spanish/Rules.php`)
- Turkish Rules → Rule Primitives: defines transformations (evidence: `src/Rules/Turkish/Rules.php`)
- English Rules → String Inflector: provides English rules (evidence: `src/Rules/English/Inflectible.php`)
- Italian Rules → String Inflector: provides Italian rules (evidence: `src/Rules/Italian/Inflectible.php`)
