# rajeshmk/string-utils architecture

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

- Interactive diagram: https://gitdiagram.com/rajeshmk/string-utils
- Repository: https://github.com/rajeshmk/string-utils

## Overview

1. This is a small PHP 8.3 library package, not an application. The architecture is centered on two static utility classes under `src/`: `StrTo` for string normalization/manipulation and `Hash` for monotonic unique hash generation.

2. The public API is intentionally narrow:
   - `Hatchyu\String\StrTo` exposes slugging, casing, path conversion, and UTF-8 substring helpers.
   - `Hatchyu\String\Hash` exposes `uniqueHash()`.
   Consumers call these stateless-looking helpers directly; there is no service container, controller layer, database, or HTTP boundary.

3. `StrTo` is the main subsystem and likely contains the package’s core string-processing pipeline. Its job is to take technical or identifier-like input and normalize it into different output formats: slug, snake, kebab, dotted, headline/title case, StudlyCase, camelCase, upper/lower, and first-letter variants.

4. The slugging pipeline is the key architectural behavior. According to the README, it does more than simple delimiter replacement: it recognizes camelCase/StudlyCase boundaries, acronym boundaries, number-to-word transitions, punctuation like `@`, and path-like separators. The output is word-preserving and separator-aware rather than a flattened transliteration.

5. Compound words are an important internal boundary in `StrTo`. `setCompoundWords()` changes package-wide static state for the current PHP process, so slugging behavior can be globally altered for brand/domain-specific terms such as `MySQL`, `iPhone`, or `GraphQL`. This means the library has one mutable configuration axis, and all other helpers likely read from that shared list.

6. Unicode handling is a second major concern in `StrTo`. The README explicitly makes `ext-intl` optional but recommended for transliteration. That means the architecture has a portability fallback: basic splitting/formatting works without intl, while ASCII transliteration quality improves when intl is available. This materially affects output for non-Latin scripts and accented text.

7. `StrTo::dotPath()` is a distinct path-normalization helper, not just another alias. It converts slash-separated or namespace-like paths into dot notation while kebab-casing segments. That suggests the library is useful for code identifiers, file-like paths, and config-style dotted keys, not only for SEO slugs.

8. The casing helpers form a separate transformation family from slugging. `words()`/`headline()` preserve technical tokens better than generic title-casing, while `studly()` and `camel()` likely reuse the same tokenization engine and then reassemble tokens with casing rules. This reuse is an important diagram point: one tokenization core feeding multiple output formats.

9. `Hash` is independent from `StrTo` except for package namespace and utility style. Its `uniqueHash($length = 40)` produces a time-derived, monotonic identifier with random padding and a minimum length constraint of 24. Architecturally, this is a separate data path from string normalization and likely has no dependency on transliteration or compound-word rules.

10. There is no external infrastructure. No database, queue, cache, filesystem persistence, or network service is described. The only runtime dependency that materially changes behavior is PHP itself plus optional `ext-intl`.

11. The `tests/` directory contains PHPUnit coverage for both major subsystems: `StrToTest.php` and `HashTest.php`. These tests are the behavioral contract for the library’s normalization rules, edge cases, and hash length/uniqueness guarantees. For architecture, they function as executable specification rather than integration tests.

12. The repository shape is conventional Composer packaging: `composer.json` defines the library metadata and autoloading, `phpunit.xml.dist` defines the test runner config, and `README.md` documents the API and examples. The package is designed to be embedded into other PHP codebases as a utility dependency, with static state being the main caveat.

13. If you are drawing the architecture diagram, the clearest boundaries are:
   - External caller → `StrTo` public API
   - `StrTo` tokenization/formatting core → output format helpers
   - optional `setCompoundWords()` configuration → all subsequent `StrTo` transforms
   - External caller → `Hash::uniqueHash()` → time/random-based string output
   - PHPUnit tests validating both public surfaces

