How sjdpk/fsm works
Main Components
• CLI Entry Point: Represent the shell script (fsm.sh) that acts as the entry point for user commands.
• Shell Helper Scripts: Include additional scripts like fsm_info.sh, helper.sh, scripts.sh, and constants.sh. These scripts handle environment setup, logging, and configuration operations.
• Core Engine (Dart Code): This is located under src/dart. It is organized into submodules:
• Common Utilities: Files like common.dart and string_extension.dart (from the extensions directory).
• Config Module: Represents configuration functionality (src/dart/config) to parse, validate, or load configuration details about the Flutter SDK.
• Feature Module: A key component where feature-related logic is implemented. Notice the “raw” partitioning into three layers:
▸ Data Layer (src/dart/feature/raw/data): Contains files that likely handle data retrieval/storage operations.
▸ Domain Layer (src/dart/feature/raw/domain): Implements the business logic, core rules, and validations.
▸ Presentation Layer (src/dart/feature/raw/presentation): Handles user-facing content or command responses.
• Service Components: For example, file_service.dart in the “services” directory, which likely abstracts file system interactions needed to manage the Flutter SDK directories.
• External Dependencies and Environment: Although not explicitly detailed in the files, the README explains the dependency on the Flutter SDK’s structure and various shell environments (Bash, Zsh, Fish, PowerShell).
Relationships and Interactions
• When a user types a command (e.g., “fsm use 3.10.4”), it is received by the CLI entry script (fsm.sh).
• fsm.sh then possibly delegates tasks to either helper scripts (for operations that are best handled in Bash) or calls into the Dart core engine.
• Within the Dart code, the call flows through:
• The Config module (to read current configuration/state regarding Flutter SDK versions).
• The Feature module where the clean architecture’s layers interact (presentation receiving the command, the domain processing the business logic, and the data layer fetching/storing relevant information like available versions).
• Service modules (like file_service.dart) which interface with the file system to perform actions such as installing, removing, or switching SDK versions.
• Feedback is then passed back to the CLI, enabling output to the terminal.
Architectural Patterns and Design Principles
• Clean Architecture: The separation into data, domain, and presentation within the feature/raw directory clearly indicates adherence to clean architecture principles for modular and testable code.
• Command-Line Interface Pattern: The project design clearly separates CLI concerns (shell scripts) from the application logic (Dart modules).
• Layered Organization: By separating configuration, core features, and extensions, the design makes it easy to maintain and extend.
Relevant Technologies and Frameworks
• Shell Scripting: Bash, Zsh, Fish, and PowerShell support provided by different shell scripts.
• Dart: Used for the implementation of the core logic and clean architecture.
• Flutter SDK: The versioned Flutter installation directories (flutter-<version>) are managed by this tool.