# joaomofrancisco/thrift-java-compiler architecture

> Architecture diagram of the GitHub repository joaomofrancisco/thrift-java-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joaomofrancisco/thrift-java-compiler
- Repository: https://github.com/joaomofrancisco/thrift-java-compiler

## Overview

##### Project type and purpose
- This is an open-source compiler toolchain for Apache Thrift IDL written in Java. It has two main Maven modules:
- thrift-java-compiler-idl-parser: parses .thrift files into an in-memory AST/model
- thrift-java-compiler-codegenerator: takes that AST and emits Java (and Swift) source
- Its purpose is to let you feed it Thrift definitions and get out generated client/server code.

##### File structure
- Top level: a multi-module Maven project (pom.xml, two submodule directories).
- thrift-java-compiler-idl-parser:
- ANTLR3 grammar under src/main/antlr3
- Parser entry point ThriftIdlParser
- com.facebook.swift.parser.model package with AST node classes
- Visitor framework to walk/transform the AST
- thrift-java-compiler-codegenerator:
- Generator entry points (SwiftGenerator, ConstantRenderer, ServiceCodeGenerator, etc.)
- A registry (TypeRegistry, TypedefRegistry) holding AST→Java‐type mappings
- Packages for codegenerator implementations, visitor templates, utility classes
- Both modules have test resources (sample .thrift files) and JUnit/TestNG test suites.
- Build: Maven, ANTLR plugin generating lexer/parser code, standard compiler and surefire plugins.

##### Key insights from README
- The README appears to be an unrelated API doc template. For architecture, focus on code structure:
- Thrift grammar → parser → AST
- AST → generator → code files

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Input Layer
    subgraph "Input Layer"
        IDL1["Thrift IDL files (parser tests)"]:::input
        IDL2["Thrift IDL files (codegen tests)"]:::input
    end

    %% Parser Module
    subgraph "Parser Module" 
        direction TB
        ANTLR["ANTLR Grammar"]:::runtime
        Parser["ThriftIdlParser"]:::module
        VisitorFW["Visitor Framework"]:::module
        ASTModel["AST Model Package"]:::data
    end

    %% Code Generator Module
    subgraph "Code Generator Module"
        direction TB
        GenEntry["Generator Entry Points"]:::module
        Registries["Type/Typedef Registries"]:::module
        Impl["CodeGenerator Implementations"]:::module
        Visitors["Codegen Visitor Templates"]:::module
        Util["Utility Classes"]:::module
    end

    %% Output Layer
    subgraph "Output Layer"
        direction TB
        GenJava["Generated Java/Swift Code"]:::output
        ANTLROut["Generated ANTLR Sources"]:::output
    end

    %% Build Orchestration
    Maven["Maven Multi-Module Build"]:::module

    %% Connections
    IDL1 -->|"Thrift IDL text"| ANTLR
    IDL2 -->|"Thrift IDL text"| ANTLR
    ANTLR -->|"Parse Tree"| Parser
    Parser -->|"AST Document"| ASTModel
    VisitorFW --> ASTModel
    ASTModel -->|"AST Document"| GenEntry
    GenEntry --> Registries
    Registries --> Visitors
    Visitors --> Impl
    Util --> Impl
    Impl -->|"Source files"| GenJava
    Maven --> ANTLR
    Maven --> Parser
    Maven --> GenEntry
    Maven --> GenJava
    Maven --> ANTLROut

    %% Click Events
    click IDL1 "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-idl-parser/src/test/resources"
    click IDL2 "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-codegenerator/src/test/resources"
    click ANTLR "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-idl-parser/src/main/antlr3/com/facebook/swift/parser/antlr/Thrift.g"
    click ANTLR "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-idl-parser/src/main/antlr3/com/facebook/swift/parser/antlr/DocumentGenerator.g"
    click Parser "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-idl-parser/src/main/java/com/facebook/swift/parser/ThriftIdlParser.java"
    click ASTModel "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-idl-parser/src/main/java/com/facebook/swift/parser/model"
    click VisitorFW "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-idl-parser/src/main/java/com/facebook/swift/parser/visitor/DocumentVisitor.java"
    click VisitorFW "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-idl-parser/src/main/java/com/facebook/swift/parser/visitor/Nameable.java"
    click VisitorFW "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-idl-parser/src/main/java/com/facebook/swift/parser/visitor/Visitable.java"
    click GenEntry "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/SwiftGenerator.java"
    click GenEntry "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/SwiftGeneratorConfig.java"
    click GenEntry "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/SwiftGeneratorTweak.java"
    click GenEntry "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/SwiftDocumentContext.java"
    click GenEntry "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/ConstantRenderer.java"
    click GenEntry "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/JavaGeneratorUtil.java"
    click Registries "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/TypeRegistry.java"
    click Registries "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/TypedefRegistry.java"
    click Registries "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/TypeToJavaConverter.java"
    click Registries "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/SwiftJavaType.java"
    click Impl "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/codegenerator"
    click Visitors "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/visitors"
    click Util "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/src/main/java/com/facebook/swift/thrift/generator/util/SwiftInternalStringUtils.java"
    click Maven "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/pom.xml"
    click Maven "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-idl-parser/pom.xml"
    click Maven "https://github.com/joaomofrancisco/thrift-java-compiler/blob/master/thrift-java-compiler-codegenerator/pom.xml"
    click GenJava "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-codegenerator/src/test/resources/gen-java"
    click GenJava "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-codegenerator/src/test/resources/gen-java/swift"
    click ANTLROut "https://github.com/joaomofrancisco/thrift-java-compiler/tree/master/thrift-java-compiler-idl-parser/target/generated-sources/antlr3"

    %% Styles
    classDef input fill:#FFF2CC,stroke:#333,stroke-width:1px
    classDef module fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef runtime fill:#DFFFD6,stroke:#333,stroke-width:1px
    classDef data fill:#FFE6B8,stroke:#333,stroke-width:1px
    classDef output fill:#FFFF99,stroke:#333,stroke-width:1px
```