Main entry points: [`src/StrTo.php`](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php) (StrTo), [`src/Hash.php`](https://github.com/rajeshmk/string-utils/blob/main/src/Hash.php) (Hash), [`composer.json`](https://github.com/rajeshmk/string-utils/blob/main/composer.json) (composer.json), [`phpunit.xml.dist`](https://github.com/rajeshmk/string-utils/blob/main/phpunit.xml.dist) (phpunit.xml)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_public["Public API"]
  node_n_strto["StrTo<br/>string utility<br/>[StrTo.php]"]
  node_n_hash["Hash<br/>[Hash.php]"]
  node_n_tokenize(("Tokenize<br/>splitter core<br/>[StrTo.php]"))
  node_n_compounds["Compound Words<br/>static config<br/>[StrTo.php]"]
  node_n_translit(("Transliterate<br/>unicode fallback<br/>[StrTo.php]"))
  node_n_slug(("Slug<br/>separator format<br/>[StrTo.php]"))
  node_n_paths(("Dot Path<br/>path format<br/>[StrTo.php]"))
  node_n_case(("Casing<br/>case transforms<br/>[StrTo.php]"))
  node_n_words(("Words<br/>text formatting<br/>[StrTo.php]"))
  node_n_camel(("Camel/Studly<br/>identifier format<br/>[StrTo.php]"))
  node_n_utf8(("UTF-8 Substrings<br/>unicode helpers<br/>[StrTo.php]"))
  node_n_uniquehash["uniqueHash<br/>identifier generator<br/>[Hash.php]"]
end

subgraph group_g_support["Package Support"]
  node_n_intl{{"ext-intl<br/>optional extension"}}
  node_n_composer["composer.json<br/>package metadata<br/>[composer.json]"]
  node_n_phpunit["phpunit.xml<br/>test config<br/>[phpunit.xml.dist]"]
  node_n_readme["README<br/>documentation<br/>[README.md]"]
end

subgraph group_g_tests["Tests"]
  node_n_strtotest["StrToTest<br/>unit tests<br/>[StrToTest.php]"]
  node_n_hashtest["HashTest<br/>unit tests<br/>[HashTest.php]"]
end

node_n_php{{"PHP 8.3<br/>runtime"}}

node_n_php -->|"runs on"| node_n_strto
node_n_php -->|"runs on"| node_n_hash
node_n_strto -->|"uses"| node_n_tokenize
node_n_strto -->|"reads"| node_n_compounds
node_n_strto -->|"optionally uses"| node_n_translit
node_n_tokenize -->|"feeds"| node_n_slug
node_n_tokenize -->|"feeds"| node_n_paths
node_n_tokenize -->|"feeds"| node_n_case
node_n_tokenize -->|"feeds"| node_n_words
node_n_case -->|"specializes"| node_n_camel
node_n_case -->|"uses"| node_n_utf8
node_n_strto -->|"exposes"| node_n_utf8
node_n_hash -->|"exposes"| node_n_uniquehash
node_n_intl -->|"enhances"| node_n_translit
node_n_composer -->|"autoloads"| node_n_strto
node_n_composer -->|"autoloads"| node_n_hash
node_n_phpunit -->|"runs"| node_n_strtotest
node_n_phpunit -->|"runs"| node_n_hashtest
node_n_strtotest -->|"validates"| node_n_strto
node_n_hashtest -->|"validates"| node_n_uniquehash
node_n_readme -->|"documents"| node_n_strto
node_n_readme -->|"documents"| node_n_hash

click node_n_strto "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_hash "https://github.com/rajeshmk/string-utils/blob/main/src/Hash.php"
click node_n_tokenize "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_compounds "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_translit "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_slug "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_paths "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_case "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_words "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_camel "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_utf8 "https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php"
click node_n_uniquehash "https://github.com/rajeshmk/string-utils/blob/main/src/Hash.php"
click node_n_composer "https://github.com/rajeshmk/string-utils/blob/main/composer.json"
click node_n_phpunit "https://github.com/rajeshmk/string-utils/blob/main/phpunit.xml.dist"
click node_n_readme "https://github.com/rajeshmk/string-utils/blob/main/README.md"
click node_n_strtotest "https://github.com/rajeshmk/string-utils/blob/main/tests/StrToTest.php"
click node_n_hashtest "https://github.com/rajeshmk/string-utils/blob/main/tests/HashTest.php"

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_n_strto,node_n_hash,node_n_tokenize,node_n_compounds,node_n_translit,node_n_slug,node_n_paths,node_n_case,node_n_words,node_n_camel,node_n_utf8,node_n_uniquehash toneBlue
class node_n_intl,node_n_composer,node_n_phpunit,node_n_readme toneAmber
class node_n_strtotest,node_n_hashtest toneMint
class node_n_php toneNeutral
```

## Components

### Public API

Stateless helper classes consumed directly by package users.

- [StrTo](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): string utility · Main string normalization and formatting API. · `src/StrTo.php`
- [Hash](https://github.com/rajeshmk/string-utils/blob/main/src/Hash.php): hash utility · Monotonic unique hash generator. · `src/Hash.php`
- [Tokenize](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): splitter core · Detects word boundaries in identifiers, acronyms, numbers, punctuation, and path-like input. · `src/StrTo.php`
- [Compound Words](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): static config · Package-wide mutable compound-word list that changes slug and casing behavior. · `src/StrTo.php`
- [Transliterate](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): unicode fallback · Optional intl-backed normalization for accented and non-Latin text. · `src/StrTo.php`
- [Slug](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): separator format · Builds separator-aware slugs from normalized tokens. · `src/StrTo.php`
- [Dot Path](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): path format · Converts slash or namespace-like paths into dot notation with kebab-cased segments. · `src/StrTo.php`
- [Casing](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): case transforms · Reassembles tokens as snake, kebab, dotted, headline, title, studly, camel, upper, lower, and first-letter variants. · `src/StrTo.php`
- [Words](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): text formatting · Token-preserving word formatting used by headline/title-style helpers. · `src/StrTo.php`
- [Camel/Studly](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): identifier format · Identifier-style output built from shared tokenization and casing rules. · `src/StrTo.php`
- [UTF-8 Substrings](https://github.com/rajeshmk/string-utils/blob/main/src/StrTo.php): unicode helpers · Multibyte-safe substring helpers for string slicing. · `src/StrTo.php`
- [uniqueHash](https://github.com/rajeshmk/string-utils/blob/main/src/Hash.php): identifier generator · Time-derived monotonic identifier with random padding and minimum length enforcement. · `src/Hash.php`

### Package Support

Composer metadata, documentation, and test runner configuration.

- **ext-intl**: optional extension · Improves transliteration quality when available.
- [composer.json](https://github.com/rajeshmk/string-utils/blob/main/composer.json): package metadata · Defines package metadata and autoloading. · `composer.json`
- [phpunit.xml](https://github.com/rajeshmk/string-utils/blob/main/phpunit.xml.dist): test config · Configures the PHPUnit test runner. · `phpunit.xml.dist`
- [README](https://github.com/rajeshmk/string-utils/blob/main/README.md): documentation · Documents API behavior, examples, and optional dependencies. · `README.md`

### Tests

Executable specification for the public API behavior.

- [StrToTest](https://github.com/rajeshmk/string-utils/blob/main/tests/StrToTest.php): unit tests · Covers string normalization, tokenization, and formatting behavior. · `tests/StrToTest.php`
- [HashTest](https://github.com/rajeshmk/string-utils/blob/main/tests/HashTest.php): unit tests · Covers unique hash length and uniqueness behavior. · `tests/HashTest.php`

### Other components

- **PHP 8.3**: runtime · Primary language runtime for the library.

## Connections

- PHP 8.3 → StrTo: runs on · StrTo executes within the PHP runtime.
- PHP 8.3 → Hash: runs on · Hash executes within the PHP runtime.
- StrTo → Tokenize: uses · Shared tokenization engine feeds most transforms.
- StrTo → Compound Words: reads · Compound-word state alters normalization results.
- StrTo → Transliterate: optionally uses · Unicode transliteration improves when ext-intl is present.
- Tokenize → Slug: feeds · Token boundaries are reassembled into slug output.
- Tokenize → Dot Path: feeds · Path segments are normalized before dot-path output.
- Tokenize → Casing: feeds · The same tokens are reused across casing variants.
- Tokenize → Words: feeds · Word formatting preserves technical tokens from the core splitter.
- Casing → Camel/Studly: specializes · Camel and Studly are identifier-oriented case outputs.
- Casing → UTF-8 Substrings: uses · Multibyte-safe slicing supports character-aware helpers.
- StrTo → UTF-8 Substrings: exposes · UTF-8 substring helpers are part of the public API.
- Hash → uniqueHash: exposes · uniqueHash is the single public entry point.
- ext-intl → Transliterate: enhances · Optional extension improves transliteration quality.
- composer.json → StrTo: autoloads · Composer metadata exposes the library classes.
- composer.json → Hash: autoloads · Composer metadata exposes the library classes.
- phpunit.xml → StrToTest: runs · PHPUnit configuration runs StrTo coverage.
- phpunit.xml → HashTest: runs · PHPUnit configuration runs Hash coverage.
- StrToTest → StrTo: validates · Tests document and lock the public string API.
- HashTest → uniqueHash: validates · Tests document and lock hash output guarantees.
- README → StrTo: documents · README describes normalization and casing helpers.
- README → Hash: documents · README describes unique hash generation.
