# cryals/fdbsqlite architecture

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

- Interactive diagram: https://gitdiagram.com/cryals/fdbsqlite
- Repository: https://github.com/cryals/fdbsqlite

## Overview

##### Project type and purpose
- This is an open-source, cross-platform CLI/TUI utility (written in C++ with sqlite3 amalgamation) for interactively and programmatically manipulating SQLite databases.
- It produces a single binary that can run in either CLI mode (automation scripts) or TUI mode (interactive text UI).

##### File structure
- Top-level:
- CMakeLists.txt + build scripts under scripts/ → build system and CI (release.yml)
- /sqlite3/ → embedded sqlite3 amalgamation (no external deps)
- src/ → application code:
– main.cpp → entry point
– Config.* → configuration loader (config.txt)
– DatabaseManager.* → core abstraction over sqlite3: execSQL, backup/restore
– CLI.* → command-line interface implementation
– TUI.* → text-UI (curses-style) implementation
- assets/ → static logos (not runtime)

##### Key insights from README
- Two modes: CLI and TUI
- Automatic backup before editing
- Configurable defaults via config.txt
- Single dependency: sqlite3 (embedded)
- Targets Windows/Linux/macOS via CMake

##### Detailed component breakdown
- main.cpp: “Entry Point & Mode Selector”
- Config Loader: reads config.txt → supplies default DB path, language, autosave flags
- CLI Module: parses arguments, dispatches commands
- TUI Module: renders text menu, captures user input
- DatabaseManager:
- execSQL(sql, &error)
- backupDatabase(path)
- restoreBackup(path)
- sqlite3 amalgamation: direct API calls (sqlite3_open, sqlite3_exec, sqlite3_close)
- Build System: CMakeLists.txt → generates build targets, scripts/build.sh/.bat → compile steps
- CI Pipeline: .github/workflows/release.yml → automates packaging and release

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User(("User")):::external

    %% User Interaction Layer
    subgraph "User Interaction Layer"
        CLI["CLI Module"]:::ui
        TUI["TUI Module"]:::ui
    end

    %% Application Layer
    subgraph "Application Layer"
        MAIN["Entry Point & Mode Selector\nmain.cpp"]:::core
        CONFIG["Config Loader\nreads config.txt"]:::core
        DBM["DatabaseManager\nexecSQL, backup, restore"]:::core
    end

    %% Data Layer
    subgraph "Data Layer"
        CONFIGTXT["config.txt"]:::data
        SQLITE["sqlite3 Engine"]:::embedded
        DBFILE[".db File"]:::data
        BACKUP["Backup File"]:::data
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        BUILD["Build System\nCMake & scripts"]:::build
        CI["CI Pipeline\nGitHub Actions"]:::build
    end

    %% Connections
    User -->|uses| MAIN
    MAIN -->|launches| CLI
    MAIN -->|launches| TUI
    CLI -->|load defaults| CONFIG
    TUI -->|load defaults| CONFIG
    CONFIG -->|reads| CONFIGTXT
    CLI -->|exec commands| DBM
    TUI -->|exec commands| DBM
    DBM -->|calls API| SQLITE
    SQLITE -->|reads/writes| DBFILE
    DBM -->|creates backup| BACKUP

    BUILD -->|produces| MAIN
    CI -->|runs| BUILD

    %% Click Events
    click CLI "https://github.com/cryals/fdbsqlite/blob/main/src/CLI.cpp"
    click TUI "https://github.com/cryals/fdbsqlite/blob/main/src/TUI.cpp"
    click CONFIG "https://github.com/cryals/fdbsqlite/blob/main/src/Config.cpp"
    click DBM "https://github.com/cryals/fdbsqlite/blob/main/src/DatabaseManager.cpp"
    click MAIN "https://github.com/cryals/fdbsqlite/blob/main/src/main.cpp"
    click SQLITE "https://github.com/cryals/fdbsqlite/blob/main/include/sqlite3/sqlite3.c"
    click BUILD "https://github.com/cryals/fdbsqlite/blob/main/CMakeLists.txt"
    click CI "https://github.com/cryals/fdbsqlite/blob/main/.github/workflows/release.yml"

    %% Styles
    classDef ui fill:#e0f7e9,stroke:#2b8c36,stroke-width:2px;
    classDef core fill:#e7f0fd,stroke:#1c478e,stroke-width:2px;
    classDef embedded fill:#fff4e5,stroke:#d57e00,stroke-width:2px;
    classDef data fill:#fdeff0,stroke:#b71c1c,stroke-width:2px,shape:cylinder;
    classDef build fill:#f4f4f4,stroke:#616161,stroke-width:2px;
    classDef external fill:#ffffff,stroke:#999999,stroke-dasharray: 5 5;
```
