# mpanczyk/sim architecture

> Architecture diagram of the GitHub repository mpanczyk/sim, 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/mpanczyk/sim
- Repository: https://github.com/mpanczyk/sim

## Overview

##### Main Components

a) Input Processing Layer:
- Language-specific lexers (represented by *lang.l files)
- UTF-8/UTF-16 handling (utf8.c/h)
- File handling system (ForEachFile.c/h)

b) Core Processing Engine:
- Three-Pass Architecture (pass1.c/h, pass2.c/h, pass3.c/h)
- Token Management (token.c/h, tokenarray.c/h)
- Hash System (hash.c/h)

c) Analysis Components:
- Similarity Detection Engine (compare.c/h)
- Percentage Calculation (percentages.c/h)
- Run Management (runs.c/h, add_run.c/h)

d) Support Systems:
- Memory Management (Malloc.c/h)
- Stream Handling (stream.c/h)
- Error Handling (error.c/h)

**[Input Files] → [Language Lexer] → [Processing Pipeline] → [Analysis Engine] → [Output Results]**

##### Important Relationships to Highlight

- How the lexer outputs feed into the token management system
- Relationship between the three passes
- Demonstrate how the hash system supports similarity detection
- Error handling paths throughout the system

##### Technical Details

- Token transformation process
- Hash table implementation
- Memory management strategy
- File handling mechanisms
- Language-specific preprocessing steps

##### Specific Implementation Notes

- Configuration paths (settings.par, system.par)
- Debug system integration (debug.c/h)
- How different language processors are plugged into the system
- Database interaction points (*_db.i files)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        IF[Input Files]
        LexSys[Language Lexers]:::lexer
        UTF[UTF-8 Handler]:::support
        FH[File Handler]:::support
    end

    subgraph Core["Core Processing Engine"]
        direction TB
        TM[Token Management]:::core
        HS[Hash System]:::core
        subgraph Passes["Three-Pass System"]
            direction TB
            P1[Pass 1]:::pass
            P2[Pass 2]:::pass
            P3[Pass 3]:::pass
        end
    end

    subgraph Analysis["Analysis Components"]
        direction TB
        SDE[Similarity Detection]:::analysis
        PC[Percentage Calculator]:::analysis
        RM[Run Manager]:::analysis
    end

    subgraph Support["Support Systems"]
        direction TB
        MM[Memory Manager]:::support
        SH[Stream Handler]:::support
        EH[Error Handler]:::support
        DB[Debug System]:::support
        CF[Configuration]:::support
    end

    IF --> LexSys
    LexSys --> UTF
    UTF --> FH
    FH --> TM

    TM --> P1
    P1 --> P2
    P2 --> P3
    HS --- Passes

    P3 --> SDE
    SDE --> PC
    PC --> RM

    MM --- Core
    SH --- Core
    EH --- Core
    DB --- Core
    CF --- Core

    %% Component Mappings
    click LexSys "https://github.com/mpanczyk/sim/blob/master/clang.l"
    click UTF "https://github.com/mpanczyk/sim/blob/master/utf8.c"
    click FH "https://github.com/mpanczyk/sim/blob/master/ForEachFile.c"
    click P1 "https://github.com/mpanczyk/sim/blob/master/pass1.c"
    click P2 "https://github.com/mpanczyk/sim/blob/master/pass2.c"
    click P3 "https://github.com/mpanczyk/sim/blob/master/pass3.c"
    click TM "https://github.com/mpanczyk/sim/blob/master/token.c"
    click HS "https://github.com/mpanczyk/sim/blob/master/hash.c"
    click SDE "https://github.com/mpanczyk/sim/blob/master/compare.c"
    click PC "https://github.com/mpanczyk/sim/blob/master/percentages.c"
    click RM "https://github.com/mpanczyk/sim/blob/master/runs.c"
    click MM "https://github.com/mpanczyk/sim/blob/master/Malloc.c"
    click SH "https://github.com/mpanczyk/sim/blob/master/stream.c"
    click EH "https://github.com/mpanczyk/sim/blob/master/error.c"
    click DB "https://github.com/mpanczyk/sim/blob/master/debug.c"
    click CF "https://github.com/mpanczyk/sim/blob/master/settings.par"

    %% Styling
    classDef lexer fill:#1f77b4
    classDef core fill:#2ca02c
    classDef pass fill:#ff7f0e
    classDef analysis fill:#d62728
    classDef support fill:#9467bd

    %% Legend
    subgraph Legend
        L1[Language Processing]:::lexer
        L2[Core Components]:::core
        L3[Pass Components]:::pass
        L4[Analysis Components]:::analysis
        L5[Support Systems]:::support
    end
```
