# francisrstokes/super-expressive architecture

> Architecture diagram of the GitHub repository francisrstokes/super-expressive, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/francisrstokes/super-expressive
- Repository: https://github.com/francisrstokes/super-expressive

## Overview

##### Main Components and Architecture

a) Core Builder Component:
- Central SuperExpressive class/builder
- Immutable state management
- Method chain handling

b) API Layer:
- Flag methods (allowMultipleMatches, lineByLine, etc.)
- Pattern methods (anyChar, digit, word, etc.)
- Quantifier methods (exactly, between, oneOrMore, etc.)
- Grouping methods (capture, group, anyOf, etc.)

c) Transformation Layer:
- Regex string generation
- Final RegExp object creation

**┌─────────────────────────────────────────────────────────┐**
- Super Expressive                       │
- ┘

- ▼
**┌─────────────────────────────────────────────────────────┐**
- Builder Core                         │
- ┤
- State Management                                      │
- Method Chain Processing                              │
- Validation Logic                                     │
- ┘

- ┌────────────┴───────────┐
- ▼                        ▼
**┌────────────────────┐    ┌──────────────────────┐**
- API Layer      │    │  Transformation Layer │
- ┤    ├──────────────────────┤
- Flags           │    │ - toRegexString()     │
- Patterns        │    │ - toRegex()          │
- Quantifiers     │    └──────────────────────┘
- Groups          │
- ┘

##### Important Elements

a) Method Categories:
- Flag methods (caseInsensitive, unicode, etc.)
- Pattern methods (digit, word, anyChar, etc.)
- Quantifier methods (exactly, between, etc.)
- Methods (capture, anyOf, etc.)

b) Data Flow:
- How method calls build up the internal state
- How the final regex is generated

c) Key Features:
- Immutability
- Method chaining
- Validation
- TypeScript support

##### Additional Notes

- Notes about the lightweight nature (4kb minified + gzipped)
- Relationship with the final RegExp object
- TypeScript definition file integration

##### Implementation Details

- The builder pattern implementation
- The fluent interface design
- The transformation process from readable API to regex
- Error handling and validation flow

This design captures the essence of Super Expressive as a tool that transforms human-readable method chains into regular expressions, while maintaining a clean and maintainable architecture.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Main
        SE[Super Expressive]
    end

    subgraph BuilderCore
        direction TB
        BC[Builder Core]
        SM[State Management]
        MCP[Method Chain Processing]
        VL[Validation Logic]
        BC --> SM
        BC --> MCP
        BC --> VL
    end

    subgraph APILayer
        direction TB
        API[API Methods]
        FM[Flag Methods]
        PM[Pattern Methods]
        QM[Quantifier Methods]
        GM[Group Methods]
        API --> FM
        API --> PM
        API --> QM
        API --> GM
    end

    subgraph TransformationLayer
        direction TB
        TL[Transformation Logic]
        RS[toRegexString]
        RO[toRegex]
        TL --> RS
        TL --> RO
    end

    subgraph TestingLayer
        direction TB
        TEST[Testing & Validation]
        TC[Test Cases]
        VLD[Validation Rules]
        TEST --> TC
        TEST --> VLD
    end

    SE --> BC
    BC --> API
    BC --> TL
    BC --> TEST

    %% Component Mappings
    click SE "https://github.com/francisrstokes/super-expressive/blob/master/index.js"
    click BC "https://github.com/francisrstokes/super-expressive/blob/master/index.js"
    click API "https://github.com/francisrstokes/super-expressive/blob/master/index.js"
    click TL "https://github.com/francisrstokes/super-expressive/blob/master/index.js"
    click TEST "https://github.com/francisrstokes/super-expressive/blob/master/index.test.js"
    click TC "https://github.com/francisrstokes/super-expressive/blob/master/index.test.js"
    click VLD "https://github.com/francisrstokes/super-expressive/blob/master/.github/workflows/tests.yml"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef core fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef transform fill:#FFB347,stroke:#333,stroke-width:2px
    classDef test fill:#E6E6FA,stroke:#333,stroke-width:2px

    class SE,BC,SM,MCP,VL core
    class API,FM,PM,QM,GM api
    class TL,RS,RO transform
    class TEST,TC,VLD test

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[API Components]:::api
        L3[Transformation Components]:::transform
        L4[Testing Components]:::test
    end
```
