How swiftfiddle/swiftregex works
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