# metacall/core architecture

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

- Interactive diagram: https://gitdiagram.com/metacall/core
- Repository: https://github.com/metacall/core

## Overview

##### Main Components
- Core MetaCall Engine: Represent the central runtime component (e.g. the “metacall” core, found in source/metacall) which acts as the central dispatcher. This subsystem is responsible for managing type conversions, error handling, inter-language communication, and overall lifecycle.
- Plugin Architecture: Highlight the plugin system (source/plugin and source/plugins) where additional functionality can be added dynamically.
- Configuration and Environment: Include the configuration system (source/configuration) and environment management (source/environment) that allow customization of runtime behavior.
- Auxiliary Services: Represent supporting layers such as logging (source/log), memory management (source/memory), file system integration (source/filesystem), dynamic linking (source/dynlink), portability (source/portability), and reflection (source/reflect).
- CLI & Tools: Separate out the command-line interface component (source/cli) and developer tools, which include build scripts, CMake configuration, and Docker integration (as seen in Dockerfile, docker-compose files, and tools/).

##### Relationships and Interactions
- Plugin extension point where additional functionalities or even new loaders can be integrated at runtime.
- Interconnections with configuration management that feeds execution parameters (for instance, the configuration system passes details to the engine and language loaders).
- Interfaces between the memory management, logging, and portability layers with the core engine.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize that each language loader is self-contained and designed to interface with the core engine.
- Separation of Concerns: The core engine handles inter-language orchestration while each language loader encapsulates language-specific runtime logic.
- Interoperability: Highlight how the system abstracts language differences, providing a unified API to the developer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    UserScript["User Script/CLI"]:::cli
    CLIComponent["CLI Component"]:::cli

    %% Runtime Core Layer
    CoreEngine["Core MetaCall Engine"]:::core
    Configuration["Configuration Manager"]:::support
    Environment["Environment Manager"]:::support
    Logging["Logging Service"]:::support
    Memory["Memory Management"]:::support
    Filesystem["File System Integration"]:::support
    DynLink["Dynamic Linking"]:::support
    Portability["Portability Layer"]:::support
    Reflection["Reflection Module"]:::support

    %% Extensible Modules Layer
    LanguageLoaders["Language Loaders"]:::loaders
    PluginCore["Plugin Architecture (Core)"]:::loaders
    PluginsExtra["Plugin Architecture (Plugins)"]:::loaders

    %% Developer Tools
    DevTools["Developer Tools & Build Scripts"]:::tools

    %% Connections - User Layer
    UserScript -->|"invokes"| CLIComponent
    CLIComponent -->|"calls"| CoreEngine

    %% Connections - Core Engine interactions
    CoreEngine -->|"loads"| LanguageLoaders
    CoreEngine -->|"integrates"| PluginCore
    PluginCore -->|"extends to"| PluginsExtra
    CoreEngine -->|"configures via"| Configuration
    CoreEngine -->|"uses"| Environment
    CoreEngine -->|"logs via"| Logging
    CoreEngine -->|"manages"| Memory
    CoreEngine -->|"accesses"| Filesystem
    CoreEngine -->|"links"| DynLink
    CoreEngine -->|"runs on"| Portability
    CoreEngine -->|"reflects"| Reflection

    %% Developer Tools connecting to Core Engine
    DevTools -->|"builds"| CoreEngine

    %% Styles
    classDef core fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef loaders fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef support fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef cli fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef tools fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;

    %% Click Events
    click CoreEngine "https://github.com/metacall/core/tree/develop/source/metacall"
    click LanguageLoaders "https://github.com/metacall/core/tree/develop/source/loaders"
    click PluginCore "https://github.com/metacall/core/tree/develop/source/plugin"
    click PluginsExtra "https://github.com/metacall/core/tree/develop/source/plugins"
    click Configuration "https://github.com/metacall/core/tree/develop/source/configuration"
    click Environment "https://github.com/metacall/core/tree/develop/source/environment"
    click Logging "https://github.com/metacall/core/tree/develop/source/log"
    click Memory "https://github.com/metacall/core/tree/develop/source/memory"
    click Filesystem "https://github.com/metacall/core/tree/develop/source/filesystem"
    click DynLink "https://github.com/metacall/core/tree/develop/source/dynlink"
    click Portability "https://github.com/metacall/core/tree/develop/source/portability"
    click Reflection "https://github.com/metacall/core/tree/develop/source/reflect"
    click CLIComponent "https://github.com/metacall/core/tree/develop/source/cli"
    click DevTools "https://github.com/metacall/core/tree/develop/tools"
```
