# swiftfiddle/swift-ast-explorer architecture

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

- Interactive diagram: https://gitdiagram.com/swiftfiddle/swift-ast-explorer
- Repository: https://github.com/swiftfiddle/swift-ast-explorer

## Overview

##### Main Components
- Frontend/UI:
– All static assets (HTML, CSS, JavaScript) reside in the Public folder.
– These files power the interactive visualizations (e.g., tree views, syntax maps) shown to the final user in the browser.
- Backend Server:
– The Swift application code under Sources/App (including entrypoint.swift, routes.swift, and middleware) forms the backbone of your server.
– This is where HTTP requests are handled and where the AST processing logic is integrated.
- Parser Modules:
– Under Resources/parsers you have several directories (e.g., 50800, 50900, 51000, 60000, trunk) each containing a separate Package.swift-based Swift package.
– These modules implement the actual parsing logic for different syntax versions and are key to converting Swift source code into AST representations.
- Development & Build Tools:
– There is a dev folder that includes an additional web-based tool (xml-formatter) and Node/webpack configurations that are likely used for development workflows or auxiliary tasks.
- CI/CD and Deployment:
– Dockerfile, GitHub workflows, and deployment scripts (e.g., DEPLOYMENT.md, deploy folder) indicate containerization and continuous integration/deployment setups.

##### Relationships and Interactions
- Frontend ↔ Backend:
– The browser requests static content from the Public folder and interacts with the backend via HTTP endpoints (and possibly WebSocket connections as indicated by Public/js/websocket.js).
- Backend ↔ Parser Modules:
– The middleware or route handlers in the main Swift application interface with the chosen parser module to perform AST generation.
- Build/Deploy Interface:
– Show auxiliary components like Docker and CI/CD pipelines that wrap the entire system, indicating how code is built, tested, and deployed.
- Developer Tools:
– Optionally, include the dev folder tools to highlight that there is a development-specific toolchain (e.g., xml-formatter) that supports code formatting and quality assurance.

##### Architectural Patterns & Design Principles
- Separation of Concerns:
– Clear division between front end (presentation) and back end (business logic and AST processing).
– The parser modules are isolated and versioned, ensuring that the core AST generation functionality is modular.
- Modularization:
– Using multiple parser versions and a clearly defined Sources/App for the web server promotes independent development and testing.
- CI/CD and Containerization:
– The Dockerfile, GitHub workflows, and deployment scripts indicate a modern development workflow that supports reproducible and scalable deployments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend (Public Assets)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Swift Web Server (Sources/App)"]:::backend
        MW["Middleware & Routes"]:::backend
        BE -->|"delegates to"| MW
    end

    %% Parser Modules Layer
    subgraph "Parser Modules (Resources/parsers)"
        P50800["Parser Module 50800"]:::parser
        P50900["Parser Module 50900"]:::parser
        P51000["Parser Module 51000"]:::parser
        P60000["Parser Module 60000"]:::parser
        Ptrunk["Parser Module trunk"]:::parser
    end

    %% Dev & Build Tools
    subgraph "Dev & Build Tools"
        DEV["Development Tools (dev/)"]:::dev
        WCC["webpack.common.js"]:::dev
        WDEV["webpack.dev.js"]:::dev
        WPROD["webpack.prod.js"]:::dev
        DEV -->|"configures"| WCC
        DEV -->|"configures"| WDEV
        DEV -->|"configures"| WPROD
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        GHA["GitHub Workflows (.github/workflows)"]:::cicd
        DF["Dockerfile"]:::cicd
        DEPLOYMD["DEPLOYMENT.md"]:::cicd
        DEPLOY["Deployment Scripts (deploy/)"]:::cicd
        GHA --- DF
        DF --- DEPLOYMD
        DEPLOYMD --- DEPLOY
    end

    %% Data Flow Connections
    FE -->|"HTTP requests & static assets"| BE
    MW -->|"calls parser"| P50800
    MW -->|"calls parser"| P50900
    MW -->|"calls parser"| P51000
    MW -->|"calls parser"| P60000
    MW -->|"calls parser"| Ptrunk

    %% Click Events
    click FE "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Public/"
    click BE "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Sources/App"
    click P50800 "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Resources/parsers/50800"
    click P50900 "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Resources/parsers/50900"
    click P51000 "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Resources/parsers/51000"
    click P60000 "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Resources/parsers/60000"
    click Ptrunk "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Resources/parsers/trunk"
    click DEV "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/dev/"
    click WCC "https://github.com/swiftfiddle/swift-ast-explorer/blob/master/webpack.common.js"
    click WDEV "https://github.com/swiftfiddle/swift-ast-explorer/blob/master/webpack.dev.js"
    click WPROD "https://github.com/swiftfiddle/swift-ast-explorer/blob/master/webpack.prod.js"
    click GHA "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/.github/workflows"
    click DF "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/Dockerfile"
    click DEPLOYMD "https://github.com/swiftfiddle/swift-ast-explorer/blob/master/DEPLOYMENT.md"
    click DEPLOY "https://github.com/swiftfiddle/swift-ast-explorer/tree/master/deploy/"

    %% Style Classes
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef parser fill:#cfc,stroke:#333,stroke-width:2px;
    classDef dev fill:#fcc,stroke:#333,stroke-width:2px;
    classDef cicd fill:#fc9,stroke:#333,stroke-width:2px;
```
