# ai4se4ai-lab/sikg architecture

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

- Interactive diagram: https://gitdiagram.com/ai4se4ai-lab/sikg
- Repository: https://github.com/ai4se4ai-lab/sikg

## Overview

##### Project type and purpose
- This is a VS Code extension (open-source developer tool) named “SIKG” that builds a semantic knowledge graph of your code, analyzes changes, and prioritizes/runs tests accordingly.

##### File structure
- Top-level:
- package.json, tsconfig.json, README.md – extension manifest, build config, docs
- src/extension.ts – activation entry point
- src/services/ – integration services (GitService, TestRunnerService)
- src/sikg/ – core knowledge-graph logic (SIKGManager, CodeParser, ChangeAnalyzer, TestParser, TestPrioritizer, GraphTypes)
- src/ui/ – UI components (StatusBarManager, SIKGViewProvider for webview)
- src/utils/ – config and logging utilities

##### Extract architecture insights from README
- Components: graph builder, change analyzer, impact propagator, self-learning engine, UI visualizer
- External dependencies: Git for diffs, VS Code UI, test runners

##### Main components and their interactions
A. Extension Host & Activation
B. Services Layer
- GitService: fetches diffs/commits
- TestRunnerService: executes test suites and returns results
C. Core Graph Engine (sikg/)
1. CodeParser & TestParser – scan workspace to identify code entities & tests → produce initial graph nodes
2. SIKGManager – holds in-memory graph (GraphTypes) and weights
3. ChangeAnalyzer – consumes Git diff + parsed graph → marks changed nodes
4. TestPrioritizer – propagates impact through graph edges → scores tests
5. Self-learning loop – after TestRunnerService returns results, SIKGManager adjusts edge weights
D. UI Layer
- SIKGViewProvider – renders interactive impact graph in webview
- StatusBarManager – shows status/progress in VS Code status bar
E. Utilities
- ConfigManager – reads extension settings
- Logger – logs debug/info to output channel

##### Architectural patterns & design principles
- Modular layering: Services / Core / UI / Utils
- Event-driven command handlers (VS Code API)
- Knowledge-graph model (nodes & edges) for domain logic
- Feedback loop for self-learning (observer pattern)

##### Technologies & frameworks
- TypeScript, Node.js, VS Code Extension API
- Graph data structures in memory (no external DB)
- VS Code Webview API for visualization

## Diagram (Mermaid)

```mermaid
graph TB
    %% Developer Workspace
    DeveloperWorkspace["Developer Workspace"]:::external

    %% Extension Host
    ExtensionHost["VS Code Extension Host\n(TypeScript / Node.js / VS Code API)"]:::host

    %% Subgraphs
    subgraph "Services Layer"
        direction TB
        GitService["GitService"]:::services
        TestRunnerService["TestRunnerService"]:::services
    end

    subgraph "Core Graph Engine"
        direction TB
        CodeParser["CodeParser"]:::core
        TestParser["TestParser"]:::core
        SIKGManager["SIKGManager\n(In-memory Graph)"]:::core
        ChangeAnalyzer["ChangeAnalyzer"]:::core
        TestPrioritizer["TestPrioritizer"]:::core
        GraphTypes["GraphTypes"]:::core
    end

    subgraph "UI Layer"
        direction TB
        StatusBarManager["StatusBarManager"]:::ui
        SIKGViewProvider["SIKGViewProvider\n(Webview)"]:::ui
    end

    subgraph "Utilities"
        direction TB
        ConfigManager["ConfigManager"]:::utils
        Logger["Logger"]:::utils
    end

    subgraph "External Systems"
        direction TB
        GitRepo["Git CLI / Repository"]:::external
        TestFrameworks["Test Runner Frameworks"]:::external
    end

    %% Edges
    DeveloperWorkspace -->|activates| ExtensionHost
    ExtensionHost -->|initializes| GitService
    ExtensionHost -->|initializes| TestRunnerService
    ExtensionHost -->|registers commands| CodeParser
    ExtensionHost -->|registers commands| ChangeAnalyzer
    ExtensionHost -->|registers commands| TestPrioritizer

    GitService -->|fetch diffs| ChangeAnalyzer
    CodeParser -->|build nodes| SIKGManager
    TestParser -->|build test nodes| SIKGManager
    ChangeAnalyzer -->|mark changes| SIKGManager
    SIKGManager -->|provides graph| TestPrioritizer
    TestPrioritizer -->|score tests| SIKGManager
    SIKGManager -->|graph data| SIKGViewProvider
    SIKGViewProvider -->|visualize| DeveloperWorkspace
    StatusBarManager -->|status updates| DeveloperWorkspace

    SIKGViewProvider -->|run tests| TestRunnerService
    TestRunnerService -->|test results| SIKGManager

    ConfigManager --> ExtensionHost
    ConfigManager --> GitService
    ConfigManager --> TestRunnerService
    ConfigManager --> SIKGManager

    Logger --> ExtensionHost
    Logger --> GitService
    Logger --> TestRunnerService
    Logger --> SIKGManager
    Logger --> ChangeAnalyzer
    Logger --> TestPrioritizer

    GitRepo --> GitService
    TestFrameworks --> TestRunnerService

    %% Click events
    click ExtensionHost "https://github.com/ai4se4ai-lab/sikg/blob/main/src/extension.ts"
    click GitService "https://github.com/ai4se4ai-lab/sikg/blob/main/src/services/GitService.ts"
    click TestRunnerService "https://github.com/ai4se4ai-lab/sikg/blob/main/src/services/TestRunnerService.ts"
    click CodeParser "https://github.com/ai4se4ai-lab/sikg/blob/main/src/sikg/CodeParser.ts"
    click TestParser "https://github.com/ai4se4ai-lab/sikg/blob/main/src/sikg/TestParser.ts"
    click SIKGManager "https://github.com/ai4se4ai-lab/sikg/blob/main/src/sikg/SIKGManager.ts"
    click ChangeAnalyzer "https://github.com/ai4se4ai-lab/sikg/blob/main/src/sikg/ChangeAnalyzer.ts"
    click TestPrioritizer "https://github.com/ai4se4ai-lab/sikg/blob/main/src/sikg/TestPrioritizer.ts"
    click GraphTypes "https://github.com/ai4se4ai-lab/sikg/blob/main/src/sikg/GraphTypes.ts"
    click SIKGViewProvider "https://github.com/ai4se4ai-lab/sikg/blob/main/src/ui/SIKGViewProvider.ts"
    click StatusBarManager "https://github.com/ai4se4ai-lab/sikg/blob/main/src/ui/StatusBarManager.ts"
    click ConfigManager "https://github.com/ai4se4ai-lab/sikg/blob/main/src/utils/ConfigManager.ts"
    click Logger "https://github.com/ai4se4ai-lab/sikg/blob/main/src/utils/Logger.ts"

    %% Styles
    classDef services fill:#bbdefb,stroke:#1e88e5
    classDef core fill:#c8e6c9,stroke:#43a047
    classDef ui fill:#ffe0b2,stroke:#fb8c00
    classDef utils fill:#eeeeee,stroke:#9e9e9e
    classDef external fill:#e1bee7,stroke:#8e24aa
    classDef host fill:#d1c4e9,stroke:#6a1b9a
```
