# lh3/ropebwt3 architecture

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

- Interactive diagram: https://gitdiagram.com/lh3/ropebwt3
- Repository: https://github.com/lh3/ropebwt3

## Overview

##### Main Components

a) Core Components:
- BWT Construction Module
- Search Engine Module
- File Format Handlers
- Memory Management System

b) Input/Output Components:
- Sequence Input Handler
- Index Output Handler
- Search Results Generator

**┌─ User Interface Layer ─────────────────────┐**
- Command Line Interface (main.c)          │
- Input/Output Handlers (io.c, io.h)       │
- ┬─────────────────────────┘
- ↓
**┌─ Core Processing Layer ───────────────────┐**
- ┌─ BWT Construction ─┐ ┌─ Search Engine ─┐│
- RopeBWT Builder  │ │ - MEM Finder    ││
- FM-Index Creator │ │ - BWA-SW Aligner││
- ┘ └─────────────────┘│
- ┬─────────────────────┘
- ↓
**┌─ Data Structure Layer ──────────────────┐**
- FM-Index (fm-index.c)                 │
- Rope Data Structure (rope.c, mrope.c) │
- Run-Length Encoding (rle.c)           │
- ┬────────────────────┘
- ↓
**┌─ Support Layer ────────────────────────┐**
- Memory Allocator (kalloc.c)          │
- Thread Management (kthread.c)         │
- Suffix Array Construction (sais-ss.c) │
- ┘

##### Key Elements to Highlight

- Blue: Input/Output components
- Green: Core processing modules
- Yellow: Data structures
- Gray: Support utilities

- Double lines: Heavy data transfer paths

##### Technical Details

Annotations for:
- OpenMP parallelization support
- Memory-mapping capabilities for FMD format
- Run-length encoding compression
- Backward search implementation

##### Interface Points

Highlight:
- Command-line interface entry points
- File I/O interfaces
- External tool integration points (e.g., seqtk)

##### Performance Characteristics

Notes about:
- Optimization for highly redundant sequence sets
- Compression capabilities (7.3Tb → 30GB)
- Search performance characteristics

This design should reflect both the tool's sophisticated internal architecture and its practical application in processing large-scale genomic data sets.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef ui fill:#B3E0FF,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef data fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef support fill:#E6E6E6,stroke:#333,stroke-width:2px
    
    subgraph UI["User Interface Layer"]
        CLI["Command Line Interface"]:::ui
        IO["Input/Output Handlers"]:::ui
    end

    subgraph Core["Core Processing Layer"]
        subgraph BWT["BWT Construction"]
            Builder["RopeBWT Builder"]:::core
            BWTConst["BWT Constructor"]:::core
        end
        
        subgraph Search["Search Engine"]
            MEM["MEM Finder"]:::core
            BWA["BWA-SW Aligner"]:::core
            BackExt["Backward Extension"]:::core
        end
    end

    subgraph Data["Data Structure Layer"]
        FMIndex["FM-Index"]:::data
        Rope["Rope Data Structure"]:::data
        RLE["Run-Length Encoding"]:::data
        RLCFM["Run-Length Compressed FM-Index"]:::data
    end

    subgraph Support["Support Layer"]
        MemAlloc["Memory Allocator"]:::support
        ThreadMgmt["Thread Management"]:::support
        SuffixArray["Suffix Array Construction"]:::support
        AlignUtils["Alignment Utilities"]:::support
    end

    %% Connections
    UI --> Core
    Core --> Data
    Data --> Support

    %% Click events
    click CLI "https://github.com/lh3/ropebwt3/blob/master/main.c"
    click IO "https://github.com/lh3/ropebwt3/blob/master/io.c"
    click BWTConst "https://github.com/lh3/ropebwt3/blob/master/build.c"
    click MEM "https://github.com/lh3/ropebwt3/blob/master/search.c"
    click BWA "https://github.com/lh3/ropebwt3/blob/master/bwa-sw.c"
    click FMIndex "https://github.com/lh3/ropebwt3/blob/master/fm-index.c"
    click Rope "https://github.com/lh3/ropebwt3/blob/master/rope.c"
    click RLE "https://github.com/lh3/ropebwt3/blob/master/rle.c"
    click MemAlloc "https://github.com/lh3/ropebwt3/blob/master/kalloc.c"
    click ThreadMgmt "https://github.com/lh3/ropebwt3/blob/master/kthread.c"
    click SuffixArray "https://github.com/lh3/ropebwt3/blob/master/sais-ss.c"
    click RLCFM "https://github.com/lh3/ropebwt3/blob/master/rld0.c"
    click AlignUtils "https://github.com/lh3/ropebwt3/blob/master/align.h"
    click BackExt "https://github.com/lh3/ropebwt3/blob/master/bre.c"

    %% Legend
    subgraph Legend
        UI_L["User Interface"]:::ui
        Core_L["Core Processing"]:::core
        Data_L["Data Structures"]:::data
        Support_L["Support Utilities"]:::support
    end
```
