# kushal1o1/haul architecture

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

- Interactive diagram: https://gitdiagram.com/kushal1o1/haul
- Repository: https://github.com/kushal1o1/haul

## Overview

1. **Repository shape**
   - This repo is intentionally minimal: the architecture lives almost entirely in two shell scripts, `haul.sh` and `install.sh`.
   - There is no application framework, package manifest, or multi-module codebase; the system is a Bash-based Linux daemon plus an installer/bootstrapper.

2. **Core purpose**
   - `haul` is a file-organizing service for Linux that reacts to filesystem events and moves files into categorized destination folders.
   - Its main architectural constraint is “event-driven, not polling”: it is designed to wake only when the kernel reports a file arrival.

3. **Runtime model**
   - The daemon depends on `inotify-tools` for file events and `systemd` for lifecycle management.
   - The watcher is not meant to stay in a long-running application loop; instead it processes an event batch and exits, with `systemd` expected to restart it.

4. **Bootstrap and installation boundary**
   - `install.sh` is the setup entrypoint referenced by the README’s one-liner install path.
   - Its role is to place `haul.sh` into the user’s local bin path, make it executable, and install/start the service so the watcher becomes persistent under `systemd`.

5. **Single-script configuration boundary**
   - The configuration is embedded at the top of `~/.local/bin/haul`, not stored in separate config files.
   - This block defines the destination root, watched directories, destination folder names, and extension-to-folder routing, making the script itself the primary configuration artifact.

6. **Event ingestion subsystem**
   - The watcher uses `inotifywait` to observe one or more input folders such as `~/Downloads` and `~/Pictures/Screenshots`.
   - Relevant event types are file completion/move events like `close_write` and `moved_to`, which establish the boundary between “file is still being written” and “file is ready to sort.”

7. **Routing and categorization subsystem**
   - Incoming files are classified by the `sort_file()` logic into category folders under a configurable data root.
   - The routing map is extension-based for most files, while screenshots are treated as a special case based on source directory rather than filename extension.

8. **Filesystem transfer subsystem**
   - Once classified, files are moved into the destination hierarchy under `~/Data/` by default.
   - The move boundary is important: this is an organizer, not a copier or indexer; the source folder is expected to be cleared as files are processed.

9. **Duplicate/conflict handling**
   - The script explicitly handles two collision cases: identical content with the same name, and same name with different content.
   - Identical duplicates are silently discarded, while conflicting files are preserved by renaming with a timestamp suffix before moving.

10. **Operational interface**
   - The user-facing CLI is exposed through commands like `install`, `uninstall`, `start`, `stop`, `restart`, `status`, `logs`, `sweep`, and `version`.
   - This suggests a thin command-dispatch layer inside `haul.sh` that orchestrates service control, one-time sorting, and diagnostics rather than exposing a large API.

11. **Observability**
   - Logging goes to a user-local log file under `~/.local/share/haul/haul.log`.
   - The log captures lifecycle events, moves, duplicate skips, and conflict renames, which is the main operational trace for the system.

12. **External dependencies and environment assumptions**
   - The architecture is Linux-only and depends on `systemd`, Bash 4+, and `inotify-tools`.
   - The project assumes local-user installation and user-owned directories, not a multi-user server or cloud service model.

13. **Key diagram boundary to draw**
   - The most accurate architecture diagram would show: watched folders on one side, the Linux kernel/inotify event source in the middle, `haul` as the sorting engine, and the organized destination tree plus log file on the other side.
   - `install.sh` should be shown as a separate bootstrap path that provisions the daemon and service, while `haul.sh` remains the runtime and command surface.

