# ydiaz1699/nas-dotfiles architecture

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

- Interactive diagram: https://gitdiagram.com/ydiaz1699/nas-dotfiles
- Repository: https://github.com/ydiaz1699/nas-dotfiles

## Overview

#### Purpose and operating model
nas-dotfiles is a personal Linux/NAS operations framework centered on Docker service management. It exposes the same NAS state through Bash shell shortcuts, two `svc` CLIs, and a natural-language Python agent. It manages local Compose projects, persistent service documentation, backups, diagnostics, and notifications rather than serving a web application.

#### Primary entry points
- Installation and shell bootstrap: `install.sh`, `shell/init.sh`.
- Default Bash service CLI: `docker/cli/svc.sh`; it dispatches operational libraries under `docker/cli/lib/`.
- Optional Python `svc` CLI: `svc_py/__main__.py`, `svc_py/app.py`.
- Interactive AI agent: `agent/nas_agent.py`; background process: `agent/daemon.py`.
- Persistent deployment unit: `systemd/nas-agent.service`.

#### Shell and service-control layer
The shell layer installs aliases, prompt/navigation, Docker convenience commands, and lifecycle shortcuts. The Bash `svc` command is the default operational interface and delegates Compose lifecycle, health, backup, discovery, menus, catalog synchronization, and ntfy notifications to focused shell modules.
- `shell/init.sh`
- `docker/cli/svc.sh`
- `docker/cli/lib/docker.sh`

The Python CLI is an alternative presentation/control layer using Typer, Rich, and InquirerPy. It wraps Docker/Compose and discovery behavior behind command modules, with a Bash bridge where shared shell behavior is needed.
- `svc_py/app.py`
- `svc_py/core/docker.py`
- `svc_py/core/bash_bridge.py`

#### Service catalog as source of operational truth
The catalog stores service-specific Compose definitions, environment templates, and operational “ficha” documentation. It supports a synchronization pipeline that derives or updates catalog/documentation artifacts when Compose definitions change, with optional DebMenux integration.
- `agent/catalog/catalog.json`
- `agent/catalog/_index.py`
- `agent/catalog/services/homeassistant/compose.yml`

Shared runtime settings belong in external `/docker/.env`; service secrets are intended to remain in per-service `.env` files. Docker Compose v2 is the core infrastructure boundary; managed services include Home Assistant, EMQX/MQTT, ESPHome, Node-RED, ntfy, Homepage, Filebrowser, and DataSQL.

#### AI agent orchestration
The agent converts natural-language requests into tool calls. Its core managers coordinate Compose operations, service state, backups, and persistent memory; tools are the execution boundary for shell/Docker, diagnostics, discovery, search, and catalog actions.
- `agent/nas_agent.py`
- `agent/core/compose_manager.py`
- `agent/tools/docker_tools.py`

AI provider configuration supports Gemini, AWS Bedrock, and local Ollama. The agent’s durable operator context is file-backed, allowing learned service facts and user preferences to persist across sessions.
- `agent/core/memory.py`
- `agent/memory/MEMORY.md`
- `agent/config/defaults.yml`

#### Events, daemon, and plugins
The daemon runs continuously under systemd, starting a scheduler and extensible plugins. Plugins isolate background capabilities—Docker monitoring, backups, networking, Home Assistant discovery, memory, and notifications—while the event bus and MQTT listener provide asynchronous event ingress.
- `agent/daemon.py`
- `agent/scheduler/runner.py`
- `agent/plugins/loader.py`

External integrations include Docker Engine/Compose, MQTT via EMQX and `paho-mqtt`, Home Assistant discovery, ntfy push notifications, systemd, and optional local Ollama/AWS/Gemini APIs.
- `agent/events/bus.py`
- `agent/events/mqtt_listener.py`
- `agent/plugins/notification_plugin.py`

