# sjdpk/fsm architecture

> Architecture diagram of the GitHub repository sjdpk/fsm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sjdpk/fsm
- Repository: https://github.com/sjdpk/fsm

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User Command
    user["User Command"]:::external

    %% CLI Layer
    subgraph "CLI Interface"
        fsm["CLI Entry: fsm.sh"]:::shell
        fsm_info["Shell Helper: fsm_info.sh"]:::shell
        helper["Shell Helper: helper.sh"]:::shell
        scripts["Shell Helper: scripts.sh"]:::shell
        constants["Shell Helper: constants.sh"]:::shell
    end

    %% Core Engine Layer (Dart)
    subgraph "Core Engine (Dart Code)"
        common["Common Utilities: common.dart"]:::dart
        stringExt["Common Utilities: string_extension.dart"]:::dart

        subgraph "Configuration Module"
            config["Config Module"]:::dart
            configFile["Config: config.dart"]:::dart
            rawConfig["Raw Config (config/raw)"]:::dart
        end

        subgraph "Feature Module"
            subgraph "Data Layer"
                data["Data Layer"]:::dart
            end
            subgraph "Domain Layer"
                domain["Domain Layer"]:::dart
            end
            subgraph "Presentation Layer"
                presentation["Presentation Layer"]:::dart
            end
        end

        fileService["Service: File Service"]:::dart
    end

    %% Interactions
    user -->|"issues"| fsm
    fsm -->|"delegates"| fsm_info
    fsm -->|"delegates"| helper
    fsm -->|"delegates"| scripts
    fsm -->|"delegates"| constants
    fsm -->|"invokes"| common
    fsm -->|"invokes"| config
    config -->|"parses"| configFile
    config -->|"loads"| rawConfig
    fsm -->|"triggers"| presentation
    presentation -->|"forwards"| domain
    domain -->|"fetches/saves"| data
    domain -->|"calls"| fileService
    data -->|"uses"| fileService

    %% Styles
    classDef shell fill:#FFEEAD,stroke:#F3A712,stroke-width:2px;
    classDef dart fill:#CEF0CC,stroke:#2E8B57,stroke-width:2px;
    classDef external fill:#E0E0E0,stroke:#A9A9A9,stroke-width:2px;

    %% Click Events for CLI Components
    click fsm "https://github.com/sjdpk/fsm/blob/main/fsm.sh"
    click fsm_info "https://github.com/sjdpk/fsm/blob/main/src/fsm_info.sh"
    click helper "https://github.com/sjdpk/fsm/blob/main/src/helper.sh"
    click scripts "https://github.com/sjdpk/fsm/blob/main/src/scripts.sh"
    click constants "https://github.com/sjdpk/fsm/blob/main/src/constants.sh"

    %% Click Events for Core Engine Components
    click common "https://github.com/sjdpk/fsm/blob/main/src/dart/common.dart"
    click stringExt "https://github.com/sjdpk/fsm/blob/main/src/dart/extensions/string_extension.dart"
    click config "https://github.com/sjdpk/fsm/tree/main/src/dart/config"
    click configFile "https://github.com/sjdpk/fsm/blob/main/src/dart/config/config.dart"
    click rawConfig "https://github.com/sjdpk/fsm/tree/main/src/dart/config/raw"
    click data "https://github.com/sjdpk/fsm/tree/main/src/dart/feature/raw/data"
    click domain "https://github.com/sjdpk/fsm/tree/main/src/dart/feature/raw/domain"
    click presentation "https://github.com/sjdpk/fsm/tree/main/src/dart/feature/raw/presentation"
    click fileService "https://github.com/sjdpk/fsm/blob/main/src/dart/feature/services/file_service.dart"
```
