# jaf666/tooltfg architecture

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

- Interactive diagram: https://gitdiagram.com/jaf666/tooltfg
- Repository: https://github.com/jaf666/tooltfg

## Overview

##### Project Type and Purpose
- This is an open-source command-line tool (“toolTFG”) written in Python whose purpose is to simulate SOME/IP messages using the Scapy packet-crafting library.
- It reads ECU and service configuration from JSON files, performs service discovery and packet parsing, then uses Scapy to inject or sniff SOME/IP frames over a VLAN-configured network.

##### File Structure Analysis
- Top level
- README.md – high-level description
- data/ – JSON definitions
- src/ – core Python modules
- vlan/ – shell scripts for VLAN setup
- src/
- main.py – orchestration entry point
- parser.py – parses JSON configs, incoming packets
- serviceDiscovery.py – handles SOME/IP service discovery logic
- __init__.py – package marker
- data/
- ecu_data.json – ECU payload/config definitions
- services.json – SOME/IP service definitions
- vlan/
- check_interfaces.sh – verifies NICs & VLAN tagging
- vlan3.sh – applies VLAN ID 3 configuration

##### README Insights
- Confirms: Python + Scapy + JSON for simulating SOME/IP
- Data/configuration layer
- Core logic modules
- External dependencies (Scapy, OS network stack)
- Environment setup scripts

a. Main Components
1. CLI/Orchestrator: src/main.py
2. Configuration Layer: data/*.json
3. Parser Module: src/parser.py
4. Service Discovery Module: src/serviceDiscovery.py
5. Packet Engine: Scapy library
6. VLAN Setup Scripts: vlan/*.sh
7. Network Interface & OS Stack
8. External ECU or Test Network (optional)
b. Relationships & Data Flow
- User (CLI) → main.py
- main.py reads JSON files (→ parser.py)
- parser populates internal data structures → serviceDiscovery
- serviceDiscovery triggers Scapy calls → raw SOME/IP packets
- Packets exit via OS network stack → VLAN-tagged NIC → test network or ECU
- VLAN scripts run (manually or via main) to prepare the OS NIC before injection
c. Architectural Patterns & Principles
- Modular separation: orchestration vs parsing vs discovery vs packet engine
- Data-driven design: JSON configs decouple code from test scenarios
- Single responsibility: each module has one clear function
d. Key Technologies & Libraries
- Python 3.x
- Scapy for packet construction & sniffing
- JSON for configuration
- Bash for VLAN network setup

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    Operator["Operator"]:::user

    %% Configuration Layer
    subgraph "Configuration Layer"
        ECU["ecu_data.json"]:::config
        Services["services.json"]:::config
    end

    %% Core Python Modules
    subgraph "Core Python Modules"
        Init["__init__.py"]:::core
        Main["main.py"]:::core
        Parser["parser.py"]:::core
        Discovery["serviceDiscovery.py"]:::core
    end

    %% External Libraries
    subgraph "External Libraries"
        Scapy["Scapy Engine"]:::external
    end

    %% VLAN Setup Scripts
    subgraph "VLAN Setup Scripts"
        CheckIF["check_interfaces.sh"]:::script
        VLAN3["vlan3.sh"]:::script
    end

    %% Environment
    subgraph "Environment"
        OSStack["OS Network Stack"]:::env
        NIC["VLAN-tagged NIC"]:::env
        Network["Test Network / ECU"]:::env
    end

    %% Connections
    Operator -->|"invoke"| Main
    Operator -->|"manual setup"| CheckIF
    Operator -->|"manual setup"| VLAN3

    Main -->|"load JSON"| ECU
    Main -->|"load JSON"| Services
    Main -->|"invoke parser"| Parser

    Parser -->|"parsed data"| Discovery
    Discovery -->|"invoke Scapy"| Scapy

    Scapy -->|"raw packets"| OSStack
    OSStack -->|"tagged"| NIC
    NIC -->|"send/receive"| Network

    CheckIF -->|"verify/tag"| OSStack
    VLAN3 -->|"configure VLAN"| OSStack

    %% Click Events
    click Main "https://github.com/jaf666/tooltfg/blob/main/src/main.py"
    click Parser "https://github.com/jaf666/tooltfg/blob/main/src/parser.py"
    click Discovery "https://github.com/jaf666/tooltfg/blob/main/src/serviceDiscovery.py"
    click ECU "https://github.com/jaf666/tooltfg/blob/main/data/ecu_data.json"
    click Services "https://github.com/jaf666/tooltfg/blob/main/data/services.json"
    click CheckIF "https://github.com/jaf666/tooltfg/blob/main/vlan/check_interfaces.sh"
    click VLAN3 "https://github.com/jaf666/tooltfg/blob/main/vlan/vlan3.sh"
    click Init "https://github.com/jaf666/tooltfg/blob/main/src/__init__.py"

    %% Styles
    classDef core fill:#E0F7FA,stroke:#006064
    classDef config fill:#E8F5E9,stroke:#1B5E20
    classDef external fill:#FFF3E0,stroke:#E65100
    classDef script fill:#FFF3E0,stroke:#E65100
    classDef env fill:#ECEFF1,stroke:#90A4AE
    classDef user fill:#E1F5FE,stroke:#0277BD
```
