# michaelciraci/monarch-butterfly architecture

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

- Interactive diagram: https://gitdiagram.com/michaelciraci/monarch-butterfly
- Repository: https://github.com/michaelciraci/monarch-butterfly

## Overview

##### Main Components
a. Core FFT Library:
- Represented primarily by the src/lib.rs file.
- This is where the top-level functions (fft, ifft) reside.
b. Proc-Macro / Code Generation (monarch-derive):
- Located in the crates/monarch-derive directory.
- Handles compile-time transformation to generate unrolled loops using const-evaluation.
c. Benchmark Suite:
- Found in the crates/benches directory, which includes both Rust benchmark code and a Python plotting script.
- This module validates performance (comparing against other libraries, as mentioned in the README).
d. Test Suite:
- Present in the tests directory (forward.rs, inverse.rs).
- Verifies correctness and consistency of the FFT implementations.
e. CI/CD and Build Configurations:
- Includes GitHub workflows (.github/workflows/rust.yml) and Cargo configurations (.cargo/config.toml).
- Although not part of runtime architecture, these are important for continuous integration and reliable builds.
f. Assets:
- Any support artifacts such as the assets folder (e.g., log_comparison.png) that document performance comparisons.

##### Relationships and Interactions
- The core FFT library (API) relies on the proc-macro provided by the monarch-derive crate to generate its specialized FFT implementations at compile time.
- Client code (users of the library) directly calls the public methods (fft/ifft) exposed by the core library.
- The benches and tests are separate consumers of the library, aimed at performance validation and correctness respectively.
- The CI configurations ensure that any change in these components is automatically tested and built, emphasizing safe code practices (e.g., no unsafe code).

##### Architectural Patterns and Design Principles
- Modularity: The project is divided into clearly defined crates, each with a focused responsibility.
- Compile-Time Code Generation: Using proc-macros to unroll loops and generate optimal FFT kernels.
- Const-Evaluation and SIMD Optimization: The design leverages compile-time knowledge of FFT sizes to optimize performance.
- Zero Unsafe Code Emphasis: The library is designed to be completely safe in Rust.
- Separation of Concerns: Clear distinction between core functionality, code generation, and benchmarking/testing.

##### Relevant Technologies and Frameworks
- Rust and Cargo workspaces.
- Rust proc-macros for code generation.
- SIMD instructions (as detailed in the README for performance) and Rust’s const-evaluation.
- CI/CD integrations with GitHub Actions.
- Python scripting in benchmarks (for plot generation).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Application / External User"]:::external
    B["Core FFT Library"]:::core
    C["Proc-Macro Engine (monarch-derive)"]:::proc
    D["Benchmark Suite"]:::bench
    D1["Comparison Benchmark"]:::bench
    D2["Benchmark Plot Script"]:::bench
    E["Test Suite"]:::tests
    E1["Forward Test"]:::tests
    E2["Inverse Test"]:::tests
    F1["GitHub Workflow"]:::cicd
    F2["Cargo Config"]:::cicd
    G["Assets"]:::assets

    A -->|"API Calls (fft/ifft)"| B
    B -->|"Compile-Time Code Generation"| C
    B -->|"Performance Validation"| D
    B -->|"Correctness Testing"| E
    D -->|"Uses"| D1
    D -->|"Uses"| D2
    E -->|"Includes"| E1
    E -->|"Includes"| E2
    D -->|"Provides"| G
    F1 -->|"Build & Test Automation"| B
    F1 -->|"Build & Test Automation"| C
    F1 -->|"Build & Test Automation"| D
    F1 -->|"Build & Test Automation"| E
    F2 -->|"Build & Test Automation"| B
    F2 -->|"Build & Test Automation"| C
    F2 -->|"Build & Test Automation"| D
    F2 -->|"Build & Test Automation"| E

    classDef external fill:#FFCCCB,stroke:#333,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef proc fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef bench fill:#FFFFE0,stroke:#333,stroke-width:2px;
    classDef tests fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef cicd fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef assets fill:#FFA07A,stroke:#333,stroke-width:2px;

    click B "https://github.com/michaelciraci/monarch-butterfly/blob/main/src/lib.rs"
    click C "https://github.com/michaelciraci/monarch-butterfly/blob/main/crates/monarch-derive/src/lib.rs"
    click D "https://github.com/michaelciraci/monarch-butterfly/tree/main/crates/benches"
    click D1 "https://github.com/michaelciraci/monarch-butterfly/blob/main/crates/benches/benches/comparison.rs"
    click D2 "https://github.com/michaelciraci/monarch-butterfly/blob/main/crates/benches/generate_benchmark_plot.py"
    click E "https://github.com/michaelciraci/monarch-butterfly/tree/main/tests"
    click E1 "https://github.com/michaelciraci/monarch-butterfly/blob/main/tests/forward.rs"
    click E2 "https://github.com/michaelciraci/monarch-butterfly/blob/main/tests/inverse.rs"
    click F1 "https://github.com/michaelciraci/monarch-butterfly/blob/main/.github/workflows/rust.yml"
    click F2 "https://github.com/michaelciraci/monarch-butterfly/blob/main/.cargo/config.toml"
    click G "https://github.com/michaelciraci/monarch-butterfly/tree/main/assets"
```