#### Key boundaries and control flow
User command or agent request → CLI/tool/manager → Docker Compose, filesystem, or system command → normalized result → terminal output, memory update, event, or notification. The shell CLI and Python CLI are peer interfaces; the agent is a higher-level orchestrator that reuses equivalent operational primitives. Catalog files define service intent and documentation, while runtime state is obtained from Docker and host diagnostics.

Main entry points: [`agent/daemon.py`](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/daemon.py) (Agent Daemon), [`agent/nas_agent.py`](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/nas_agent.py) (NAS Agent), [`agent/tools/docker_tools.py`](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/tools/docker_tools.py) (Docker Tools), [`agent/catalog/_index.py`](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/catalog/_index.py) (Catalog Index)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Operator Interfaces"]
  node_bootstrap["Shell Bootstrap<br/>installer<br/>[init.sh]"]
  node_bash_svc["Bash svc CLI<br/>shell CLI<br/>[svc.sh]"]
  node_python_svc["Python svc CLI<br/>Typer CLI<br/>[app.py]"]
  node_bash_bridge["Bash Bridge<br/>CLI adapter<br/>[bash_bridge.py]"]
end

subgraph group_control["Service Control"]
  node_shell_docker_lib["Shell Docker Library<br/>shell module<br/>[docker.sh]"]
  node_python_docker["Python Docker Core<br/>Docker adapter<br/>[docker.py]"]
end

subgraph group_agent["AI Agent"]
  node_compose_manager["Compose Manager<br/>agent manager<br/>[compose_manager.py]"]
  node_agent{{"NAS Agent<br/>AI orchestrator<br/>[nas_agent.py]"}}
  node_docker_tools["Docker Tools<br/>tool boundary<br/>[docker_tools.py]"]
  node_memory_manager["Memory Manager<br/>durable context<br/>[memory.py]"]
  node_memory_store["Operator Memory<br/>Markdown store<br/>[MEMORY.md]"]
end

subgraph group_background["Background Automation"]
  node_systemd_service["nas-agent Service<br/>systemd unit<br/>[nas-agent.service]"]
  node_daemon["Agent Daemon<br/>background process<br/>[daemon.py]"]
  node_scheduler["Scheduler<br/>job runner<br/>[runner.py]"]
  node_plugin_loader["Plugin Loader<br/>plugin runtime<br/>[loader.py]"]
  node_event_bus["Event Bus<br/>event channel<br/>[bus.py]"]
  node_mqtt_listener["MQTT Listener<br/>event ingress<br/>[mqtt_listener.py]"]
  node_notification_plugin["Notification Plugin"]
end

subgraph group_catalog["Service Catalog"]
  node_catalog_index["Catalog Index<br/>service registry<br/>[_index.py]"]
  node_catalog_data["Catalog Metadata<br/>catalog data<br/>[catalog.json]"]
  node_service_compose["Service Compose Definitions<br/>Compose project<br/>[compose.yml]"]
end

node_docker_compose{{"Docker Engine / Compose<br/>infrastructure boundary"}}
node_mqtt["EMQX / MQTT<br/>external broker"]
node_ntfy["ntfy<br/>notification service"]

node_bootstrap -->|"exposes"| node_bash_svc
node_bash_svc -->|"dispatches"| node_shell_docker_lib
node_shell_docker_lib -->|"controls"| node_docker_compose
node_python_svc -->|"uses"| node_python_docker
node_python_svc -.->|"bridges shared behavior"| node_bash_bridge
node_python_docker -->|"controls"| node_docker_compose
node_agent -->|"invokes"| node_docker_tools
node_agent -->|"coordinates through"| node_compose_manager
node_compose_manager -->|"manages"| node_docker_compose
node_docker_tools -->|"executes operations"| node_docker_compose
node_agent -->|"updates context"| node_memory_manager
node_memory_manager -->|"persists"| node_memory_store
node_docker_tools -->|"reads and synchronizes"| node_catalog_index
node_catalog_index -->|"indexes"| node_catalog_data
node_catalog_index -->|"resolves services"| node_service_compose
node_service_compose -->|"defines deployments"| node_docker_compose
node_systemd_service -->|"starts"| node_daemon
node_daemon -->|"runs"| node_scheduler
node_daemon -->|"loads"| node_plugin_loader
node_daemon -->|"publishes events"| node_event_bus
node_mqtt_listener -->|"ingresses events"| node_event_bus
node_mqtt -->|"delivers messages"| node_mqtt_listener
node_plugin_loader -->|"loads"| node_notification_plugin
node_notification_plugin -->|"sends pushes"| node_ntfy

