# mar-file-system/gufi architecture

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

- Interactive diagram: https://gitdiagram.com/mar-file-system/gufi
- Repository: https://github.com/mar-file-system/gufi

## Overview

#### Purpose and Build Surface
GUFI (Grand Unified File-Index) is a native filesystem-indexing and query toolkit, part of MarFS. It builds primarily as C executables and shared core code through CMake. The top-level build defines the product; executable targets and common library composition are organized under:
- `CMakeLists.txt`
- `src/CMakeLists.txt`
- `config/CMakeLists.txt`

#### Primary Entry Points
The principal operational pipeline is filesystem/trace ingestion into an index, followed by SQL-oriented traversal and reporting. Core command entry points include:
- `src/gufi_dir2index.c` — walk a live directory tree and create an index.
- `src/gufi_trace2index.c` and `src/gufi_dir2trace.c` — convert between filesystem trees, traces, and indexes.
- `src/gufi_query/main.c` — query indexed trees.
Additional lifecycle tools include `src/gufi_incremental_update/main.c`, `src/gufi_rollup.c`, `src/gufi_unrollup.c`, and `src/gufi_index2dir.c`.

#### Indexing and Metadata Capture
Index construction traverses directory trees, collects file metadata, extended attributes, and optional filesystem-specific data, then materializes per-directory index databases. Traversal and worker primitives establish the parallel boundary:
- `src/gufi_dir2index.c`
- `src/descend.c`
- `src/QueuePerThreadPool.c`
Metadata/database concerns are separated into reusable modules:
- `src/dbutils.c`
- `src/xattrs.c`
- `src/template_db.c`

#### Query Execution
`gufi_query` accepts SQL-like work and executes it across indexed directories, with directory processing parallelized and results aggregated or buffered for output. Query parsing/replacement, SQL handling, and traversal are distinct stages:
- `src/gufi_query/main.c`
- `src/gufi_query/process_queries.c`
- `src/gufi_query/processdir.c`
- `src/gufi_query/handle_sql.c`
The system also exposes indexed data to SQLite-oriented clients and virtual-table workflows through:
- `src/gufi_sqlite3.c`
- `src/gufi_vt.c`
- `src/run_vt.c`

#### Aggregation, Rollups, and Incremental Maintenance
GUFI supports summarized tree metadata (“rollups”), top-down or bottom-up aggregation, and later reversal/recomputation. Incremental update detects and reindexes changed directories rather than requiring a full rebuild:
- `src/rollup.c`
- `src/gufi_rollup_topdown.c`
- `src/gufi_incremental_update/incremental_update.c`
- `src/gufi_incremental_update/reindex_dir.c`
This is a key boundary between immutable/indexed historical state and changing live filesystem state.

#### Deployment, Distribution, and Integrations
Local C binaries are complemented by shell/Python front ends for common operations and distributed scheduling. Distributed wrappers coordinate remote execution, likely using SSH and Slurm-style batch submission templates:
- `scripts/distributed/gufi_distributed.py`
- `scripts/distributed/template.sbatch.in`
- `scripts/gufi_query.py`
External infrastructure includes SQLite and extensions/patches, PCRE support, optional jemalloc, and MarFS-related integration:
- `contrib/deps/sqlite3.sh`
- `contrib/deps/sqlite-vec.sh`
- `contrib/plugins/marfs_plugin.c`
Plugins provide an extension boundary for indexing/querying and storage-system-specific metadata:
- `src/plugin.c`
- `contrib/plugins/dsi_indexing.c`
- `contrib/plugins/lustre_plugin.c`

#### Outputs and Consumers
Results can be emitted via native command-line programs, scripts implementing familiar filesystem views (`find`, `ls`, `du`, `stat`), FUSE-related binaries, and optional example interfaces. Representative consumer-facing layers are:
- `scripts/gufi_find`
- `scripts/gufi_ls`
- `src/bffuse.c`
- `examples/gui/open-ondemand/app.py`

