# voutcn/megahit architecture

> Architecture diagram of the GitHub repository voutcn/megahit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/voutcn/megahit
- Repository: https://github.com/voutcn/megahit

## Overview

MEGAHIT is a command-line NGS assembler whose principal workflow takes sequencing reads and produces assembled contigs. The sampled entry point dispatches commands, and the assembly driver references graph-cleaning algorithms and contig output; README usage documents read inputs and final.contigs.fa. Separate commands support local assembly, iterative edge extraction, and library building. The graph preserves those capabilities and the core sequence, graph, and data-structure layers. Some pipeline links rely on README-level behavior or are unverified because their implementations were not excerpted.

Main entry points: [`src/main.cpp`](https://github.com/voutcn/megahit/blob/master/src/main.cpp) (Command dispatcher), [`src/main_assemble.cpp`](https://github.com/voutcn/megahit/blob/master/src/main_assemble.cpp) (Assembly command), [`src/localasm/local_assemble.cpp`](https://github.com/voutcn/megahit/blob/master/src/localasm/local_assemble.cpp) (Local assembly), [`src/idba/contig_graph.cpp`](https://github.com/voutcn/megahit/blob/master/src/idba/contig_graph.cpp) (Local contig graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Command entry"]
  node_cli["Command dispatcher<br/>[main.cpp]"]
  node_assemble_cmd["Assembly command<br/>[main_assemble.cpp]"]
end

subgraph group_reads["Read processing"]
  node_read_input["Sequence readers<br/>[fastx_reader.h]"]
  node_sequence_lib["Sequence libraries<br/>[sequence_lib.h]"]
  node_read_sort["Read sorting<br/>[base_engine.cpp]"]
  node_sdbg_build["SDBG construction<br/>[seq_to_sdbg.cpp]"]
end

subgraph group_assembly["Graph assembly"]
  node_sdbg["Succinct de Bruijn graph<br/>[sdbg.h]"]
  node_unitig_graph["Unitig graph<br/>[unitig_graph.cpp]"]
  node_cleaning["Graph cleaning<br/>[all_algo.h]"]
  node_contig_output["Contig output<br/>[contig_output.h]"]
end

subgraph group_extensions["Additional workflows"]
  node_local_cmd["Local assembly<br/>[local_assemble.cpp]"]
  node_hash_mapper["Contig hash mapper<br/>[hash_mapper.cpp]"]
  node_contig_graph["Local contig graph<br/>[contig_graph.cpp]"]
  node_iterate_cmd["Iterative extraction<br/>[main_iterate.cpp]"]
  node_buildlib_cmd["Library building<br/>[main_buildlib.cpp]"]
end

subgraph group_internals["Core data structures"]
  node_sequence_package["Packed sequences<br/>[sequence_package.h]"]
  node_contig_reader["Contig reader<br/>[contig_reader.h]"]
  node_hash_graph["Hash graph<br/>[hash_graph.h]"]
  node_kmer["K-mer representation<br/>[kmer.h]"]
  node_bit_vectors["Bit-vector primitives<br/>[kmbitvector.h]"]
  node_hash_map["Parallel hash map<br/>[phmap.h]"]
  node_xxhash["Hash functions<br/>[xxhash.h]"]
end

node_user(("Assembler user"))

node_user -->|"runs"| node_cli
node_cli -->|"dispatches"| node_assemble_cmd
node_cli -->|"dispatches"| node_local_cmd
node_cli -->|"dispatches"| node_iterate_cmd
node_cli -->|"dispatches"| node_buildlib_cmd
node_user -->|"supplies reads"| node_read_input
node_read_input -.->|"loads libraries"| node_sequence_lib
node_sequence_lib -.->|"packs sequences"| node_sequence_package
node_read_input -.->|"provides reads"| node_read_sort
node_read_sort -.->|"sorts for graph"| node_sdbg_build
node_sdbg_build -.->|"constructs graph"| node_sdbg
node_assemble_cmd -->|"assembles from"| node_sdbg
node_assemble_cmd -->|"runs algorithms"| node_cleaning
node_assemble_cmd -->|"writes contigs"| node_contig_output
node_contig_output -->|"produces contigs"| node_user
node_local_cmd -->|"builds mapper"| node_hash_mapper
node_local_cmd -->|"assembles graph"| node_contig_graph
node_local_cmd -->|"reads libraries"| node_sequence_lib
node_hash_mapper -->|"loads contigs"| node_contig_reader
node_contig_graph -.->|"uses graph"| node_hash_graph
node_unitig_graph -->|"uses graph data"| node_sdbg
node_unitig_graph -->|"uses bit vectors"| node_bit_vectors
node_contig_graph -->|"uses k-mers"| node_kmer
node_contig_graph -.->|"uses map"| node_hash_map
node_hash_mapper -->|"uses map"| node_hash_map
node_hash_map -.->|"hashes keys"| node_xxhash

click node_cli "https://github.com/voutcn/megahit/blob/master/src/main.cpp"
click node_assemble_cmd "https://github.com/voutcn/megahit/blob/master/src/main_assemble.cpp"
click node_read_input "https://github.com/voutcn/megahit/blob/master/src/sequence/io/fastx_reader.h"
click node_sequence_lib "https://github.com/voutcn/megahit/blob/master/src/sequence/io/sequence_lib.h"
click node_sequence_package "https://github.com/voutcn/megahit/blob/master/src/sequence/sequence_package.h"
click node_read_sort "https://github.com/voutcn/megahit/blob/master/src/sorting/base_engine.cpp"
click node_sdbg_build "https://github.com/voutcn/megahit/blob/master/src/sorting/seq_to_sdbg.cpp"
click node_sdbg "https://github.com/voutcn/megahit/blob/master/src/sdbg/sdbg.h"
click node_unitig_graph "https://github.com/voutcn/megahit/blob/master/src/assembly/unitig_graph.cpp"
click node_cleaning "https://github.com/voutcn/megahit/blob/master/src/assembly/all_algo.h"
click node_contig_output "https://github.com/voutcn/megahit/blob/master/src/assembly/contig_output.h"
click node_contig_reader "https://github.com/voutcn/megahit/blob/master/src/sequence/io/contig/contig_reader.h"
click node_local_cmd "https://github.com/voutcn/megahit/blob/master/src/localasm/local_assemble.cpp"
click node_hash_mapper "https://github.com/voutcn/megahit/blob/master/src/localasm/hash_mapper.cpp"
click node_contig_graph "https://github.com/voutcn/megahit/blob/master/src/idba/contig_graph.cpp"
click node_iterate_cmd "https://github.com/voutcn/megahit/blob/master/src/main_iterate.cpp"
click node_buildlib_cmd "https://github.com/voutcn/megahit/blob/master/src/main_buildlib.cpp"
click node_hash_graph "https://github.com/voutcn/megahit/blob/master/src/idba/hash_graph.h"
click node_kmer "https://github.com/voutcn/megahit/blob/master/src/idba/kmer.h"
click node_bit_vectors "https://github.com/voutcn/megahit/blob/master/src/kmlib/kmbitvector.h"
click node_hash_map "https://github.com/voutcn/megahit/blob/master/src/parallel_hashmap/phmap.h"
click node_xxhash "https://github.com/voutcn/megahit/blob/master/src/xxhash/xxhash.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_assemble_cmd,node_user toneBlue
class node_read_input,node_sequence_lib,node_read_sort,node_sdbg_build toneAmber
class node_sdbg,node_unitig_graph,node_cleaning,node_contig_output toneMint
class node_local_cmd,node_hash_mapper,node_contig_graph,node_iterate_cmd,node_buildlib_cmd toneRose
class node_sequence_package,node_contig_reader,node_hash_graph,node_kmer,node_bit_vectors,node_hash_map,node_xxhash toneIndigo
```

## Components

### Command entry

- [Command dispatcher](https://github.com/voutcn/megahit/blob/master/src/main.cpp): `src/main.cpp`
- [Assembly command](https://github.com/voutcn/megahit/blob/master/src/main_assemble.cpp): `src/main_assemble.cpp`

### Read processing

- [Sequence readers](https://github.com/voutcn/megahit/blob/master/src/sequence/io/fastx_reader.h): `src/sequence/io/fastx_reader.h`
- [Sequence libraries](https://github.com/voutcn/megahit/blob/master/src/sequence/io/sequence_lib.h): `src/sequence/io/sequence_lib.h`
- [Read sorting](https://github.com/voutcn/megahit/blob/master/src/sorting/base_engine.cpp): `src/sorting/base_engine.cpp`
- [SDBG construction](https://github.com/voutcn/megahit/blob/master/src/sorting/seq_to_sdbg.cpp): `src/sorting/seq_to_sdbg.cpp`

### Graph assembly

- [Succinct de Bruijn graph](https://github.com/voutcn/megahit/blob/master/src/sdbg/sdbg.h): `src/sdbg/sdbg.h`
- [Unitig graph](https://github.com/voutcn/megahit/blob/master/src/assembly/unitig_graph.cpp): `src/assembly/unitig_graph.cpp`
- [Graph cleaning](https://github.com/voutcn/megahit/blob/master/src/assembly/all_algo.h): `src/assembly/all_algo.h`
- [Contig output](https://github.com/voutcn/megahit/blob/master/src/assembly/contig_output.h): `src/assembly/contig_output.h`

### Additional workflows

- [Local assembly](https://github.com/voutcn/megahit/blob/master/src/localasm/local_assemble.cpp): `src/localasm/local_assemble.cpp`
- [Contig hash mapper](https://github.com/voutcn/megahit/blob/master/src/localasm/hash_mapper.cpp): `src/localasm/hash_mapper.cpp`
- [Local contig graph](https://github.com/voutcn/megahit/blob/master/src/idba/contig_graph.cpp): `src/idba/contig_graph.cpp`
- [Iterative extraction](https://github.com/voutcn/megahit/blob/master/src/main_iterate.cpp): `src/main_iterate.cpp`
- [Library building](https://github.com/voutcn/megahit/blob/master/src/main_buildlib.cpp): `src/main_buildlib.cpp`

### Core data structures

- [Packed sequences](https://github.com/voutcn/megahit/blob/master/src/sequence/sequence_package.h): `src/sequence/sequence_package.h`
- [Contig reader](https://github.com/voutcn/megahit/blob/master/src/sequence/io/contig/contig_reader.h): `src/sequence/io/contig/contig_reader.h`
- [Hash graph](https://github.com/voutcn/megahit/blob/master/src/idba/hash_graph.h): `src/idba/hash_graph.h`
- [K-mer representation](https://github.com/voutcn/megahit/blob/master/src/idba/kmer.h): `src/idba/kmer.h`
- [Bit-vector primitives](https://github.com/voutcn/megahit/blob/master/src/kmlib/kmbitvector.h): `src/kmlib/kmbitvector.h`
- [Parallel hash map](https://github.com/voutcn/megahit/blob/master/src/parallel_hashmap/phmap.h): `src/parallel_hashmap/phmap.h`
- [Hash functions](https://github.com/voutcn/megahit/blob/master/src/xxhash/xxhash.h): `src/xxhash/xxhash.h`

### Other components

- **Assembler user**

## Connections

- Assembler user → Command dispatcher: runs
- Command dispatcher → Assembly command: dispatches (evidence: `src/main.cpp`)
- Command dispatcher → Local assembly: dispatches (evidence: `src/main.cpp`)
- Command dispatcher → Iterative extraction: dispatches (evidence: `src/main.cpp`)
- Command dispatcher → Library building: dispatches (evidence: `src/main.cpp`)
- Assembler user → Sequence readers: supplies reads
- Sequence readers → Sequence libraries: loads libraries
- Sequence libraries → Packed sequences: packs sequences
- Sequence readers → Read sorting: provides reads
- Read sorting → SDBG construction: sorts for graph
- SDBG construction → Succinct de Bruijn graph: constructs graph
- Assembly command → Succinct de Bruijn graph: assembles from
- Assembly command → Graph cleaning: runs algorithms (evidence: `src/assembly/all_algo.h`)
- Assembly command → Contig output: writes contigs (evidence: `src/main_assemble.cpp`)
- Contig output → Assembler user: produces contigs
- Local assembly → Contig hash mapper: builds mapper (evidence: `src/localasm/local_assemble.cpp`)
- Local assembly → Local contig graph: assembles graph (evidence: `src/localasm/local_assemble.cpp`)
- Local assembly → Sequence libraries: reads libraries (evidence: `src/localasm/local_assemble.cpp`)
- Contig hash mapper → Contig reader: loads contigs (evidence: `src/localasm/hash_mapper.cpp`)
- Local contig graph → Hash graph: uses graph
- Unitig graph → Succinct de Bruijn graph: uses graph data
- Unitig graph → Bit-vector primitives: uses bit vectors (evidence: `src/assembly/unitig_graph.cpp`)
- Local contig graph → K-mer representation: uses k-mers
- Local contig graph → Parallel hash map: uses map
- Contig hash mapper → Parallel hash map: uses map
- Parallel hash map → Hash functions: hashes keys
