How vedanta/dfo works
1. Overall shape
- dfo is a Python CLI for FinOps optimization, centered on a pipeline: discover → analyze → report → execute.
- The architecture is layered and modular: Azure-specific data collection sits behind provider wrappers, then domain analysis and rules operate on local data, and execution writes audit state back to DuckDB.
2. Entry points and command surface
- The CLI entrypoint is src/dfo/cli.py, with command groups implemented under src/dfo/cmd/.
- Major user-facing areas are azure, config, db, rules, status, version, plus Azure subcommands for discovery, reporting, execution, and logs.
3. Current provider boundary
- src/dfo/providers/azure/ is the cloud adapter layer for Azure SDK access.
- It is split by concern: compute inventory, monitor metrics, advisor, pricing, cost, resource graph, and a client wrapper.
- This is the only implemented cloud provider in the repo, but the structure is clearly meant to be extensible to AWS/GCP later.
4. Discovery and inventory
- src/dfo/discover/vms.py collects VM inventory and related telemetry from Azure.
- src/dfo/inventory/ holds query and formatting logic for browsing/filtering/searching inventory results.
- Discovery feeds normalized resource data into the local database so later analysis and reporting do not need to hit Azure again.
5. Analysis layer
- src/dfo/analyze/ contains rule-like detectors for VM efficiency issues: idle VMs, low CPU, stopped VMs, and compute mapping.
- These analyzers operate on stored inventory/metrics rather than calling Azure directly, which keeps the decision layer deterministic and testable.
- The analysis output becomes the source of truth for reports and execution plans.
6. Rules subsystem
- src/dfo/rules/ stores JSON-based rule definitions such as vm_rules.json and storage_rules.json.
- The repo docs indicate a “rules-driven CLI” design, so rules are treated as configurable optimization policy separate from code.
- This makes the architecture policy-driven: detectors identify candidates, rules decide how they are categorized or acted upon.
7. Local data store
- src/dfo/db/ is the persistence boundary, using DuckDB as the local embedded database.
- schema.sql and init_data.sql define the canonical local schema and seed data, while duck.py encapsulates database access.
- The database is the central integration point for discoveries, findings, execution plans, and audit logs.
8. Reporting pipeline
- src/dfo/report/ collects analysis results and renders them to console, JSON, or CSV.
- Formatters are separated by output channel: console output for interactive use, structured JSON for automation, CSV for exports.
- This layer is read-only: it transforms stored findings into human- or machine-consumable views without changing domain state.
9. Execution workflows
- src/dfo/execute/ contains the action layer for making changes in Azure.
- It supports two distinct paths: direct execution (direct.py, azure_executor.py, stop_vms.py) and plan-based execution (plan_manager.py, approvals.py, rollback.py).
- Validators and the azure_validator.py/validators.py modules enforce safety checks before live changes happen.
10. Safety and auditability
- Live operations default to dry-run, and the system requires explicit confirmation flags for real changes.
- action_logger.py records every action, including dry-runs, into the local database for auditability.
- Protection tags such as dfo-protected=true are part of the safety boundary that prevents accidental changes.
11. Core services and shared models
- src/dfo/core/ contains shared configuration, auth, and data models used across the system.
- config.py and auth.py bridge environment/config settings with Azure credentials, while models.py provides common domain structures.
- src/dfo/common/ holds cross-cutting utilities like terminal formatting and visualizations.
12. Testing and delivery
- The repo is heavily test-driven, with extensive unit and integration coverage under src/dfo/tests/ plus top-level rule tests.
- CI is GitHub Actions-based, and the project is packaged as a Python CLI using pyproject.toml.
- Example scripts in examples/ and Azure helper scripts in tools/azure/ support manual validation and onboarding.
13. How data flows end-to-end
- Azure credentials and config are loaded first, then discovery pulls VM and metric data into DuckDB.
- Analysis and rules evaluate the stored data to produce findings.
- Reporting reads findings back out of DuckDB.
- Execution uses those findings or direct user input to trigger Azure actions, then logs results and, if needed, rollback/approval state locally.
14. Architectural boundary to note in a diagram
- The key boundary is between external Azure services and the local decision system.
- Everything on the left side of that boundary is Azure API interaction through provider wrappers; everything on the right side is local compute, storage, policy, and audit logic.
- DuckDB is the shared backbone connecting discovery, analysis, reporting, and execution.
Main entry points: cli.py CLI entry · vms.py VM discovery · execution.py Execution · duck.py DuckDB store
Components 24
CLI surface
User-facing command entrypoints and subcommands
- CLI entry · Main command dispatcher for the application
src/dfo/cli.py - Azure cmd · Azure-facing command group and discovery/reporting entrypoints
src/dfo/cmd/azure.py - Execute cmd · Execution command surface for direct and planned actions
src/dfo/cmd/azure_execute.py - Config cmd · Configuration command surface
src/dfo/cmd/config.py - DB cmd · Local database command surface
src/dfo/cmd/db.py - Rules cmd · Rule inspection and policy command surface
src/dfo/cmd/rules.py - Status cmd · Status and health command surface
src/dfo/cmd/status.py - Version cmd · Version command surface
src/dfo/cmd/version.py
Azure boundary
Provider wrappers around Azure APIs
- Azure client · Shared Azure SDK client wrapper
src/dfo/providers/azure/client.py - Compute API · Azure VM and compute inventory access
src/dfo/providers/azure/compute.py - Monitor API · Azure metrics and telemetry access
src/dfo/providers/azure/monitor.py - Advisor API · Azure advisor recommendations access
src/dfo/providers/azure/advisor.py - Pricing API · Azure pricing and SKU lookup access
src/dfo/providers/azure/pricing.py - Cost API · Azure cost data access
src/dfo/providers/azure/cost.py - Resource graph · Azure resource graph query access
src/dfo/providers/azure/resource_graph.py
Local pipeline
Discovery, analysis, storage, reporting, and execution inside the repo
- VM discovery · Pulls Azure VM inventory and related telemetry into local storage
src/dfo/discover/vms.py - DuckDB store · Embedded database for discoveries, findings, plans, and audit state
src/dfo/db/duck.py - Analysis · Deterministic detection layer for efficiency issues
src/dfo/analyze/__init__.py - Rules · JSON-based optimization policy and categorization rules
src/dfo/rules/vm_rules.json - Inventory · Query and formatting layer for stored inventory results
src/dfo/inventory/queries.py - Reporting · Formats stored findings for console, JSON, and CSV
src/dfo/report/json_report.py - Execution · Validates, approves, executes, and rolls back Azure actions
src/dfo/execute/execution.py - Core models · Shared config, auth, and domain models
src/dfo/core/models.py - Common utils · Cross-cutting terminal and visualization helpers
src/dfo/common/visualizations.py
Connections 26
- CLI entry → Azure cmd: dispatches · Main CLI routes into Azure command group
- CLI entry → Execute cmd: dispatches · Main CLI routes into execution commands
- CLI entry → Config cmd: dispatches · Main CLI routes into config commands
- CLI entry → DB cmd: dispatches · Main CLI routes into database commands
- CLI entry → Rules cmd: dispatches · Main CLI routes into rule commands
- CLI entry → Status cmd: dispatches · Main CLI routes into status commands
- CLI entry → Version cmd: dispatches · Main CLI routes into version command
- Azure cmd → VM discovery: starts · Azure command triggers VM discovery
- Azure cmd → Reporting: renders · Azure command exposes report views
- Execute cmd → Execution: invokes · Execution command hands off to workflow engine
- VM discovery → Azure client: uses · Discovery relies on shared Azure client wrapper
- VM discovery → Compute API: reads · Discovery pulls compute inventory
- VM discovery → Monitor API: reads · Discovery pulls metrics and telemetry
- VM discovery → DuckDB store: writes · Normalized discovery data is stored locally
- Analysis → DuckDB store: reads · Analysis evaluates stored local data
- Analysis → Rules: applies · Detectors are shaped by policy rules
- Inventory → DuckDB store: queries · Inventory browsing reads from DuckDB
- Reporting → DuckDB store: reads · Reports are generated from persisted findings
- Reporting → Common utils: formats · Report output uses shared presentation helpers
- Execution → DuckDB store: logs · Execution writes actions and audit state
- Execution → Azure client: uses · Execution uses Azure client access
- Execution → Compute API: acts on · Execution targets compute resources
- Execution → Monitor API: validates · Execution may consult telemetry for safety checks
- Execution → Core models: shares · Execution uses shared config and models
- VM discovery → Core models: shares · Discovery uses shared config and auth
- Reporting → Core models: shares · Reporting uses common models