Main entry points: [`haul.sh`](https://github.com/kushal1o1/haul/blob/main/haul.sh) (Command dispatch), [`install.sh`](https://github.com/kushal1o1/haul/blob/main/install.sh) (install.sh)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bootstrap["Bootstrap"]
  node_install_sh["install.sh<br/>bootstrap script<br/>[install.sh]"]
  node_systemd[("systemd<br/>service manager")]
  node_local_bin["Local bin<br/>user install path"]
end

subgraph group_runtime["Runtime"]
  node_haul_cli["haul.sh<br/>shell CLI<br/>[haul.sh]"]
  node_command_dispatch["Command dispatch<br/>CLI router<br/>[haul.sh]"]
  node_embedded_config["Config block<br/>embedded config<br/>[haul.sh]"]
  node_event_watch["Event watch<br/>inotify watcher<br/>[haul.sh]"]
  node_sort_file["Sort file<br/>routing logic<br/>[haul.sh]"]
  node_conflict_handler["Conflict handling<br/>dedupe/rename<br/>[haul.sh]"]
  node_move_engine["Move engine<br/>filesystem move<br/>[haul.sh]"]
  node_inotify_tools(("inotify-tools<br/>event source"))
end

subgraph group_storage["Storage"]
  node_watched_dirs["Watched folders<br/>source dirs"]
  node_data_root["Data root<br/>destination tree"]
  node_log_file["haul.log<br/>log file"]
end

node_install_sh -->|"installs"| node_haul_cli
node_install_sh -->|"places"| node_local_bin
node_install_sh -->|"provisions"| node_systemd
node_haul_cli -->|"exposes"| node_command_dispatch
node_command_dispatch -->|"uses"| node_embedded_config
node_command_dispatch -->|"starts"| node_event_watch
node_command_dispatch -->|"triggers"| node_move_engine
node_command_dispatch -->|"controls"| node_systemd
node_event_watch -->|"depends on"| node_inotify_tools
node_event_watch -->|"observes"| node_watched_dirs
node_event_watch -->|"hands off to"| node_sort_file
node_sort_file -->|"resolves"| node_conflict_handler
node_conflict_handler -->|"feeds"| node_move_engine
node_move_engine -->|"writes to"| node_data_root
node_move_engine -->|"logs"| node_log_file
node_systemd -->|"restarts"| node_event_watch
node_embedded_config -->|"defines"| node_watched_dirs
node_embedded_config -->|"defines"| node_data_root

click node_install_sh "https://github.com/kushal1o1/haul/blob/main/install.sh"
click node_haul_cli "https://github.com/kushal1o1/haul/blob/main/haul.sh"
click node_command_dispatch "https://github.com/kushal1o1/haul/blob/main/haul.sh"
click node_embedded_config "https://github.com/kushal1o1/haul/blob/main/haul.sh"
click node_event_watch "https://github.com/kushal1o1/haul/blob/main/haul.sh"
click node_sort_file "https://github.com/kushal1o1/haul/blob/main/haul.sh"
click node_conflict_handler "https://github.com/kushal1o1/haul/blob/main/haul.sh"
click node_move_engine "https://github.com/kushal1o1/haul/blob/main/haul.sh"

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_install_sh,node_systemd,node_local_bin toneBlue
class node_haul_cli,node_command_dispatch,node_embedded_config,node_event_watch,node_sort_file,node_conflict_handler,node_move_engine,node_inotify_tools toneAmber
class node_watched_dirs,node_data_root,node_log_file toneMint
```

## Components

### Bootstrap

Install and lifecycle setup path

- [install.sh](https://github.com/kushal1o1/haul/blob/main/install.sh): bootstrap script · Installs the daemon, makes it executable, and wires it into systemd · `install.sh`
- **systemd**: service manager · Keeps the watcher persistent by restarting it after each batch
- **Local bin**: user install path · Target location for the installed haul executable

### Runtime

Event-driven file organization service

- [haul.sh](https://github.com/kushal1o1/haul/blob/main/haul.sh): shell CLI · Single-script command surface and embedded configuration · `haul.sh`
- [Command dispatch](https://github.com/kushal1o1/haul/blob/main/haul.sh): CLI router · Handles install, uninstall, start, stop, restart, status, logs, sweep, and version · `haul.sh`
- [Config block](https://github.com/kushal1o1/haul/blob/main/haul.sh): embedded config · Defines watched folders, destination root, categories, and routing rules · `haul.sh`
- [Event watch](https://github.com/kushal1o1/haul/blob/main/haul.sh): inotify watcher · Waits for close_write and moved_to events from watched folders · `haul.sh`
- [Sort file](https://github.com/kushal1o1/haul/blob/main/haul.sh): routing logic · Classifies arrivals into destination folders by extension or source directory · `haul.sh`
- [Conflict handling](https://github.com/kushal1o1/haul/blob/main/haul.sh): dedupe/rename · Drops identical duplicates and renames conflicting files with a timestamp · `haul.sh`
- [Move engine](https://github.com/kushal1o1/haul/blob/main/haul.sh): filesystem move · Moves ready files into the organized destination tree · `haul.sh`
- **inotify-tools**: event source · Provides inotifywait for filesystem event ingestion

### Storage

User-owned paths the daemon reads and writes

- **Watched folders**: source dirs · Input folders such as Downloads and screenshots
- **Data root**: destination tree · Organized output under the user data directory
- **haul.log**: log file · User-local operational log for lifecycle, moves, duplicates, and conflicts

## Connections

- install.sh → haul.sh: installs · Copies the runtime script into the user bin path and marks it executable
- install.sh → Local bin: places · Installs the executable into the local user command path
- install.sh → systemd: provisions · Installs and starts the service so the watcher persists
- haul.sh → Command dispatch: exposes · Provides the user-facing command interface
- Command dispatch → Config block: uses · Reads the embedded runtime configuration
- Command dispatch → Event watch: starts · Launches the watcher path for ongoing sorting
- Command dispatch → Move engine: triggers · Runs one-time sweep behavior through the same move pipeline
- Command dispatch → systemd: controls · Delegates service start, stop, restart, and status operations
- Event watch → inotify-tools: depends on · Uses inotifywait to receive filesystem events
- Event watch → Watched folders: observes · Listens on configured input folders
- Event watch → Sort file: hands off to · Passes completed file events into routing logic
- Sort file → Conflict handling: resolves · Applies duplicate and rename policy before moving
- Conflict handling → Move engine: feeds · Sends the final source and destination pair for transfer
- Move engine → Data root: writes to · Moves organized files into the destination hierarchy
- Move engine → haul.log: logs · Records moves, skips, and rename actions
- systemd → Event watch: restarts · Keeps the event-driven watcher alive across batches
- Config block → Watched folders: defines · Declares which directories are monitored
- Config block → Data root: defines · Declares the destination root and category folders
