# ruby-numo/numo-narray architecture

> Architecture diagram of the GitHub repository ruby-numo/numo-narray, 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/ruby-numo/numo-narray
- Repository: https://github.com/ruby-numo/numo-narray

## Overview

##### Main Architectural Components
- Ruby API Layer – Represented by the code in the lib folder (especially lib/numo/narray.rb and related files). This is the public interface that users interact with.
- C Extension Layer – The core computation routines and performance-critical operations are implemented in native code under ext/numo/narray and its subdirectories. Also include the FFT components from the fft directory.
- Code Generation Pipeline – Under ext/numo/narray/gen, the library uses a set of ERB templates and Ruby scripts to generate the repetitive C code parts. This is an essential part of the build process.
- Build and Test Infrastructure – The Rakefile, test/ directory, and GitHub workflows (.github/workflows/build.yml) that compile the C code, run tests, and ensure continuous integration.
- Examples & Documentation – The notebooks (e.g., 100-narray-exercises.ipynb) and the README provide usage examples that guide the library’s interaction patterns.

##### Important Architectural Patterns and Design Principles
- Separation of Concerns – The project clearly separates the Ruby-level API from performance-oriented C implementations.
- Code Generation – Using ERB templates and a dedicated code generator indicates a meta-programming approach to reduce repetitive coding in C.
- Modular Design – With separate directories for FFT, tests, and documentation, the project is well organized to isolate functionalities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    userApp["User Application / Client Code"]:::client

    subgraph "Ruby API Layer"
        rubyAPI["Ruby API (lib/numo/narray)"]:::ruby
    end

    subgraph "C Extension Layer"
        nativeC["Native C Extensions (ext/numo/narray)"]:::c_ext
    end

    subgraph "Code Generation Pipeline"
        codeGen["Code Generation (ext/numo/narray/gen)"]:::codegen
    end

    subgraph "FFT Module"
        fftModule["FFT Module (fft)"]:::fft
    end

    subgraph "Build and Test Infrastructure"
        buildInfra["Build & Test (Rakefile, test, CI)"]:::build
    end

    subgraph "Examples & Documentation"
        docs["Examples & Docs (notebooks, README)"]:::docs
    end

    userApp -->|"imports"| rubyAPI
    rubyAPI -->|"calls_native"| nativeC
    codeGen -->|"generates_code_for"| nativeC
    nativeC -->|"integrates_with"| fftModule
    buildInfra -->|"tests_builds"| rubyAPI
    buildInfra -->|"tests_builds"| nativeC
    buildInfra -->|"verifies"| codeGen
    docs -.->|"guides_usage"| rubyAPI

    click rubyAPI "https://github.com/ruby-numo/numo-narray/blob/master/lib/numo/narray.rb"
    click nativeC "https://github.com/ruby-numo/numo-narray/tree/master/ext/numo/narray/"
    click codeGen "https://github.com/ruby-numo/numo-narray/tree/master/ext/numo/narray/gen/"
    click fftModule "https://github.com/ruby-numo/numo-narray/tree/master/fft/"
    click buildInfra "https://github.com/ruby-numo/numo-narray/tree/master/Rakefile"
    click docs "https://github.com/ruby-numo/numo-narray/blob/master/100-narray-exercises.ipynb"

    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef ruby fill:#bbf,stroke:#333,stroke-width:2px
    classDef c_ext fill:#bfb,stroke:#333,stroke-width:2px
    classDef codegen fill:#ffb,stroke:#333,stroke-width:2px
    classDef fft fill:#fbb,stroke:#333,stroke-width:2px
    classDef build fill:#fbf,stroke:#333,stroke-width:2px
    classDef docs fill:#aff,stroke:#333,stroke-width:2px
```
