# nucleoidai/nucleoid architecture

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

- Interactive diagram: https://gitdiagram.com/nucleoidai/nucleoid
- Repository: https://github.com/nucleoidai/nucleoid

## Overview

##### Project Type and Purpose
- Nucleoid is a neuro-symbolic AI runtime that integrates declarative (logic) programming with data management and knowledge graph generation.
- Its purpose is to support adaptive reasoning by dynamically managing both logic and data in a unified runtime, serving as a foundation for decision‐making and symbolic reasoning.

##### File Structure
- Notice key top-level directories:
– “arc” folder: Appears to be the primary Node.js implementation with its source code for the runtime, evaluations, and training data.
– “src” folder: Contains various modules related to the language, AST, and runtime core such as Expression, Instruction, Scope, and modules under “src/lang” and “src/nuc”. These reflect the implementation of the declarative language, parsers, interpreters, and abstract syntax trees.
– “python” folder: Provides additional components written in Python, including a nucleoid submodule (graph, parsing, state management) and tests. This highlights the multi-language support (Node.js/JavaScript and Python).
– Other directories like “.github” contain workflows and metadata for CI/CD, while configuration files (e.g., package.json, ESLint configuration) indicate standard practices.
- Patterns such as compiler modules (“src/experimental/compiler.js” and “compiler.py”), and dedicated “data/evaluation”, “data/training”, and “instruct_dataset” folders, showcase the dynamic data ingestion and evaluation process.

##### Readme Insights
- The README explains the core ideas of neuro-symbolic AI, a declarative runtime that mixes symbolic reasoning (logic graph) with dynamic data updates.
- It emphasizes integration with external services (e.g., OpenAI, Azure, and others in “arc/src/lib”) and shows that there are both fast (neural network based learning) and deliberate (symbolic logic) decision-making paths.
- Technologies mentioned include Node.js, Express.js, and hints of future TypeScript and more advanced ES support. There’s also multi-language support with Python tools.

a. Main Components:
– Frontend/API/Interface Layer: Represented by Express routes (located under “src/routes”) and CLI entry points (e.g., server.js, bin.js). This layer handles user interactions (e.g., terminal, chat interface, OpenAPI).
– Runtime Engine: The core of Nucleoid which runs the declarative logic. This comprises the main runtime modules in “arc/src/app.js”, “nucleoid.js”, “src/stack.js”, “src/state.js”, and others that manage the execution of logic statements.
– Data and Knowledge Graph: The component that stores, updates, and evaluates both logic and data statements. This includes the in-memory datastore and the continuous construction of the logic graph.
– Integration & Library Modules: Elements in “arc/src/lib” handle integrations with external services (e.g., Azure, OpenAI, Claude, Llama, etc.), supporting neuro-symbolic processing.
– Multi-language Support: The Python side (under “python/”) and related tests illustrate auxiliary support and experiments. This can be represented as a parallel engine that interoperates with the main runtime to experiment with or extend the system.
– Evaluation & Training Data: The “arc/src/data/evaluation” and “arc/src/data/training” directories indicate modules processing evaluated and training examples that feed into the runtime for adaptive reasoning.

b. Relationships & Interactions:
– Illustrate directional data flows between the language processing/parsing modules and the knowledge graph datastore. For example, once the AST is generated, it feeds into the logic engine that updates the graph.
– Show integration between external library modules (e.g., for neural network outputs) and the engine, which informs both immediate inference and knowledge graph updates.
– Represent the multi-language bridge: a connection between the primary Node.js engine and the Python components as they both support distinct aspects of the system.

c. Highlighting Architectural Patterns:
– Separation of Concerns / Layered Architecture: Distinct layers for presentation (routes, server), core logic (runtime engine, datastore), language processing (parsers, AST modules), and integration (external library calls).
– Dynamic Data Flow & Plasticity: Emphasize the “on-chain data store” and continuous update process of the knowledge graph, as well as the adaptive reasoning cycle.
– Modularity and Extensibility: Note the finely partitioned modules (logic, libraries, training data, evaluations) allowing feature extensions.

