How thedhanawada/sf-monitor works
Project Type and Purpose
• This is an open-source, multi-package Node.js monorepo delivering a Salesforce observability platform.
• It consists of:
• A CLI tool (“packages/cli”) for terminal-based monitoring and deployment tracking
• A VS Code extension (“packages/vscode”) providing UI components (TreeView, Webviews, Status Bar)
• A shared core library (“packages/shared”) containing all monitoring and authentication logic
File Structure Highlights
• Root package.json likely configures npm workspaces for three child packages.
• packages/shared:
• Core modules: sfauth.js, monitor.js, deploymentMonitor.js, alerts.js
• packages/cli:
• Bin script (sf-monitor.js) invokes shared logic
• CLI-specific glue: cliMonitor.js, cliAlerts.js, config.js
• packages/vscode:
• extension.js as entry point to VS Code Extension Host
• UI modules: limitsTreeProvider.js, deploymentMonitorPanel.js, notificationManager.js, statusBarManager.js
• Webpack config to build dist/*.vsix
Key Architectural Concepts (from README)
• Core Monitoring
• Poll Salesforce Limits API via shared monitor module
• Authenticate via SF CLI (child process “sf org display --json”)
• Emit events on threshold breaches
• Deployment Tracking
• Wrap SF CLI commands in a child process to intercept deployments
• Poll Metadata API for real-time status, compute deltas
• VS Code Integration
• Extension Host communicates with Webview panels via message passing
• TreeView provider surfaces live metric updates
a. Main Components
• CLI Application
• VS Code Extension (Extension Host, Webview UI)
• Shared Core Library (Monitoring, Auth, Alerts, Deployment Monitor)
• Salesforce CLI (external process)
• Salesforce Org & APIs (Limits API, Metadata API)
b. Interactions and Data Flow
• CLI/VS Code → invoke shared sfauth to retrieve access tokens from SF CLI
• Shared monitor/deploymentMonitor modules → call Salesforce REST APIs
• Shared modules emit Node.js EventEmitter events → consumed by CLI console output or VS Code UI
• Deployment tracking wraps SF CLI commands, streams output back through shared event bus
c. Architectural Patterns and Principles
• Monorepo with clear separation of concerns (UI vs. business logic vs. external integration)
• Event‐driven core powered by EventEmitter
• Adapter pattern for SF CLI integration (child process wrapper)
• Observer pattern for real-time updates to UI (listeners in CLI and Extension Host)
d. Technologies & Frameworks
• Node.js 18+, npm workspaces
• jsforce or direct REST calls for Salesforce Limits API / Metadata API
• Salesforce CLI (sf or sfdx)
• VS Code Extension API (TreeView, Webview, StatusBar)
• Webpack for VS Code packaging
Essential Elements
• Arrowheads for data flow direction
• Notes on authentication flow (SF CLI → token → shared sfauth)
• Event bus between shared core and UI layers