# sindrip/analysis-tool architecture

> Architecture diagram of the GitHub repository sindrip/analysis-tool, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sindrip/analysis-tool
- Repository: https://github.com/sindrip/analysis-tool

## Overview

##### Main Components

a) Frontend Layer:
- Blazor Web Application (WebApplication project)
- Component-based UI structure
- JavaScript interop capabilities

b) Analysis Core:
- Parser Component (Parser project)
- Abstract Syntax Tree (AST) Component
- Control Flow Graph (CFG) Component
- Analysis Implementations:
- Available Expressions
- Detection of Signs
- Faint Variables
- Interval Analysis
- Live Variables
- Reaching Definitions

c) Infrastructure:
- Docker containerization
- GitHub Actions CI/CD pipeline
- Heroku deployment

**[Web Interface Layer]**
- ↓  ↑
**[Analysis Service Layer]**
- ↓  ↑
**[Core Analysis Layer]**
- ↓  ↑
**[Parser Layer]**

##### Component Relationships to Highlight

a) Data Flow:
- Source code input → Parser → AST → CFG → Analysis Engines
- Analysis Results → Analysis Service → Web Interface
- User Interface → Analysis Service → Analysis Engines

b) Key Interactions:
- Parser to AST transformation
- AST to CFG conversion
- Analysis implementations utilizing the Worklist algorithm
- Web components communicating with Analysis Service

##### Detailed Component Breakdown

a) Parser Section:
**[MicroC Grammar (.g4)] → [Generated Parser] → [Parse Visitor]**
- ↓
- [Symbol Table Handler]

b) Analysis Core:
**[AST Components] → [CFG Generator] → [Analysis Framework]**
- ↓
- [Individual Analysis Implementations]

c) Web Interface:
**[Blazor Components] ↔ [Analysis Service] ↔ [State Management]**

##### Implementation Details

- Different analysis types as parallel components
- Worklist algorithm implementation
- Lattice-based analysis structure
- Relationship between different expression types (AExpr, BExpr)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        WebApp["Web Application"]:::webapp
        UIComp["UI Components"]:::ui
        AnalysisService["Analysis Service"]:::service
        StateManagement["State Management"]:::service
        
        WebApp --> UIComp
        UIComp --> AnalysisService
        AnalysisService --> StateManagement
    end

    subgraph Parser
        Grammar["MicroC Grammar"]:::parser
        GenParser["Generated Parser"]:::parser
        ParseVisitor["Parse Visitor"]:::parser
        SymbolTable["Symbol Table"]:::parser

        Grammar --> GenParser
        GenParser --> ParseVisitor
        ParseVisitor --> SymbolTable
    end

    subgraph AST
        CoreAST["Core AST"]:::ast
        AExpr["Arithmetic Expressions"]:::ast
        BExpr["Boolean Expressions"]:::ast
        Statements["Statements"]:::ast

        CoreAST --> AExpr
        CoreAST --> BExpr
        CoreAST --> Statements
    end

    subgraph CFG
        FlowGraph["Flow Graph"]:::cfg
        FlowUtil["Flow Utilities"]:::cfg

        FlowGraph --> FlowUtil
    end

    subgraph Analysis
        WorklistCore["Worklist Core"]:::analysis
        IterationSteps["Iteration Steps"]:::analysis

        subgraph "Analysis Implementations"
            AvailableExp["Available Expressions"]:::analysis
            DetectionSigns["Detection of Signs"]:::analysis
            FaintVars["Faint Variables"]:::analysis
            IntervalAnalysis["Interval Analysis"]:::analysis
            LiveVars["Live Variables"]:::analysis
            ReachingDefs["Reaching Definitions"]:::analysis
        end

        WorklistCore --> IterationSteps
        IterationSteps --> AvailableExp
        IterationSteps --> DetectionSigns
        IterationSteps --> FaintVars
        IterationSteps --> IntervalAnalysis
        IterationSteps --> LiveVars
        IterationSteps --> ReachingDefs
    end

    subgraph Infrastructure
        Docker["Docker Container"]:::infra
        CICD["GitHub Actions CI/CD"]:::infra
        
        Docker --> CICD
    end

    AnalysisService --> WorklistCore
    ParseVisitor --> CoreAST
    CoreAST --> FlowGraph
    FlowGraph --> WorklistCore

    %% Component Mappings
    click WebApp "https://github.com/sindrip/analysis-tool/tree/master/src/WebApplication"
    click UIComp "https://github.com/sindrip/analysis-tool/tree/master/src/WebApplication/Shared/Components"
    click AnalysisService "https://github.com/sindrip/analysis-tool/blob/master/src/WebApplication/Data/AnalysisService.cs"
    click StateManagement "https://github.com/sindrip/analysis-tool/blob/master/src/WebApplication/Data/AppStateService.cs"
    click Grammar "https://github.com/sindrip/analysis-tool/blob/master/src/Parser/MicroC.g4"
    click GenParser "https://github.com/sindrip/analysis-tool/tree/master/src/Parser/Generated"
    click ParseVisitor "https://github.com/sindrip/analysis-tool/blob/master/src/Parser/ParseToAstVisitor.cs"
    click SymbolTable "https://github.com/sindrip/analysis-tool/blob/master/src/Parser/SymbolTable.cs"
    click CoreAST "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/AST"
    click AExpr "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/AST/AExpr"
    click BExpr "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/AST/BExpr"
    click Statements "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/AST/Statement"
    click FlowGraph "https://github.com/sindrip/analysis-tool/blob/master/src/Analysis/CFG/FlowGraph.cs"
    click FlowUtil "https://github.com/sindrip/analysis-tool/blob/master/src/Analysis/CFG/FlowUtil.cs"
    click AvailableExp "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/Analysis/AvailableExpressions"
    click DetectionSigns "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/Analysis/DetectionOfSigns"
    click FaintVars "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/Analysis/FaintVariables"
    click IntervalAnalysis "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/Analysis/IntervalAnalysis"
    click LiveVars "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/Analysis/LiveVariables"
    click ReachingDefs "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/Analysis/ReachingDefinitions"
    click WorklistCore "https://github.com/sindrip/analysis-tool/tree/master/src/Analysis/Analysis/Worklist"
    click IterationSteps "https://github.com/sindrip/analysis-tool/blob/master/src/Analysis/Analysis/Worklist/IterationStep.cs"
    click Docker "https://github.com/sindrip/analysis-tool/tree/master/Dockerfile"
    click CICD "https://github.com/sindrip/analysis-tool/blob/master/.github/workflows/docker-publish.yml"

    %% Styles
    classDef webapp fill:#2196F3,stroke:#1565C0,color:white
    classDef ui fill:#42A5F5,stroke:#1565C0,color:white
    classDef service fill:#64B5F6,stroke:#1565C0,color:white
    classDef parser fill:#FDD835,stroke:#F9A825,color:black
    classDef ast fill:#4CAF50,stroke:#2E7D32,color:white
    classDef cfg fill:#66BB6A,stroke:#2E7D32,color:white
    classDef analysis fill:#81C784,stroke:#2E7D32,color:white
    classDef infra fill:#9E9E9E,stroke:#616161,color:white
```