##### Instructing the Principal Software Engineer
– Begin by listing all the major system components as identified above.
– Make sure the modular components (for Node.js and Python processing) are clearly indicated and show how they interact or complement one another.
– Include annotations or notes to mention that the system’s adaptive reasoning and plasticity are achieved by the real-time, in-memory computing model and the continuous re-evaluation of declarative statements.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/API/Interface Layer
    subgraph "Frontend/API/Interface"
        API1["Express Routes"]
        API2["Server (arc/server.js)"]
        API3["Server (server.js)"]
    end

    %% Runtime Engine
    subgraph "Runtime Engine"
        RE1["Core Runtime (arc/src/app.js)"]
        RE2["Nucleoid Module (src/nucleoid.js)"]
        RE3["Stack (src/stack.js)"]
        RE4["State (src/state.js)"]
    end

    %% Language Processing and Parsing
    subgraph "Language Processing and Parsing"
        LANG1["Language Modules (src/lang)"]
        LANG2["AST Parsers (src/lang/ast)"]
        LANG3["ESTree (src/lang/estree)"]
        LANG4["Python Parsing (python/nucleoid/parse.py)"]
    end

    %% Data and Knowledge Graph
    subgraph "Data and Knowledge Graph"
        DATA1["Graph (src/graph.js)"]
        DATA2["Datastore (src/datastore.js)"]
        DATA3["Python Graph Support (python/nucleoid/graph.py)"]
    end

    %% Integration & Library Modules
    subgraph "Integration & Library Modules"
        INT1["External Integrations (arc/src/lib)"]
        INT2["Supporting Libraries (src/lib)"]
    end

    %% Multi-language Support
    subgraph "Multi-language Support"
        MULTI1["Python Components & Tests (python)"]
    end

    %% Evaluation & Training Data
    subgraph "Evaluation & Training Data"
        EVAL1["Evaluation Data (arc/src/data/evaluation)"]
        EVAL2["Training Data (arc/src/data/training)"]
        EVAL3["Instruct Dataset (arc/src/instruct_dataset)"]
    end

    %% Connections: Frontend/API to Runtime Engine
    API1 --> RE1
    API2 --> RE1
    API3 --> RE1

    %% Connections: Language Processing to Runtime Engine
    LANG1 --> RE1
    LANG2 --> RE1
    LANG3 --> RE1
    LANG4 --> RE1

    %% Connections: Runtime Engine to Data and Knowledge Graph
    RE1 --> DATA1
    RE1 --> DATA2

    %% Connections: Runtime Engine to Integration Modules
    RE1 --> INT1
    RE1 --> INT2
    INT1 --> RE1

    %% Connections: Evaluation & Training Data to Runtime Engine
    EVAL1 --> RE1
    EVAL2 --> RE1
    EVAL3 --> RE1

    %% Connections: Multi-language Support interacting with Runtime and Data
    MULTI1 --> RE1
    MULTI1 --> DATA3

    %% Styles
    class API1,API2,API3 api
    class RE1,RE2,RE3,RE4 runtime
    class LANG1,LANG2,LANG3,LANG4 lang
    class DATA1,DATA2,DATA3 data
    class INT1,INT2 integration
    class MULTI1 multi
    class EVAL1,EVAL2,EVAL3 eval

    %% Class Definitions with Colors
    classDef api fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef runtime fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef lang fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef data fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef integration fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef multi fill:#d9ccff,stroke:#333,stroke-width:2px;
    classDef eval fill:#d9f2d9,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend/API/Interface Layer
    click API1 "https://github.com/nucleoidai/nucleoid/tree/main/src/routes"
    click API2 "https://github.com/nucleoidai/nucleoid/blob/main/arc/server.js"
    click API3 "https://github.com/nucleoidai/nucleoid/blob/main/server.js"

    %% Click Events for Runtime Engine
    click RE1 "https://github.com/nucleoidai/nucleoid/blob/main/arc/src/app.js"
    click RE2 "https://github.com/nucleoidai/nucleoid/blob/main/src/nucleoid.js"
    click RE3 "https://github.com/nucleoidai/nucleoid/blob/main/src/stack.js"
    click RE4 "https://github.com/nucleoidai/nucleoid/blob/main/src/state.js"

    %% Click Events for Language Processing and Parsing
    click LANG1 "https://github.com/nucleoidai/nucleoid/tree/main/src/lang"
    click LANG2 "https://github.com/nucleoidai/nucleoid/tree/main/src/lang/ast"
    click LANG3 "https://github.com/nucleoidai/nucleoid/tree/main/src/lang/estree"
    click LANG4 "https://github.com/nucleoidai/nucleoid/blob/main/python/nucleoid/parse.py"

    %% Click Events for Data and Knowledge Graph
    click DATA1 "https://github.com/nucleoidai/nucleoid/blob/main/src/graph.js"
    click DATA2 "https://github.com/nucleoidai/nucleoid/blob/main/src/datastore.js"
    click DATA3 "https://github.com/nucleoidai/nucleoid/blob/main/python/nucleoid/graph.py"

    %% Click Events for Integration & Library Modules
    click INT1 "https://github.com/nucleoidai/nucleoid/tree/main/arc/src/lib"
    click INT2 "https://github.com/nucleoidai/nucleoid/tree/main/src/lib"

    %% Click Event for Multi-language Support
    click MULTI1 "https://github.com/nucleoidai/nucleoid/tree/main/python"

    %% Click Events for Evaluation & Training Data
    click EVAL1 "https://github.com/nucleoidai/nucleoid/tree/main/arc/src/data/evaluation"
    click EVAL2 "https://github.com/nucleoidai/nucleoid/tree/main/arc/src/data/training"
    click EVAL3 "https://github.com/nucleoidai/nucleoid/tree/main/arc/src/instruct_dataset"
```
