# maxime-pages/fabgen architecture

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

- Interactive diagram: https://gitdiagram.com/maxime-pages/fabgen
- Repository: https://github.com/maxime-pages/fabgen

## Overview

##### Project Type and Key Purpose
- Fabgen is essentially a code generation tool that converts user-provided API binding scripts into binding code tailored for different target languages.
- Its primary components include the generic binding generator (implemented in gen.py), language-specific binding implementations (found in the “lang” directory), and additional library code (in the “lib” directory) that supports standard C++ constructs such as STL, and even additional functionalities like proxying and feature-based extensions.
- The tool is further validated via a comprehensive set of tests and CI configurations (e.g., Travis CI files, Coveralls).

##### Main Components
a. User Input Layer:
- API Binding Script – the Python script provided by the user that describes what C++ functions, classes, etc., to bind.
- bind.py – the main entry point that routes to appropriate language-specific binding generators based on the provided CLI options.

b. Core Generator:
- gen.py – the central generic binding generator that encapsulates most of the core logic.
- Feature Extension Mechanism – includes support for additional features such as proxy, arg_out, and more as explained in the README.

c. Language-Specific Handlers:
- “lang” Directory – contains separate modules (cpython.py, lua.py, go.py, xml.py) for handling language-specific conversion rules.
- “lib” Directory – provides low-level common and language-specific support code (with similar subdirectories for cpython, lua, go, xml) which further abstract C++ standard library constructs and simplify the binding generation.

d. Testing and Examples:
- “tests” Directory and tests.py – verify correct binding generation and ensure the robustness of the tool.
- “examples” Directory – demonstrates usage, such as a sample binding for Harfang Multimedia Framework usage.

e. External Components:
- CI/CD and dependency files, including Travis CI configuration and requirements.txt.

##### Relationships and Data Flow
- The user invokes bind.py with an API binding script and options (such as --cpython, --lua, or --go).
- bind.py calls the generic generator (gen.py) which orchestrates the process.
- The generator then leverages language-specific modules in the “lang” directory to convert C++ constructs into target language bindings.
- Underlying type conversion details and additional functionalities are provided via modules in the “lib” directory.
- Output (target binding code) is produced and may then be deployed, tested, or further compiled.
- The tests directory ensures that all conversion and binding productions meet expected behaviors.

##### Architectural Patterns & Design Principles
- Modular Design: Separation between the core generator logic (gen.py) and language-specific conversion logic (modules under “lang” and “lib”).
- Extensibility: The feature mechanism (with proxies, type converters, and extended function prototypes) allows additional behaviors without needing to change the core generator.
- Abstraction & Reuse: The “lib” folder abstracts out common and language-specific conversions (std, stl routines) to keep the generic parts (in gen.py) simple and maintainable.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Input Layer
    subgraph "User Input Layer"
        U1["API Binding Script"]:::input
        B["bind.py"]:::core
        U1 -->|"routes_input"| B
    end

    %% Core Generator
    subgraph "Core Generator"
        G["gen.py (Core Generator w/Feature_Extension)"]:::core
        B -->|"calls"| G
    end

    %% Language-Specific Handlers
    subgraph "Language-Specific Handlers"
        CP["CPython Module (lang/cpython.py)"]:::lang
        CP_LIB["CPython Library (lib/cpython/)"]:::lib
        CP -->|"lib_support"| CP_LIB

        L["Lua Module (lang/lua.py)"]:::lang
        L_LIB["Lua Library (lib/lua/)"]:::lib
        L -->|"lib_support"| L_LIB

        GO["Go Module (lang/go.py)"]:::lang
        GO_LIB["Go Library (lib/go/)"]:::lib
        GO -->|"lib_support"| GO_LIB

        X["XML Module (lang/xml.py)"]:::lang
        X_LIB["XML Library (lib/xml/)"]:::lib
        X -->|"lib_support"| X_LIB

        G -->|"binding_generation"| CP
        G -->|"binding_generation"| L
        G -->|"binding_generation"| GO
        G -->|"binding_generation"| X
    end

    %% Testing and Examples
    subgraph "Testing and Examples"
        subgraph "Test Suite"
            T1["tests directory"]:::test
            T2["tests.py"]:::test
            T1 -->|"contains"| T2
        end
        E["Examples (examples/)"]:::test
        G -->|"validated_by"| T1
        G -->|"demo_usage"| E
    end

    %% External Components
    subgraph "External Components"
        subgraph "Continuous Integration"
            CI1["Travis_CI_Config (.travis.yml)"]:::external
            CI2["Lua_Setup (.travis/setup_lua.sh)"]:::external
            CI1 -->|"includes"| CI2
        end
        subgraph "Dependencies"
            D1["requirements.txt"]:::dep
            D2[".coveragerc"]:::dep
            D3[".gitignore"]:::dep
        end
        G -->|"CI_integration"| CI1
        T1 -->|"run_on"| CI1
    end

    %% Click Events
    click B "https://github.com/maxime-pages/fabgen/blob/master/bind.py"
    click G "https://github.com/maxime-pages/fabgen/blob/master/gen.py"
    click CP "https://github.com/maxime-pages/fabgen/blob/master/lang/cpython.py"
    click CP_LIB "https://github.com/maxime-pages/fabgen/tree/master/lib/cpython/"
    click L "https://github.com/maxime-pages/fabgen/blob/master/lang/lua.py"
    click L_LIB "https://github.com/maxime-pages/fabgen/tree/master/lib/lua/"
    click GO "https://github.com/maxime-pages/fabgen/blob/master/lang/go.py"
    click GO_LIB "https://github.com/maxime-pages/fabgen/tree/master/lib/go/"
    click X "https://github.com/maxime-pages/fabgen/blob/master/lang/xml.py"
    click X_LIB "https://github.com/maxime-pages/fabgen/tree/master/lib/xml/"
    click T1 "https://github.com/maxime-pages/fabgen/tree/master/tests"
    click T2 "https://github.com/maxime-pages/fabgen/blob/master/tests.py"
    click E "https://github.com/maxime-pages/fabgen/tree/master/examples"
    click CI1 "https://github.com/maxime-pages/fabgen/blob/master/.travis.yml"
    click CI2 "https://github.com/maxime-pages/fabgen/blob/master/.travis/setup_lua.sh"
    click D1 "https://github.com/maxime-pages/fabgen/blob/master/requirements.txt"
    click D2 "https://github.com/maxime-pages/fabgen/blob/master/.coveragerc"
    click D3 "https://github.com/maxime-pages/fabgen/blob/master/.gitignore"

    %% Styles
    classDef input fill:#cce5ff,stroke:#000,stroke-width:2px;
    classDef core fill:#d4edda,stroke:#000,stroke-width:2px;
    classDef lang fill:#fff3cd,stroke:#000,stroke-width:2px;
    classDef lib fill:#ffeeba,stroke:#000,stroke-width:2px;
    classDef test fill:#d1c4e9,stroke:#000,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#000,stroke-width:2px;
    classDef dep fill:#f5f5f5,stroke:#000,stroke-width:2px;
```
