# xcbclc/istock-shell architecture

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

- Interactive diagram: https://gitdiagram.com/xcbclc/istock-shell
- Repository: https://github.com/xcbclc/istock-shell

## Overview

Step 1. Identify the Main Components:
- User Interface (Frontend):
- Components built with Svelte reside in the “src/view” folder (for command windows, command input, modals, etc.).
- Store and state management are handled in “src/store” to manage cmd interactions, history, and UI state.
- The “public” folder and supporting CSS/SCSS styles in “src/style” contribute to visual rendering.

- Command-Line Engine & CLI Module:
- The “src/packages/cli” package contains the command-line interface logic (actions, templates, and utility functions) that handle user commands.
- The “src/packages/command-parser” parses and tokenizes the simple command language.

- Core Framework & Business Logic (iswork):
- The “src/packages/iswork” package provides a core framework including application context, dependency injection (via decorators and IoC), and various helper modules that manage command execution.
- It also sets up the decorators, domain management, and repository/ORM logic, suggesting a microservice/MVC-like architecture internally.

- Domain-Specific Command Processing:
- The “src/worker” folder contains worker logic split into domains (for example, “domains/ag”, “domains/global”, “domains/cdfc”, etc.). Each domain includes its own command, controller, model, and service files.
- This modular separation shows that each financial data query type (A股, 成都房产, etc.) is encapsulated within its own domain module.

- UI Component Library:
- In “src/packages/shell-ui”, a custom UI component library is provided (buttons, calendar, charts, forms), likely used by the Svelte components to render interactive parts of the shell.

Step 2. Determine Relationships and Data Flow:
- User Input Flow:
- A user interacts with the UI (via Svelte components in “src/view” and state managed through “src/store”).
- Input commands are forwarded to the CLI engine (under “src/packages/cli”), which uses the command parser (“src/packages/command-parser”) to tokenize and interpret the input.

- Command Execution Flow:
- Once parsed, the command is processed by the iswork framework’s core logic (from “src/packages/iswork”). This framework manages context, dependency injection, and then hands over execution to specific domain controllers.
- In “src/worker/domains”, the corresponding command’s controller, model, and service implementations take over to query financial data, process it, and generate output.

- UI Feedback and Output Rendering:
- The processed output returns via the command pipeline back through the CLI system, updating the state and then re-rendered in the UI output components (found under “src/view/components/output”).

Step 3. Highlight Architectural Patterns and Design Principles:
- Modularity:
- The project is broken into many independent packages (cli, command-parser, iswork, shell-ui, util) that can be individually maintained.
- Separation of Concerns:
- Frontend display and state management are clearly separated from the command parsing and business logic.
- Domain-Driven Design:
- Each financial query command is implemented in a dedicated domain folder within “src/worker/domains”, showing a focus on organizing code by business capability.
- Use of Decorators and Dependency Injection:
- The use of decorators (in iswork’s “decorators” and IoC container) allows loosely coupled modules and easier extension.

- Create distinct sections for:
- Frontend Interface (Svelte components, view, store)
- CLI/Command Parsing Layer (packages/cli and command-parser)
- Core Application Framework (iswork, including DI and application context)
- Domain Modules (each domain’s command, controller, model, service in “src/worker/domains”)
- Supporting Libraries (shell-ui components, util functions)
- Development and Build Configurations (mention Dockerfile, Vite config, tsconfig files for completeness)

- Use Clear Labels:
- Data Flow:
- Distinguish Components:
- Supporting Information:
- Technologies (Svelte, Vite, Node.js, Docker) near relevant sections.
- Annotations for key design patterns (dependency injection, modularization, separation of concerns).

- Connections:
- From “Svelte UI/Store” to “CLI Module”.
- From “CLI Module” to “Command Parser”.
- From “Command Parser” to “iswork Framework” which includes DI and message/command handling.
- From “iswork Framework” to various “Domain Modules” (each handling a financial query).
- And from “Domain Modules” back to the CLI, which then updates the UI.
- Modularity: every command domain is almost a self-contained unit making the system both extensible and maintainable.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        SvelteUI["Svelte UI Components"]:::frontend
        StateManagement["State Management"]:::frontend
        PublicAssets["Public Assets & Styles"]:::frontend
    end

    %% CLI and Command Parsing Layer
    subgraph "CLI/Parsing Layer"
        CLIEngine["CLI Engine"]:::cli
        CmdParser["Command Parser"]:::cli
    end

    %% Core Application Framework
    subgraph "Core Framework"
        IsworkFramework["iswork Framework"]:::backend
    end

    %% Domain Specific Modules
    subgraph "Domain Modules"
        DomainModules["Domain Command Processors"]:::backend
    end

    %% UI Component Library
    subgraph "UI Component Library"
        ShellUI["Shell UI Library"]:::frontend
    end

    %% Build & Configuration
    subgraph "Build & Config"
        BuildConfig["Build & Configuration"]:::config
    end

    %% Connections / Data Flow
    SvelteUI -->|"sendsCommand"| CLIEngine
    StateManagement -->|"managesState"| CLIEngine
    CLIEngine -->|"callsParser"| CmdParser
    CmdParser -->|"interpretsCmd"| IsworkFramework
    IsworkFramework -->|"executesCmd"| DomainModules
    DomainModules -->|"returnsOutput"| CLIEngine
    CLIEngine -->|"updatesUI"| SvelteUI
    CLIEngine -->|"updatesState"| StateManagement
    SvelteUI -->|"rendersUsing"| ShellUI
    BuildConfig -->|"configures"| IsworkFramework

    %% Click Events
    click SvelteUI "https://github.com/xcbclc/istock-shell/blob/main/src/view/Cmd.svelte"
    click StateManagement "https://github.com/xcbclc/istock-shell/tree/main/src/store/cmd"
    click PublicAssets "https://github.com/xcbclc/istock-shell/blob/main/src/style/main.scss"
    click CLIEngine "https://github.com/xcbclc/istock-shell/blob/main/src/packages/cli/src/index.mjs"
    click CmdParser "https://github.com/xcbclc/istock-shell/blob/main/src/packages/command-parser/src/parser.ts"
    click IsworkFramework "https://github.com/xcbclc/istock-shell/tree/main/src/packages/iswork/src/application"
    click DomainModules "https://github.com/xcbclc/istock-shell/tree/main/src/worker/domains/ag"
    click ShellUI "https://github.com/xcbclc/istock-shell/blob/main/src/packages/shell-ui/src/button/Button.svelte"
    click BuildConfig "https://github.com/xcbclc/istock-shell/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#FDE2FF,stroke:#7D3C98,stroke-width:2px;
    classDef cli fill:#D6EAF8,stroke:#21618C,stroke-width:2px;
    classDef backend fill:#D5F5E3,stroke:#239B56,stroke-width:2px;
    classDef config fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
```
