# swiftfiddle/swiftregex architecture

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

- Interactive diagram: https://gitdiagram.com/swiftfiddle/swiftregex
- Repository: https://github.com/swiftfiddle/swiftregex

## Overview

##### Project Type and Purpose
- Type: Full-stack single-page web application.
- Purpose: Provide an in-browser Swift Regex tester and debugger with syntax highlighting, DSL conversion, parsing, and matching.

##### File Structure
- Top-level “Public” folder: contains all static assets (HTML/CSS/JS).
- “webpack.*.js” + package.json: frontend build and bundling setup.
- Sources/App: Swift backend code—Router definitions (routes.swift), Middlewares, Models, Debugger, entrypoint.
- Sources/DSLConverter, ExpressionParser, Matcher: three Swift executables/library modules performing conversion, parsing, and matching.
- .github/workflows, Dockerfile: CI and deployment configurations.

##### Extract Architectural Patterns & Tech Stack (from README & files)
- HTTP server (likely Vapor or SwiftNIO) exposing REST endpoints.
- No external database—the state is ephemeral in memory.
- Frontend built with vanilla JS + webpack, organized into views, state, runner, worker modules.
- Docker for containerization; GitHub Actions for CI.

##### Main Components
a. Client (Browser SPA)
– Static host serving index.html, JS, CSS
– JS modules:
- Views & UI components (dsl_editor, expression_field, debugger_text, etc.)
- State management (encoder/decoder, worker)
- Runner module invokes HTTP APIs
b. HTTP Server (Swift App)
– Entry point & configuration (entrypoint.swift, configure.swift)
– Router (routes.swift)
– Middlewares (error handling, headers)
– Controllers/Handlers processing ExecRequest → ResultResponse
c. Core Processing Modules (Swift Libraries/Executables)
– DSLConverter
– ExpressionParser
– Matcher
– Debugger/Executor orchestrates multi-stage flow
d. DevOps & CI
– Docker container
– GitHub Actions workflows (code scanning, tests)

##### Relationships & Data Flow
1. User types regex or DSL in browser UI → frontend state.
2. Frontend “runner.js” packages input into JSON ExecRequest.
3. HTTP POST → /execute endpoint on Swift server.
4. Server router invokes Debugger/Executor
- Passes input to DSLConverter → yields Swift regex DSL
- Feeds DSL into ExpressionParser → builds AST
- Runs Matcher against target string → produces match results
5. ResultResponse JSON sent back to browser.
6. Frontend updates UI views, syntax highlighting, debugger panels.

##### Architectural Patterns & Principles
- Separation of Concerns:
– Frontend UI vs. backend logic vs. individual processing modules
- Modular Design: each regex stage is a standalone Swift component
- Middleware pipeline on server for cross-cutting concerns
- Single-page application served as static assets

##### Final Checklist
[ ] Frontend vs. Backend separation clearly shown
[ ] All Swift Modules (DSLConverter, ExpressionParser, Matcher, Debugger) included
[ ] Middlewares & Router depicted in the HTTP layer
[ ] Static asset serving pathway (Public folder → Browser)
[ ] DevOps components (Dockerfile, GitHub Actions) optionally represented

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        subgraph "Public/ (Static Assets)"
            HTML["index.html"]:::frontend
            CSS["css/"]:::frontend
            JS["js/"]:::frontend
            BUILD["webpack & package.json"]:::frontend
        end
        JS --> State["js/state/"]:::frontend
        JS --> Runner["js/runner.js"]:::frontend
        JS --> Views["js/views/"]:::frontend
    end
    HTML -->|loads| Browser["Browser"]:::frontend
    CSS -->|loads| Browser
    JS -->|loads| Browser

    Browser -->|ExecRequest JSON| Runner
    Runner -->|HTTP POST /execute| ServerHTTP

    %% Server Tier
    subgraph "Server Tier"
        subgraph "HTTP Server"
            Entrypoint["entrypoint.swift"]:::backend
            Configure["configure.swift"]:::backend
            Routes["routes.swift"]:::backend
            Middlewares["Middlewares/"]:::backend
            Models["Models/"]:::backend
        end
        subgraph "Processing Layer"
            DebugExec["Executor.swift"]:::core
            Debugger["Debugger/"]:::core
            DSLConv["DSLConverter/"]:::core
            Parser["ExpressionParser/"]:::core
            Matcher["Matcher/"]:::core
        end
    end

    ServerHTTP["Swift HTTP Server"]:::backend
    ServerHTTP --> Entrypoint
    Entrypoint --> Configure
    Configure --> Routes
    Routes --> Middlewares
    Middlewares --> Models
    Routes --> DebugExec

    DebugExec --> DSLConv
    DSLConv --> Parser
    Parser --> Matcher
    Matcher --> Debugger
    Debugger --> DebugExec

    DebugExec -->|ResultResponse JSON| Browser

    %% DevOps & CI
    subgraph "DevOps & CI"
        Docker["Dockerfile"]:::devops
        CI[".github/workflows/"]:::devops
    end

    %% Click Events
    click HTML "https://github.com/swiftfiddle/swiftregex/blob/main/Public/index.html"
    click CSS "https://github.com/swiftfiddle/swiftregex/tree/main/Public/css/"
    click JS "https://github.com/swiftfiddle/swiftregex/tree/main/Public/js/"
    click State "https://github.com/swiftfiddle/swiftregex/tree/main/Public/js/state/"
    click Runner "https://github.com/swiftfiddle/swiftregex/blob/main/Public/js/runner.js"
    click Views "https://github.com/swiftfiddle/swiftregex/tree/main/Public/js/views/"
    click BUILD "https://github.com/swiftfiddle/swiftregex/blob/main/package.json"
    click Entrypoint "https://github.com/swiftfiddle/swiftregex/blob/main/Sources/App/entrypoint.swift"
    click Configure "https://github.com/swiftfiddle/swiftregex/blob/main/Sources/App/configure.swift"
    click Routes "https://github.com/swiftfiddle/swiftregex/blob/main/Sources/App/routes.swift"
    click Middlewares "https://github.com/swiftfiddle/swiftregex/tree/main/Sources/App/Middlewares/"
    click Models "https://github.com/swiftfiddle/swiftregex/tree/main/Sources/App/Models/"
    click DebugExec "https://github.com/swiftfiddle/swiftregex/blob/main/Sources/App/Debugger/Executor.swift"
    click Debugger "https://github.com/swiftfiddle/swiftregex/tree/main/Sources/App/Debugger/"
    click DSLConv "https://github.com/swiftfiddle/swiftregex/tree/main/Sources/DSLConverter/"
    click Parser "https://github.com/swiftfiddle/swiftregex/tree/main/Sources/ExpressionParser/"
    click Matcher "https://github.com/swiftfiddle/swiftregex/tree/main/Sources/Matcher/"
    click Docker "https://github.com/swiftfiddle/swiftregex/tree/main/Dockerfile"
    click CI "https://github.com/swiftfiddle/swiftregex/tree/main/.github/workflows/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef core fill:#FFA500,stroke:#333,stroke-width:1px
    classDef devops fill:#D3D3D3,stroke:#333,stroke-width:1px
```
