# jjocram/arms-simulation-engine architecture

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

- Interactive diagram: https://gitdiagram.com/jjocram/arms-simulation-engine
- Repository: https://github.com/jjocram/arms-simulation-engine

## Overview

##### Main Components

A. Core Simulation Engine:
- BPMN Elements Layer
- Process Execution Layer
- Token Management System
- Metrics Collection System

B. Web Service Layer:
- HTTP Interface
- Request/Response Handling
- Serialization Components

##### Component Details and Relationships

A. Core Simulation Engine Components:
1. BPMN Elements Layer:
- Relationships between BPMNElement (base class) and its implementations:
- Activities
- Events (Start, End, Time)
- Gateways (Exclusive, Parallel)
- To Process.kt as the orchestrator

2. Process Execution Layer:
- And Transition components
- Activity Execution handling
- Token flow management

3. Token Management System:
- Different token types:
- ControlToken
- ProductToken
- ResourceToken
- Token flow between elements

4. Metrics Collection System:
- ResourceMetric
- TimeDeltaMetric
- ActivityExecutorExtension

B. Web Service Layer:
- Application entry point
- Routing configuration
- Metric result handling
- Serialization utilities

##### Specific Implementation Details

**[Web Service Layer]**
- ↓
**[BPMN Parser (XMLProcess)]**
- ↓
**[Simulation Engine Core]**
- ↓
**[Metrics Collection]**

The simulation flow should be represented as:

##### Important Architectural Patterns to Highlight

- Clear separation between the web service interface and the simulation engine
- Token-based execution model
- Extensible metrics collection system
- Demonstrate the inheritance hierarchy of BPMN elements

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Web Service Layer"
        WS["Application Entry"]
        RT["Routing"]
        SER["Serialization"]
        MR["Metric Results"]
    end

    subgraph "BPMN Parser"
        XML["XML Process Parser"]
    end

    subgraph "Core Simulation Engine"
        direction TB
        subgraph "BPMN Elements"
            BE["Base Element"]
            ACT["Activities"]
            
            subgraph "Events"
                SE["Start Event"]
                EE["End Event"]
                TE["Time Event"]
            end
            
            subgraph "Gateways"
                EJG["Exclusive Join"]
                ESG["Exclusive Split"]
                PJG["Parallel Join"]
                PSG["Parallel Split"]
            end
        end

        subgraph "Process Execution"
            PE["Process"]
            PL["Place"]
            TR["Transition"]
            AE["Activity Executor"]
        end

        subgraph "Token Management"
            TK["Base Token"]
            CT["Control Token"]
            PT["Product Token"]
            RT["Resource Token"]
        end
    end

    subgraph "Metrics Collection"
        RM["Resource Metric"]
        TDM["Time Delta Metric"]
        AEX["Activity Executor Extension"]
    end

    %% Relationships
    WS --> RT
    RT --> SER
    RT --> MR
    RT --> XML
    XML --> PE
    PE --> BE
    BE --> ACT
    BE --> SE
    BE --> EE
    BE --> TE
    BE --> EJG
    BE --> ESG
    BE --> PJG
    BE --> PSG
    PE --> PL
    PE --> TR
    PE --> AE
    AE --> TK
    TK --> CT
    TK --> PT
    TK --> RT
    AE --> AEX
    AEX --> RM
    AEX --> TDM

    %% Styles
    classDef webservice fill:#FFB570
    classDef parser fill:#AED6F1
    classDef bpmn fill:#85C1E9
    classDef execution fill:#82E0AA
    classDef token fill:#F7DC6F
    classDef metrics fill:#C39BD3

    class WS,RT,SER,MR webservice
    class XML parser
    class BE,ACT,SE,EE,TE,EJG,ESG,PJG,PSG bpmn
    class PE,PL,TR,AE execution
    class TK,CT,PT,RT token
    class RM,TDM,AEX metrics

    %% Click events
    click WS "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/webService/Application.kt"
    click RT "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/webService/Routing.kt"
    click SER "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/webService/Serialization.kt"
    click MR "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/webService/MetricResult.kt"
    click XML "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/XMLProcess.kt"
    click BE "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/BPMNElement.kt"
    click ACT "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/Activity.kt"
    click SE "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/StartEvent.kt"
    click EE "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/EndEvent.kt"
    click TE "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/TimeEvent.kt"
    click EJG "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/ExclusiveJoinGateway.kt"
    click ESG "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/ExclusiveSplitGateway.kt"
    click PJG "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/ParallelJoinGateway.kt"
    click PSG "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/ParallelSplitGateway.kt"
    click PE "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/Process.kt"
    click PL "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/place/Place.kt"
    click TR "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/transition/Transition.kt"
    click AE "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/element/ActivityExecutor.kt"
    click TK "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/token/Token.kt"
    click CT "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/token/ControlToken.kt"
    click PT "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/token/ProductToken.kt"
    click RT "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/token/ResourceToken.kt"
    click RM "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/metrics/ResourceMetric.kt"
    click TDM "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/metrics/TimeDeltaMetric.kt"
    click AEX "https://github.com/jjocram/ARMS-Simulation-Engine/blob/main/src/main/kotlin/metrics/ActivityExecutorExtension.kt"
```
