# openrewrite/rewrite architecture

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

- Interactive diagram: https://gitdiagram.com/openrewrite/rewrite
- Repository: https://github.com/openrewrite/rewrite

## Overview

##### Main Components

a. Core Components:
- Core Engine (rewrite-core)
- Language-specific Parsers
- Java (rewrite-java-8/11/17/21)
- XML (rewrite-xml)
- YAML (rewrite-yaml)
- Properties (rewrite-properties)
- Maven (rewrite-maven)
- Gradle (rewrite-gradle)
- Others (Groovy, TOML, Protobuf, etc.)
- Recipe System
- Visitor Pattern Implementation
- Type System

b. Integration Points:
- Build Tool Plugins
- External Services Integration
- Cache Systems
- Parser Implementations

##### Relationship Flows

- Source code input flow
- Parsing process
- Recipe execution flow
- AST transformation
- Result generation

##### Architectural Layers

**┌─────────────────────────────────────────┐**
- Build Tool Plugins           │
- (Gradle, Maven Integration)        │
- ┤
- Recipe Execution Layer        │
- (Recipe Registry & Orchestration)   │
- ┤
- Language-Specific Parsers       │
- (Java, XML, YAML, Maven, etc.)        │
- ┤
- Core Engine                 │
- (AST, Visitors, Type System)          │
- ┤
- Storage & Caching Layer         │
- (Results, Types, Parser Cache)        │
- ┘

##### Key Components Detail

a. Core Engine:
- AST (Abstract Syntax Tree) Management
- Visitor Pattern Implementation
- Type System
- Results Handling

b. Recipe System:
- Recipe Registry
- Recipe Execution Pipeline
- Recipe Configuration
- Results Collection

c. Parser Framework:
- Language-Specific Parsers
- Parser Caching
- AST Generation
- Symbol Resolution

##### Cross-Cutting Concerns

- Security
- Logging
- Metrics
- Error Handling
- Configuration Management

##### External Integrations

Connections to:
- Build Systems
- Version Control
- CI/CD Systems
- Moderne Platform (optional integration)

##### Implementation Notes

Callouts for:
- Key interfaces
- Extension points
- Plugin architecture
- Cache mechanisms

##### Metrics and Monitoring

Sections for:
- Performance monitoring
- Error tracking
- Usage statistics
- Health checks

##### Integration capabilities

- Clear and readable
- Well-organized
- Properly labeled
- Easily maintainable

Remember to maintain a balance between detail and clarity, focusing on the most important architectural aspects while avoiding overwhelming detail that might obscure the main system structure.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#333
    classDef parser fill:#90EE90,stroke:#333
    classDef integration fill:#FFB347,stroke:#333
    classDef cache fill:#D3D3D3,stroke:#333
    classDef security fill:#FFB6C1,stroke:#333
    classDef config fill:#DDA0DD,stroke:#333
    classDef test fill:#F0E68C,stroke:#333

    %% Build Tool Plugins Layer
    subgraph BuildTools["Build Tool Plugins"]
        Maven["Maven Plugin"]:::integration
        Gradle["Gradle Plugin"]:::integration
    end

    %% Recipe Layer
    subgraph RecipeLayer["Recipe Execution Layer"]
        RecipeRegistry["Recipe Registry"]:::core
        RecipeExec["Recipe Execution"]:::core
        RecipeConfig["Recipe Configuration"]:::core
    end

    %% Language Parsers Layer
    subgraph Parsers["Language-Specific Parsers"]
        Java8["Java 8"]:::parser
        Java11["Java 11"]:::parser
        Java17["Java 17"]:::parser
        Java21["Java 21"]:::parser
        XML["XML"]:::parser
        YAML["YAML"]:::parser
        Properties["Properties"]:::parser
        MavenParser["Maven"]:::parser
        GradleParser["Gradle"]:::parser
        Groovy["Groovy"]:::parser
        TOML["TOML"]:::parser
        Protobuf["Protobuf"]:::parser
    end

    %% Core Engine Layer
    subgraph CoreEngine["Core Engine"]
        AST["AST Management"]:::core
        Visitors["Visitor Pattern"]:::core
        TypeSystem["Type System"]:::core
        Results["Results Handler"]:::core
    end

    %% Storage & Cache Layer
    subgraph Storage["Storage & Caching"]
        MavenCache["Maven Cache"]:::cache
        CoreCache["Core Cache"]:::cache
    end

    %% Cross-Cutting Concerns
    subgraph CrossCutting["Cross-Cutting Concerns"]
        Security["Security Components"]:::security
        ConfigMgmt["Configuration Management"]:::config
        Testing["Testing Framework"]:::test
    end

    %% Relationships
    Maven --> RecipeLayer
    Gradle --> RecipeLayer
    RecipeLayer --> Parsers
    Parsers --> CoreEngine
    CoreEngine --> Storage
    CrossCutting --> CoreEngine

    %% Click Events
    click Maven "https://github.com/openrewrite/rewrite/tree/main/rewrite-maven/src/main/java/org/openrewrite/maven/"
    click Gradle "https://github.com/openrewrite/rewrite/tree/main/rewrite-gradle/src/main/java/org/openrewrite/gradle/"
    click Java8 "https://github.com/openrewrite/rewrite/tree/main/rewrite-java-8/"
    click Java11 "https://github.com/openrewrite/rewrite/tree/main/rewrite-java-11/"
    click Java17 "https://github.com/openrewrite/rewrite/tree/main/rewrite-java-17/"
    click Java21 "https://github.com/openrewrite/rewrite/tree/main/rewrite-java-21/"
    click XML "https://github.com/openrewrite/rewrite/tree/main/rewrite-xml/"
    click YAML "https://github.com/openrewrite/rewrite/tree/main/rewrite-yaml/"
    click Properties "https://github.com/openrewrite/rewrite/tree/main/rewrite-properties/"
    click MavenParser "https://github.com/openrewrite/rewrite/tree/main/rewrite-maven/"
    click GradleParser "https://github.com/openrewrite/rewrite/tree/main/rewrite-gradle/"
    click Groovy "https://github.com/openrewrite/rewrite/tree/main/rewrite-groovy/"
    click TOML "https://github.com/openrewrite/rewrite/tree/main/rewrite-toml/"
    click Protobuf "https://github.com/openrewrite/rewrite/tree/main/rewrite-protobuf/"
    click AST "https://github.com/openrewrite/rewrite/blob/main/rewrite-core/src/main/java/org/openrewrite/Tree.java"
    click TypeSystem "https://github.com/openrewrite/rewrite/tree/main/rewrite-core/src/main/java/org/openrewrite/internal/lang/"
    click MavenCache "https://github.com/openrewrite/rewrite/tree/main/rewrite-maven/src/main/java/org/openrewrite/maven/cache/"
    click CoreCache "https://github.com/openrewrite/rewrite/tree/main/rewrite-core/src/main/java/org/openrewrite/internal/"
    click Security "https://github.com/openrewrite/rewrite/tree/main/rewrite-maven/src/main/java/org/openrewrite/maven/security/"
    click ConfigMgmt "https://github.com/openrewrite/rewrite/tree/main/rewrite-core/src/main/java/org/openrewrite/config/"
    click Testing "https://github.com/openrewrite/rewrite/tree/main/rewrite-test/"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Language Parsers"]:::parser
        L3["Integration Points"]:::integration
        L4["Cache Systems"]:::cache
        L5["Security"]:::security
        L6["Configuration"]:::config
        L7["Testing"]:::test
    end
```
