How mslavov/shelly-forge works
Main Components
• CLI Interface & Command Handlers:
– The core CLI functionality is implemented in the “src/commands” directory with separate files for each command (build, create, debug, deploy, init, logs).
– This suggests a clear separation of concerns where each command is a discrete module.
• Core Modules & Utilities:
– Files like “src/shelly-device.ts”, “src/shelly-forge.ts”, “src/solutions-config.ts”, and “src/script-hash-cache.ts” provide core functionality such as device interactions, handling of solutions’ configurations, and caching.
• Templates and Project Scaffolding:
– The “templates/default” folder holds default project templates (including its own “src”, configuration files, and a nested “.cursor” folder with similar rules files). This module is used during the “init” command to scaffold new projects.
• Type Definitions & Integration with Shelly API:
– The “types” folder contains TypeScript definitions (e.g., for Shelly’s API, TemperatureStatus, etc.), which provides strong typing and integration points with the device APIs.
• Configuration Files:
– Configuration files like “solutions.config.json”, “.env”, “tsconfig.json”, and even misc files (gitignore, LICENSE, CONTRIBUTING.md, etc.) support various aspects of the development and deployment processes.
Relationships and Data Flow
• User Interaction:
– The user interacts with the system through CLI commands. The invocation (for example, “shelly-forge init”, “shelly-forge create”, etc.) routes into the appropriate command modules.
• Command Execution Flow:
– Each command module (e.g., build.ts, deploy.ts, etc.) orchestrates multiple lower-level modules – such as reading the “solutions.config.json”, leveraging type definitions (in “types”), and calling into core functions (like “shelly-forge.ts”) that interact with the Shelly device API.
• Project Scaffolding & Templates:
– When a new project is initiated, the “init” command pulls in the structure from the “templates/default” folder to create a baseline project.
• Live Development:
• Deployment Flow:
– The deploy command reads configuration from “solutions.config.json” (mapping scripts to target devices) and deploys the bundled script to a Shelly device via API calls defined in “ShellyAPI.d.ts” and implemented in core modules.
Architectural Patterns and Design Principles
• Modular Structure:
– The commands are decoupled into separate modules, making it easy to extend or modify behavior for each CLI command.
• Template-based Project Scaffolding:
– The use of a “templates” directory ensures that new projects have a predefined structure, reinforcing consistency.
• Interface-based Design & Type Safety:
– Usage of TypeScript with dedicated “types” files shows a commitment to strong typing and clearly defined interfaces for device APIs and other interactions.
• Configuration Driven:
– The solutions are dynamically defined via JSON “solutions.config.json,” which abstracts device-specific details and allows flexible deployment.