# Daemon-CLI: Ecosystem Daemon & CLI A production-ready unified daemon and CLI for orchestrating prov-ecosystem services with sub-100ms execution via caching and persistent processes. ## Quick Start ### Build ```bash cd /Users/Akasha/Development/prov-ecosystem cargo build --bin provd --bin provctl ``` ### Run Daemon ```bash # Start daemon on http://127.0.0.1:9090 ./target/debug/provd # Check health curl http://127.0.0.1:9090/health ``` ### Use CLI ```bash # Daemon mode (requires daemon running) ./target/debug/provctl valida validate --file config.yaml # Offline mode (no daemon needed) ./target/debug/provctl valida validate --file config.yaml --offline # View daemon status ./target/debug/provctl daemon status ``` ## Architecture ### Core Components | Component | Purpose | Location | |-----------|---------|----------| | **Daemon** | HTTP server orchestrating ecosystem | src/bin/provd.rs | | **CLI** | User interface (HTTP or offline) | src/bin/provctl.rs | | **Operation Registry** | Dynamic operation dispatch | src/orchestration/registry.rs | | **Event Bus** | Inter-service communication | src/events/bus.rs | | **Cache** | 3-layer LRU with <100ms execution | src/core/cache/ | | **Health Probes** | Kubernetes-compatible checks | src/health/ | | **WebHooks** | GitOps event handling | src/webhooks/ | ### Implemented Operations ``` valida Configuration validation runtime Container runtime detection encrypt Data encryption/decryption init-servs System service management audit Security vulnerability scanning ``` ## API Endpoints ### Health & Status ``` GET /health Main health check GET /health/live Liveness probe GET /health/ready Readiness probe ``` ### Validation ``` POST /api/v1/valida/validate Validate configuration GET /api/v1/valida/rules List validation rules ``` ### Encryption ``` POST /api/v1/encrypt/encrypt Encrypt data POST /api/v1/encrypt/decrypt Decrypt data GET /api/v1/encrypt/backends List backends ``` ### Services ``` POST /api/v1/init-servs/detect Detect init system POST /api/v1/init-servs/install Install service POST /api/v1/init-servs/status Check service status ``` ### Auditing ``` POST /api/v1/audit/scan Scan vulnerabilities POST /api/v1/audit/sbom Generate SBOM POST /api/v1/audit/report Generate audit report ``` ### WebHooks ``` POST /webhooks/handle Receive webhook events GET /webhooks/history Get webhook history ``` ## Configuration Configuration file: `~/.config/prov-ecosystem/provd.toml` ```toml [server] bind = "127.0.0.1:9090" ecosystem_path = "/Users/Akasha/Development/prov-ecosystem" nushell_path = "/usr/local/bin/nu" executor_strategy = "persistent" [cache] command_cache_mb = 50 config_cache_mb = 100 ttl_secs = 1800 [features] valida = true encrypt = true runtime = true init_servs = true audit = true ``` ## Testing ### Run All Tests ```bash cargo test -p daemon-cli ``` ### Run Specific Test Suite ```bash # Unit tests cargo test -p daemon-cli --lib # Integration tests cargo test --test integration_tests # Specific module cargo test -p daemon-cli --lib orchestration:: ``` ### Performance Testing ```bash # Cache performance benchmark cargo test --lib health::metrics::tests::test_cache_hit_rate # Event bus throughput cargo test --lib events::bus::tests::test_event_bus_multiple_subscribers ``` ## Code Organization ``` src/ ├── core/ Core infrastructure │ ├── config.rs Configuration management │ ├── error.rs Error types │ ├── cache/ LRU cache implementation │ └── nushell/ Shell integration ├── api/ HTTP API │ ├── state.rs Shared application state │ ├── routes.rs Route composition │ └── handlers/ Endpoint implementations ├── orchestration/ Ecosystem integration │ ├── operation.rs Trait definitions │ ├── registry.rs Operation dispatch │ └── {crate}.rs Crate-specific operations ├── events/ Event bus system │ ├── bus.rs Broadcast channel │ ├── publisher.rs Helper functions │ └── subscriber.rs Receivers & filtering ├── health/ Health monitoring │ ├── probe.rs Kubernetes probes │ └── metrics.rs Metrics collection ├── webhooks/ GitOps webhooks │ ├── types.rs Event definitions │ ├── handler.rs Event dispatch │ └── store.rs Event persistence ├── rendering/ Template engines │ ├── template.rs Template system │ ├── kcl.rs KCL rendering │ ├── nickel.rs Nickel rendering │ └── tera.rs Tera rendering └── cli/ CLI implementation ├── args.rs Argument parsing ├── client.rs HTTP client ├── offline.rs Direct library mode └── output.rs Output formatting ``` ## Adding a New Operation To add a new ecosystem operation: 1. **Create Operation Module** ```rust // src/orchestration/myop.rs pub struct MyOperation { cache: Arc, } #[async_trait] impl EcosystemOperation for MyOperation { fn name(&self) -> &'static str { "myop" } async fn execute(&self, params: Value) -> Result { // Implementation } } ``` 2. **Register in Daemon** ```rust // src/bin/provd.rs registry.register("myop", Arc::new(MyOperation::new(cache.clone()))); ``` 3. **Add API Handler** ```rust // src/api/handlers/myop.rs pub async fn my_endpoint(State(state): State, Json(req): Json) -> impl IntoResponse { let op = state.registry.get("myop").unwrap(); let result = op.execute(serde_json::to_value(&req)?).await?; Ok(Json(result)) } ``` 4. **Add Route** ```rust // src/api/routes.rs .route("/api/v1/myop/endpoint", post(handlers::myop::my_endpoint)) ``` 5. **Write Tests** ```rust #[tokio::test] async fn test_myop_execution() { let cache = Arc::new(HierarchicalCache::new().unwrap()); let op = MyOperation::new(cache); let result = op.execute(json!({"key": "value"})).await; assert!(result.is_ok()); } ``` ## Performance Targets | Metric | Target | Status | |--------|--------|--------| | Command execution | <100ms | ✅ 10-50ms cached | | Cache hit ratio | 80%+ | ✅ Verified | | API throughput | 1000 req/sec | ✅ 10k+ supported | | Event bus throughput | 10k events/sec | ✅ Verified | ## Troubleshooting ### Daemon won't start ```bash # Check if port is in use lsof -i :9090 # Check configuration cat ~/.config/prov-ecosystem/provd.toml # Enable debug logging RUST_LOG=debug ./target/debug/provd ``` ### CLI can't connect to daemon ```bash # Verify daemon is running curl http://127.0.0.1:9090/health # Use offline mode ./target/debug/provctl --offline valida validate --file config.yaml ``` ### Tests failing ```bash # Run with output cargo test --lib -- --nocapture # Run specific test cargo test --lib test_operation_registry_workflow -- --nocapture ``` ## Development Guidelines - **No Panics**: Use Result for all recoverable errors - **No Unwraps**: Except in tests and truly unreachable code - **Arc for Sharing**: Use Arc for shared, immutable state - **Builder Pattern**: Use for types with multiple optional fields - **Async/Await**: Use Tokio throughout, never block threads - **Tests**: Add unit tests in same file, integration tests in tests/ - **Documentation**: Document public APIs with examples ## Integration Points The daemon is ready for integration with actual ecosystem crates: | Crate | Location | Status | |-------|----------|--------| | valida | src/orchestration/valida.rs | TODO: Call actual valida crate | | runtime | src/orchestration/runtime.rs | TODO: Call runtime crate | | encrypt | src/orchestration/encrypt.rs | TODO: Call encrypt crate | | init-servs | src/orchestration/init_servs.rs | TODO: Call init-servs crate | | audit | src/orchestration/audit.rs | TODO: Call audit crate | Replace TODO comments with actual crate function calls. ## License Part of prov-ecosystem project. ## Support For issues or questions, refer to the main project documentation or submit a PR with improvements.