Main entry points: [`src/template_db.c`](https://github.com/mar-file-system/gufi/blob/main/src/template_db.c) (Index databases), [`src/dbutils.c`](https://github.com/mar-file-system/gufi/blob/main/src/dbutils.c) (Metadata DB layer), [`src/gufi_query/main.c`](https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/main.c) (Query CLI), [`src/CMakeLists.txt`](https://github.com/mar-file-system/gufi/blob/main/src/CMakeLists.txt) (Core targets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build surface"]
  node_root_build["Top-level build<br/>CMake<br/>[CMakeLists.txt]"]
  node_src_build["Core targets<br/>CMake<br/>[CMakeLists.txt]"]
  node_config_build["Build configuration<br/>CMake<br/>[CMakeLists.txt]"]
end

subgraph group_index["Indexing pipeline"]
  node_dir2index{{"Directory indexer<br/>C executable<br/>[gufi_dir2index.c]"}}
  node_trace_conversion{{"Trace conversion<br/>C executables<br/>[gufi_trace2index.c]"}}
  node_traversal["Traversal engine<br/>C module<br/>[descend.c]"]
  node_worker_pool["Worker pool<br/>C module"]
  node_metadata_db[("Metadata DB layer<br/>C modules<br/>[dbutils.c]")]
  node_xattrs["Extended attributes<br/>C module<br/>[xattrs.c]"]
  node_index_db[("Index databases<br/>SQLite directory indexes<br/>[template_db.c]")]
end

subgraph group_query["Query execution"]
  node_query_cli{{"Query CLI<br/>C executable<br/>[main.c]"}}
  node_query_processing["Query processing<br/>C module<br/>[process_queries.c]"]
  node_directory_query["Directory execution<br/>C module<br/>[processdir.c]"]
  node_sql_handler["SQL handler<br/>C module<br/>[handle_sql.c]"]
  node_sqlite_interface[("SQLite interface<br/>C module<br/>[gufi_sqlite3.c]")]
  node_virtual_tables["Virtual-table runner<br/>C module<br/>[run_vt.c]"]
end

subgraph group_maintenance["Maintenance"]
  node_rollups["Rollup aggregation<br/>C modules<br/>[rollup.c]"]
  node_incremental_update{{"Incremental update<br/>C executable/module"}}
end

subgraph group_integration["Integrations and consumers"]
  node_plugins["Plugin boundary<br/>C module<br/>[plugin.c]"]
  node_distributed{{"Distributed scheduler<br/>Python frontend"}}
  node_filesystem_views["Filesystem-style views<br/>Shell frontend"]
  node_fuse{{"FUSE interface<br/>C executable<br/>[bffuse.c]"}}
end

node_root_build -->|"includes"| node_src_build
node_root_build -->|"includes"| node_config_build
node_src_build -->|"builds"| node_dir2index
node_src_build -->|"builds"| node_query_cli
node_dir2index -->|"walks through"| node_traversal
node_dir2index -->|"parallelizes with"| node_worker_pool
node_traversal -->|"captures"| node_metadata_db
node_metadata_db -->|"collects"| node_xattrs
node_metadata_db -->|"writes"| node_index_db
node_trace_conversion -->|"creates or consumes"| node_index_db
node_query_cli -->|"parses work with"| node_query_processing
node_query_processing -->|"dispatches"| node_directory_query
node_directory_query -->|"parallelizes with"| node_worker_pool
node_directory_query -->|"executes"| node_sql_handler
node_sql_handler -->|"queries"| node_index_db
node_sqlite_interface -->|"supports"| node_virtual_tables
node_virtual_tables -->|"reads"| node_index_db
node_rollups -->|"aggregates"| node_index_db
node_incremental_update -->|"detects and rewalks changes"| node_traversal
node_incremental_update -->|"updates"| node_index_db
node_plugins -.->|"extends"| node_metadata_db
node_distributed -->|"runs remotely"| node_query_cli
node_filesystem_views -->|"presents"| node_query_cli
node_fuse -->|"accesses"| node_sqlite_interface

click node_root_build "https://github.com/mar-file-system/gufi/blob/main/CMakeLists.txt"
click node_src_build "https://github.com/mar-file-system/gufi/blob/main/src/CMakeLists.txt"
click node_config_build "https://github.com/mar-file-system/gufi/blob/main/config/CMakeLists.txt"
click node_dir2index "https://github.com/mar-file-system/gufi/blob/main/src/gufi_dir2index.c"
click node_trace_conversion "https://github.com/mar-file-system/gufi/blob/main/src/gufi_trace2index.c"
click node_traversal "https://github.com/mar-file-system/gufi/blob/main/src/descend.c"
click node_worker_pool "https://github.com/mar-file-system/gufi/blob/main/src/QueuePerThreadPool.c"
click node_metadata_db "https://github.com/mar-file-system/gufi/blob/main/src/dbutils.c"
click node_xattrs "https://github.com/mar-file-system/gufi/blob/main/src/xattrs.c"
click node_index_db "https://github.com/mar-file-system/gufi/blob/main/src/template_db.c"
click node_query_cli "https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/main.c"
click node_query_processing "https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/process_queries.c"
click node_directory_query "https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/processdir.c"
click node_sql_handler "https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/handle_sql.c"
click node_sqlite_interface "https://github.com/mar-file-system/gufi/blob/main/src/gufi_sqlite3.c"
click node_virtual_tables "https://github.com/mar-file-system/gufi/blob/main/src/run_vt.c"
click node_rollups "https://github.com/mar-file-system/gufi/blob/main/src/rollup.c"
click node_incremental_update "https://github.com/mar-file-system/gufi/blob/main/src/gufi_incremental_update/incremental_update.c"
click node_plugins "https://github.com/mar-file-system/gufi/blob/main/src/plugin.c"
click node_distributed "https://github.com/mar-file-system/gufi/blob/main/scripts/distributed/gufi_distributed.py"
click node_filesystem_views "https://github.com/mar-file-system/gufi/tree/main/scripts/gufi_find"
click node_fuse "https://github.com/mar-file-system/gufi/blob/main/src/bffuse.c"

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_root_build,node_src_build,node_config_build toneBlue
class node_dir2index,node_trace_conversion,node_traversal,node_worker_pool,node_metadata_db,node_xattrs,node_index_db toneAmber
class node_query_cli,node_query_processing,node_directory_query,node_sql_handler,node_sqlite_interface,node_virtual_tables toneMint
class node_rollups,node_incremental_update toneRose
class node_plugins,node_distributed,node_filesystem_views,node_fuse toneIndigo
```

## Components

### Build surface

- [Top-level build](https://github.com/mar-file-system/gufi/blob/main/CMakeLists.txt): CMake · Defines the native product build. · `CMakeLists.txt`
- [Core targets](https://github.com/mar-file-system/gufi/blob/main/src/CMakeLists.txt): CMake · `src/CMakeLists.txt`
- [Build configuration](https://github.com/mar-file-system/gufi/blob/main/config/CMakeLists.txt): CMake · `config/CMakeLists.txt`

### Indexing pipeline

- [Directory indexer](https://github.com/mar-file-system/gufi/blob/main/src/gufi_dir2index.c): C executable · Walks live filesystem trees into indexes. · `src/gufi_dir2index.c`
- [Trace conversion](https://github.com/mar-file-system/gufi/blob/main/src/gufi_trace2index.c): C executables · Converts directory trees, traces, and indexes. · `src/gufi_trace2index.c`
- [Traversal engine](https://github.com/mar-file-system/gufi/blob/main/src/descend.c): C module · `src/descend.c`
- [Worker pool](https://github.com/mar-file-system/gufi/blob/main/src/QueuePerThreadPool.c): C module · Per-thread queue parallelism boundary. · `src/QueuePerThreadPool.c`
- [Metadata DB layer](https://github.com/mar-file-system/gufi/blob/main/src/dbutils.c): C modules · Captures metadata and materializes per-directory databases. · `src/dbutils.c`
- [Extended attributes](https://github.com/mar-file-system/gufi/blob/main/src/xattrs.c): C module · `src/xattrs.c`
- [Index databases](https://github.com/mar-file-system/gufi/blob/main/src/template_db.c): SQLite directory indexes · Persistent per-directory indexed state. · `src/template_db.c`

### Query execution

- [Query CLI](https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/main.c): C executable · Runs SQL-oriented traversal over index trees. · `src/gufi_query/main.c`
- [Query processing](https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/process_queries.c): C module · Parses and substitutes query work. · `src/gufi_query/process_queries.c`
- [Directory execution](https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/processdir.c): C module · Parallel per-directory query processing. · `src/gufi_query/processdir.c`
- [SQL handler](https://github.com/mar-file-system/gufi/blob/main/src/gufi_query/handle_sql.c): C module · `src/gufi_query/handle_sql.c`
- [SQLite interface](https://github.com/mar-file-system/gufi/blob/main/src/gufi_sqlite3.c): C module · Exposes indexed data to SQLite clients. · `src/gufi_sqlite3.c`
- [Virtual-table runner](https://github.com/mar-file-system/gufi/blob/main/src/run_vt.c): C module · `src/run_vt.c`

### Maintenance

- [Rollup aggregation](https://github.com/mar-file-system/gufi/blob/main/src/rollup.c): C modules · Computes summarized tree metadata. · `src/rollup.c`
- [Incremental update](https://github.com/mar-file-system/gufi/blob/main/src/gufi_incremental_update/incremental_update.c): C executable/module · Reindexes changed directories without a full rebuild. · `src/gufi_incremental_update/incremental_update.c`

### Integrations and consumers

- [Plugin boundary](https://github.com/mar-file-system/gufi/blob/main/src/plugin.c): C module · Extends indexing and storage metadata handling. · `src/plugin.c`
- [Distributed scheduler](https://github.com/mar-file-system/gufi/blob/main/scripts/distributed/gufi_distributed.py): Python frontend · Coordinates remote and batch execution. · `scripts/distributed/gufi_distributed.py`
- [Filesystem-style views](https://github.com/mar-file-system/gufi/tree/main/scripts/gufi_find): Shell frontend · Consumer commands such as find and ls. · `scripts/gufi_find`
- [FUSE interface](https://github.com/mar-file-system/gufi/blob/main/src/bffuse.c): C executable · `src/bffuse.c`

## Connections

- Top-level build → Core targets: includes
- Top-level build → Build configuration: includes
- Core targets → Directory indexer: builds
- Core targets → Query CLI: builds
- Directory indexer → Traversal engine: walks through
- Directory indexer → Worker pool: parallelizes with
- Traversal engine → Metadata DB layer: captures
- Metadata DB layer → Extended attributes: collects
- Metadata DB layer → Index databases: writes
- Trace conversion → Index databases: creates or consumes
- Query CLI → Query processing: parses work with
- Query processing → Directory execution: dispatches
- Directory execution → Worker pool: parallelizes with
- Directory execution → SQL handler: executes
- SQL handler → Index databases: queries
- SQLite interface → Virtual-table runner: supports
- Virtual-table runner → Index databases: reads
- Rollup aggregation → Index databases: aggregates
- Incremental update → Traversal engine: detects and rewalks changes
- Incremental update → Index databases: updates
- Plugin boundary → Metadata DB layer: extends
- Distributed scheduler → Query CLI: runs remotely
- Filesystem-style views → Query CLI: presents
- FUSE interface → SQLite interface: accesses
