# jetbrains/arend architecture

> Architecture diagram of the GitHub repository jetbrains/arend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jetbrains/arend
- Repository: https://github.com/jetbrains/arend

## Overview

##### Main Components
The system should be divided into these major components:

a) Core Components:
- API Layer (api/)
- Base Implementation (base/)
- Parser (parser/)
- Protocol Buffers (proto/)
- Command Line Interface (cli/)

b) Supporting Components:
- Build System (buildSrc/)
- Test Framework (src/test/)
- Prelude Library (lib/)

##### Component Relationships

**[CLI Interface] → [API Layer]**
- ↑
**[Parser] --------→ [Base Implementation] ← [Protocol Buffers]**
- ↓
- [Prelude Library]

##### Detailed Component Breakdown

a) API Layer (org.arend.ext):
- Extension System
- Type Checking Interface
- Core Expression Types
- Error Reporting
- Concrete Syntax Representation

b) Base Implementation (org.arend):
- Core Type System
- Pattern Matching
- Expression Evaluation
- Type Checking
- Library Management
- Module System

c) Parser:
- ANTLR Grammar (Arend.g4)
- Abstract Syntax Tree
- Concrete Syntax Processing

d) Protocol Buffers:
- Definition Serialization
- Expression Serialization
- Module Serialization
- Level Serialization

##### Key Architectural Patterns

a) Layered Architecture:
- Frontend (CLI, REPL)
- Core Language Processing
- Type System Implementation
- Storage/Serialization

b) Visitor Pattern Implementation:
- Expression Visitors
- Definition Visitors
- Pattern Matching

##### Important Flows to Highlight

Main processing flows:

##### Specific Implementation Details

- Expression Hierarchy (org.arend.core.expr)
- Definition Types (org.arend.core.definition)
- Type Checking Components (org.arend.typechecking)
- Pattern Matching System (org.arend.typechecking.patternmatching)

##### External Dependencies

Integration points with:
- JVM Platform
- ANTLR Parser Generator
- Protocol Buffers
- Build System (Gradle)

This design reflects Arend's nature as both a theorem prover and a programming language, with special emphasis on its type system implementation and extension capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef ui fill:#a8d1f0,stroke:#333
    classDef core fill:#90EE90,stroke:#333
    classDef type fill:#FFE5B4,stroke:#333
    classDef storage fill:#D3D3D3,stroke:#333
    classDef extension fill:#DDA0DD,stroke:#333

    %% Main Components
    CLI["CLI Interface"]:::ui
    click CLI "https://github.com/JetBrains/Arend/tree/master/cli/src/main/java/org/arend/frontend/"
    REPL["REPL"]:::ui
    click REPL "https://github.com/JetBrains/Arend/tree/master/cli/src/main/java/org/arend/frontend/repl/"
    API["API Layer"]:::extension
    click API "https://github.com/JetBrains/Arend/tree/master/api/src/main/java/org/arend/ext/"
    BASE["Base Implementation"]:::core
    click BASE "https://github.com/JetBrains/Arend/tree/master/base/src/main/java/org/arend/core/"
    PARSER["Parser (ANTLR)"]:::core
    click PARSER "https://github.com/JetBrains/Arend/blob/master/buildSrc/src/main/antlr/org/arend/frontend/parser/Arend.g4"
    PROTO["Protocol Buffers"]:::storage
    click PROTO "https://github.com/JetBrains/Arend/tree/master/proto/src/main/proto/"
    PRELUDE["Prelude Library"]:::storage
    click PRELUDE "https://github.com/JetBrains/Arend/blob/master/lib/Prelude.ard"

    %% Core Implementation Components
    subgraph CoreImpl["Core Implementation"]
        TS["Type System"]:::type
        click TS "https://github.com/JetBrains/Arend/tree/master/base/src/main/java/org/arend/typechecking/"
        PM["Pattern Matching"]:::type
        click PM "https://github.com/JetBrains/Arend/tree/master/base/src/main/java/org/arend/typechecking/patternmatching/"
        EE["Expression Evaluation"]:::core
        click EE "https://github.com/JetBrains/Arend/tree/master/base/src/main/java/org/arend/core/expr/visitor/"
        LM["Library Management"]:::core
        click LM "https://github.com/JetBrains/Arend/tree/master/base/src/main/java/org/arend/library/"
        MS["Module System"]:::core
        click MS "https://github.com/JetBrains/Arend/tree/master/base/src/main/java/org/arend/module/"
    end

    %% External Dependencies
    subgraph ExtDeps["External Dependencies"]
        JVM["JVM Platform"]
        ANTLR["ANTLR Parser"]
        PBUF["Protocol Buffers"]
        GRADLE["Gradle Build"]
    end

    %% Testing
    TEST["Test Framework"]:::core
    click TEST "https://github.com/JetBrains/Arend/tree/master/src/test/java/org/arend/"

    %% Relationships
    CLI --> API
    REPL --> API
    API --> BASE
    PARSER --> BASE
    PROTO --> BASE
    BASE --> PRELUDE
    
    BASE --> TS
    BASE --> PM
    BASE --> EE
    BASE --> LM
    BASE --> MS
    
    TS --> PM
    EE --> TS
    MS --> LM

    %% External Dependencies
    PARSER --> ANTLR
    PROTO --> PBUF
    BASE --> JVM
    
    %% Legend
    subgraph Legend
        UI["User Interface"]:::ui
        CORE["Core Processing"]:::core
        TYPE["Type System"]:::type
        STOR["Storage"]:::storage
        EXT["Extension Points"]:::extension
    end
```
