# pablojorge/brainfuck architecture

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

- Interactive diagram: https://gitdiagram.com/pablojorge/brainfuck
- Repository: https://github.com/pablojorge/brainfuck

## Overview

##### Project Type Analysis
This is a multi-language implementation project featuring interpreters, translators, and JIT compilers for the Brainfuck programming language. The project serves as a language implementation playground with various approaches across different programming languages.

##### Main Components

A. Core Components Layer:
- Interpreters Block
- Translators Block
- JIT Compilers Block
- Program Storage Block

B. Implementation Layer:
- Language-specific implementations (C, C++, Assembly, JavaScript, Python, Rust, etc.)
- Each with their specific optimization approaches

C. Interface Layer:
- Web Interface (JavaScript/WASM)
- Command-line Interface (for other implementations)

**Rectangle: Main components**
**Hexagon: Implementation languages**
**Diamond: Interface points**

**Blue: Core components**
**Green: Implementation languages**
**Orange: Interface components**
**Gray: Storage components**

##### Key Relationships

a) Program Flow:
**[Program Storage] -> [Interpreter/Translator/JIT] -> [Output Interface]**

b) Web Implementation:
**[JavaScript UI] <-> [WASM Engine]**
- > [Pure JS Engine]

c) Translation Paths:
**[Source Programs] -> [Translators] -> [Generated Code (C/Rust)]**

##### Important Elements to Highlight

- Optimization Layers:
- Basic interpretation
- Pre-calculated jumps
- JIT compilation
- RPython optimization

- Cross-compilation Features:
- Brainfuck to C
- Brainfuck to Rust
- WASM compilation

##### Implementation Details

- Language-specific optimizations
- Benchmark performance comparisons
- Web interface components
- Testing infrastructure

##### Specific Component Details

**[Web Interface]**
- JavaScript Frontend
- WASM Backend
- Program Gallery

**[Core Interpreters]**
- Basic Interpreters
- Optimized Interpreters
- JIT Compilers

**[Translators]**
- BF to C
- BF to Rust
- BF to Lua

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Component]:::component
        L2[/Interface/]:::interface
        L3[(Storage)]:::storage
        L4{{Language}}:::language
        L5[["Web Component"]]:::web
    end

    subgraph Core["Core Components"]
        Storage[(Program Storage)]:::storage
        click Storage "https://github.com/pablojorge/brainfuck/tree/master/programs/"

        subgraph Interpreters["Interpreters"]
            Basic["Basic Interpreters"]:::component
            click Basic "https://github.com/pablojorge/brainfuck/blob/master/c/brainfuck.c"
            Optimized["Optimized Interpreters"]:::component
            click Optimized "https://github.com/pablojorge/brainfuck/blob/master/python/brainfuck-rpython.py"
        end

        subgraph JIT["JIT Compilers"]
            JITComp["JIT Compilation Layer"]:::component
            click JITComp "https://github.com/pablojorge/brainfuck/blob/master/cpp/brainfuck-jit.cpp"
        end

        subgraph Trans["Translators"]
            BF2C["BF to C"]:::component
            click BF2C "https://github.com/pablojorge/brainfuck/blob/master/haskell/bf2c.hs"
            BF2Rust["BF to Rust"]:::component
            click BF2Rust "https://github.com/pablojorge/brainfuck/blob/master/rust/src/bin/translate.rs"
            BF2Lua["BF to Lua"]:::component
            click BF2Lua "https://github.com/pablojorge/brainfuck/blob/master/lua/bf2lua.lua"
        end
    end

    subgraph Lang["Implementation Languages"]
        C{{C}}:::language
        CPP{{C++}}:::language
        Python{{Python}}:::language
        Rust{{Rust}}:::language
        ASM{{Assembly}}:::language
        JS{{JavaScript}}:::language
        Lua{{Lua}}:::language
        Go{{Go}}:::language
        Haskell{{Haskell}}:::language
    end

    subgraph Interface["Interface Layer"]
        CLI[/Command Line Interface/]:::interface
        
        subgraph Web["Web Implementation"]
            WebUI[["Web Interface"]]:::web
            click WebUI "https://github.com/pablojorge/brainfuck/blob/master/javascript/brainfuck.html"
            WASM[["WASM Engine"]]:::web
            click WASM "https://github.com/pablojorge/brainfuck/blob/master/wasm/src/lib.rs"
            JSEngine[["Pure JS Engine"]]:::web
            click JSEngine "https://github.com/pablojorge/brainfuck/blob/master/javascript/brainfuck.js"
        end
    end

    subgraph Test["Testing Infrastructure"]
        Tests["Test Suite"]:::component
        click Tests "https://github.com/pablojorge/brainfuck/blob/master/rust/tests/tests.rs"
        Benchmarks["Performance Benchmarks"]:::component
    end

    Storage --> Basic & Optimized & JITComp & Trans
    Basic & Optimized & JITComp --> CLI
    Trans --> C & Rust & Lua
    Storage --> WebUI
    WebUI --> WASM & JSEngine
    WASM & JSEngine --> WebUI
    C & CPP & Python & Rust & ASM & JS & Lua & Go & Haskell --> Basic & Optimized & JITComp & Trans
    Basic & Optimized & JITComp & Trans --> Tests
    Tests --> Benchmarks

    classDef component fill:#a8d1ff,stroke:#000
    classDef interface fill:#ffb366,stroke:#000
    classDef storage fill:#d9d9d9,stroke:#000
    classDef language fill:#90EE90,stroke:#000
    classDef web fill:#FFB6C1,stroke:#000
```