click node_bootstrap "https://github.com/ydiaz1699/nas-dotfiles/blob/main/shell/init.sh"
click node_bash_svc "https://github.com/ydiaz1699/nas-dotfiles/blob/main/docker/cli/svc.sh"
click node_python_svc "https://github.com/ydiaz1699/nas-dotfiles/blob/main/svc_py/app.py"
click node_bash_bridge "https://github.com/ydiaz1699/nas-dotfiles/blob/main/svc_py/core/bash_bridge.py"
click node_shell_docker_lib "https://github.com/ydiaz1699/nas-dotfiles/blob/main/docker/cli/lib/docker.sh"
click node_python_docker "https://github.com/ydiaz1699/nas-dotfiles/blob/main/svc_py/core/docker.py"
click node_compose_manager "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/core/compose_manager.py"
click node_agent "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/nas_agent.py"
click node_docker_tools "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/tools/docker_tools.py"
click node_memory_manager "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/core/memory.py"
click node_memory_store "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/memory/MEMORY.md"
click node_systemd_service "https://github.com/ydiaz1699/nas-dotfiles/blob/main/systemd/nas-agent.service"
click node_daemon "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/daemon.py"
click node_scheduler "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/scheduler/runner.py"
click node_plugin_loader "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/plugins/loader.py"
click node_event_bus "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/events/bus.py"
click node_mqtt_listener "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/events/mqtt_listener.py"
click node_notification_plugin "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/plugins/notification_plugin.py"
click node_catalog_index "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/catalog/_index.py"
click node_catalog_data "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/catalog/catalog.json"
click node_service_compose "https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/catalog/services/homeassistant/compose.yml"

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_bootstrap,node_bash_svc,node_python_svc,node_bash_bridge toneBlue
class node_shell_docker_lib,node_python_docker toneAmber
class node_compose_manager,node_agent,node_docker_tools,node_memory_manager,node_memory_store toneMint
class node_systemd_service,node_daemon,node_scheduler,node_plugin_loader,node_event_bus,node_mqtt_listener,node_notification_plugin toneRose
class node_catalog_index,node_catalog_data,node_service_compose toneIndigo
class node_docker_compose,node_mqtt,node_ntfy toneNeutral
```

## Components

### Operator Interfaces

- [Shell Bootstrap](https://github.com/ydiaz1699/nas-dotfiles/blob/main/shell/init.sh): installer · Installs shell aliases and shortcuts. · `shell/init.sh`
- [Bash svc CLI](https://github.com/ydiaz1699/nas-dotfiles/blob/main/docker/cli/svc.sh): shell CLI · Default Docker service operations interface. · `docker/cli/svc.sh`
- [Python svc CLI](https://github.com/ydiaz1699/nas-dotfiles/blob/main/svc_py/app.py): Typer CLI · Alternative interactive service interface. · `svc_py/app.py`
- [Bash Bridge](https://github.com/ydiaz1699/nas-dotfiles/blob/main/svc_py/core/bash_bridge.py): CLI adapter · `svc_py/core/bash_bridge.py`

### Service Control

- [Shell Docker Library](https://github.com/ydiaz1699/nas-dotfiles/blob/main/docker/cli/lib/docker.sh): shell module · Shared Compose lifecycle and health operations. · `docker/cli/lib/docker.sh`
- [Python Docker Core](https://github.com/ydiaz1699/nas-dotfiles/blob/main/svc_py/core/docker.py): Docker adapter · `svc_py/core/docker.py`

### AI Agent

- [Compose Manager](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/core/compose_manager.py): agent manager · Coordinates Compose operations and service state. · `agent/core/compose_manager.py`
- [NAS Agent](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/nas_agent.py): AI orchestrator · Turns natural-language requests into operational tool calls. · `agent/nas_agent.py`
- [Docker Tools](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/tools/docker_tools.py): tool boundary · Executes Docker, diagnostics, discovery, and catalog actions. · `agent/tools/docker_tools.py`
- [Memory Manager](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/core/memory.py): durable context · Persists learned service facts and user preferences. · `agent/core/memory.py`
- [Operator Memory](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/memory/MEMORY.md): Markdown store · `agent/memory/MEMORY.md`

### Background Automation

- [nas-agent Service](https://github.com/ydiaz1699/nas-dotfiles/blob/main/systemd/nas-agent.service): systemd unit · Persistent deployment unit for the daemon. · `systemd/nas-agent.service`
- [Agent Daemon](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/daemon.py): background process · Runs scheduler and plugin capabilities. · `agent/daemon.py`
- [Scheduler](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/scheduler/runner.py): job runner · `agent/scheduler/runner.py`
- [Plugin Loader](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/plugins/loader.py): plugin runtime · Loads monitoring, backup, network, memory, and notification plugins. · `agent/plugins/loader.py`
- [Event Bus](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/events/bus.py): event channel · `agent/events/bus.py`
- [MQTT Listener](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/events/mqtt_listener.py): event ingress · `agent/events/mqtt_listener.py`
- [Notification Plugin](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/plugins/notification_plugin.py): plugin · Delivers ntfy push notifications. · `agent/plugins/notification_plugin.py`

### Service Catalog

- [Catalog Index](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/catalog/_index.py): service registry · Indexes service intent and documentation. · `agent/catalog/_index.py`
- [Catalog Metadata](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/catalog/catalog.json): catalog data · `agent/catalog/catalog.json`
- [Service Compose Definitions](https://github.com/ydiaz1699/nas-dotfiles/blob/main/agent/catalog/services/homeassistant/compose.yml): Compose project · Per-service deployment definitions and templates. · `agent/catalog/services/homeassistant/compose.yml`

### Other components

- **Docker Engine / Compose**: infrastructure boundary · Runs managed NAS containers and obtains runtime state.
- **EMQX / MQTT**: external broker · Asynchronous event ingress.
- **ntfy**: notification service

## Connections

- Shell Bootstrap → Bash svc CLI: exposes
- Bash svc CLI → Shell Docker Library: dispatches
- Shell Docker Library → Docker Engine / Compose: controls
- Python svc CLI → Python Docker Core: uses
- Python svc CLI → Bash Bridge: bridges shared behavior
- Python Docker Core → Docker Engine / Compose: controls
- NAS Agent → Docker Tools: invokes
- NAS Agent → Compose Manager: coordinates through
- Compose Manager → Docker Engine / Compose: manages
- Docker Tools → Docker Engine / Compose: executes operations
- NAS Agent → Memory Manager: updates context
- Memory Manager → Operator Memory: persists
- Docker Tools → Catalog Index: reads and synchronizes
- Catalog Index → Catalog Metadata: indexes
- Catalog Index → Service Compose Definitions: resolves services
- Service Compose Definitions → Docker Engine / Compose: defines deployments
- nas-agent Service → Agent Daemon: starts
- Agent Daemon → Scheduler: runs
- Agent Daemon → Plugin Loader: loads
- Agent Daemon → Event Bus: publishes events
- MQTT Listener → Event Bus: ingresses events
- EMQX / MQTT → MQTT Listener: delivers messages
- Plugin Loader → Notification Plugin: loads
- Notification Plugin → ntfy: sends pushes
