# api-rbtest/rbctest architecture

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

- Interactive diagram: https://gitdiagram.com/api-rbtest/rbctest
- Repository: https://github.com/api-rbtest/rbctest

## Overview

##### Project Type and Purpose
- This is a research-focused, command-line tool (an open-source toolkit) for mining and testing RESTful API constraints by combining static (LLM-based) and dynamic (Daikon‐based) approaches. It ingests API specifications and runtime traces, infers constraints, generates tests, and evaluates results.

##### Top-Level Components
1. RBCTest_dataset/ — self-collected OpenAPI specs and CSV traces for 8 services
2. agora_dataset/ — AGORA’s OpenAPI specs and trace CSVs
3. AGORA-eval/ — dynamic invariant results (Daikon CSVs, Excel sheets)
4. approaches/ —
- ground_truth/ — benchmark “true” constraints (Excel)
- ablation/ — results for ablation studies
- rbctest_agora_data/ & rbctest_our_data/ — detected constraints and evaluation outcomes (Excel, CSV)

B. Core Code Modules (Blue rectangles) under src/
1. Constraint Mining
- request_response_constraint_mining.py
- response_property_constraint_mining.py
- ablation variants: request_response_constraint_mining_ablation.py, response_property_constraint_mining_ablation.py
2. Test Generation
- constraints_test_generation.py
3. Evaluation
- evaluate_constraints_mining.py
- evaluate_test_gen.py
- src/eval/ (eval_invariants.py, request_approach_evaluate.py, response_approach_evaluate.py)
4. Utility Libraries (src/utils/)
- openapi_utils.py (parses OpenAPI specs)
- gptcall.py (wraps OpenAI API calls)
- convert_json_to_excel*.py, extract_request_response.py, dict_utils.py, etc.
5. Response Verification (src/response_body_verification/)
- constraint_inference.py, data_model_building.py, parameter_responsebody_mapping.py
6. Verifier (src/verifier/)
- example_verifier.py, find_example_utils.py
7. Orchestrator / CLI Entry Points
- verifier.py

C. External Services (Orange clouds)
- OpenAI API (for static, LLM-based mining)
- Daikon tool (dynamic invariant generation, CSVs under AGORA-eval/agora/)

1. Input Flow
[RBCTest_dataset/, agora_dataset/] → OpenAPI parser (openapi_utils) → JSON models
[RBCTest_dataset/ CSV traces] → dynamic pipeline (Daikon or overlapping_analysis)
2. Constraint Mining
- Static path: JSON models + gptcall → request/response constraint results → approaches/rbctest_our_data & approaches/rbctest_agora_data
- Dynamic path: Daikon CSVs → AGORA-eval → overlapping_analysis → Excel reports
3. Test Generation
- constraints_test_generation.py reads mined constraints → generates test cases → writes to approaches/rbctest_*_data
4. Evaluation
- evaluate_constraints_mining.py and src/eval/* modules compare mined vs ground truth → outputs CSV/Excel in approaches/ and AGORA-eval
- evaluate_test_gen.py analyzes test outcomes → writes to approaches/rbctest_our_data/test_outcomes_analyze.csv
5. Utility Invocations
- JSON/Excel conversions, request-response extraction flow through utils/* modules
6. Final Outputs
[approaches/, AGORA-eval/] → researcher review

##### Architectural Patterns and Principles
- Modularity: separate scripts for each major step (mining, generation, evaluation)
- Layered processing: Data ingestion → mining → generation → evaluation → reporting
- Extensibility: new mining strategies or datasets can plug into src/
- Reusability: utility and verification libraries factored out into src/utils/ and src/verifier/

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Data Sources & External Tools
  subgraph "Data Sources & External Tools"
    direction TB
    ds1[(RBCTest_dataset)]:::datastore
    click ds1 "https://github.com/api-rbtest/rbctest/tree/main/RBCTest_dataset/"
    ds2[(agora_dataset)]:::datastore
    click ds2 "https://github.com/api-rbtest/rbctest/tree/main/agora_dataset/"
    ds3[(AGORA-eval)]:::datastore
    click ds3 "https://github.com/api-rbtest/rbctest/tree/main/AGORA-eval/"
    ext1(OpenAI API):::external
    ext2(Daikon):::external
  end

  %% Mining & Generation
  subgraph "Mining & Generation"
    direction TB
    subgraph "Constraint Mining"
      direction TB
      crm["Request-Response Constraint Mining"]:::code
      click crm "https://github.com/api-rbtest/rbctest/blob/main/src/request_response_constraint_mining.py"
      rppm["Response-Property Constraint Mining"]:::code
      click rppm "https://github.com/api-rbtest/rbctest/blob/main/src/response_property_constraint_mining.py"
      crma["Request-Response Mining (Ablation)"]:::code
      click crma "https://github.com/api-rbtest/rbctest/blob/main/src/request_response_constraint_mining_ablation.py"
      rppma["Response-Property Mining (Ablation)"]:::code
      click rppma "https://github.com/api-rbtest/rbctest/blob/main/src/response_property_constraint_mining_ablation.py"
    end
    ut1["OpenAPI Parser"]:::code
    click ut1 "https://github.com/api-rbtest/rbctest/blob/main/src/utils/openapi_utils.py"
    ut2["GPT Call Wrapper"]:::code
    click ut2 "https://github.com/api-rbtest/rbctest/blob/main/src/utils/gptcall.py"
    gen["Test Generation"]:::code
    click gen "https://github.com/api-rbtest/rbctest/blob/main/src/constraints_test_generation.py"
  end

  %% Evaluation & Reports
  subgraph "Evaluation & Reports"
    direction TB
    ec["Eval Constraint Mining"]:::code
    click ec "https://github.com/api-rbtest/rbctest/blob/main/src/evaluate_constraints_mining.py"
    et["Eval Test Generation"]:::code
    click et "https://github.com/api-rbtest/rbctest/blob/main/src/evaluate_test_gen.py"
    subgraph "Invariant Evaluation Modules"
      direction TB
      ei["eval_invariants.py"]:::code
      click ei "https://github.com/api-rbtest/rbctest/blob/main/src/eval/eval_invariants.py"
      ea["request_approach_evaluate.py"]:::code
      click ea "https://github.com/api-rbtest/rbctest/blob/main/src/eval/request_approach_evaluate.py"
      er["response_approach_evaluate.py"]:::code
      click er "https://github.com/api-rbtest/rbctest/blob/main/src/eval/response_approach_evaluate.py"
    end
    ds4[(approaches/ground_truth)]:::datastore
    click ds4 "https://github.com/api-rbtest/rbctest/tree/main/approaches/ground_truth/"
    ds5[(approaches/ablation)]:::datastore
    click ds5 "https://github.com/api-rbtest/rbctest/tree/main/approaches/ablation/"
    ds6[(approaches/rbctest_agora_data)]:::datastore
    click ds6 "https://github.com/api-rbtest/rbctest/tree/main/approaches/rbctest_agora_data/"
    ds7[(approaches/rbctest_our_data)]:::datastore
    click ds7 "https://github.com/api-rbtest/rbctest/tree/main/approaches/rbctest_our_data/"
  end

  %% Utilities & Verification
  subgraph "Utilities & Verification"
    direction TB
    je["convert_json_to_excel"]:::code
    click je "https://github.com/api-rbtest/rbctest/blob/main/src/utils/convert_json_to_excel.py"
    ja["convert_json_to_excel_annotation_file"]:::code
    click ja "https://github.com/api-rbtest/rbctest/blob/main/src/utils/convert_json_to_excel_annotation_file.py"
    erx["extract_request_response"]:::code
    click erx "https://github.com/api-rbtest/rbctest/blob/main/src/utils/extract_request_response.py"
    du["dict_utils"]:::code
    click du "https://github.com/api-rbtest/rbctest/blob/main/src/utils/dict_utils.py"
    v1["constraint_inference"]:::code
    click v1 "https://github.com/api-rbtest/rbctest/blob/main/src/response_body_verification/constraint_inference.py"
    v2["data_model_building"]:::code
    click v2 "https://github.com/api-rbtest/rbctest/blob/main/src/response_body_verification/data_model_buiding.py"
    v3["parameter_responsebody_mapping"]:::code
    click v3 "https://github.com/api-rbtest/rbctest/blob/main/src/response_body_verification/parameter_responsebody_mapping.py"
    ver["example_verifier"]:::code
    click ver "https://github.com/api-rbtest/rbctest/blob/main/src/verifier/example_verifier.py"
    fuss["find_example_utils"]:::code
    click fuss "https://github.com/api-rbtest/rbctest/blob/main/src/verifier/find_example_utils.py"
    cli["Orchestrator CLI"]:::code
    click cli "https://github.com/api-rbtest/rbctest/blob/main/src/verifier.py"
  end

  %% Data Flows
  ds1 --> ut1
  ds2 --> ut1
  ut1 --> crm
  ut1 --> rppm
  ext1 -.-> ut2
  ut2 --> crm
  ut2 --> rppm
  crm --> ds6
  rppm --> ds6
  crma --> ds5
  rppma --> ds5
  crm --> gen
  rppm --> gen
  gen --> ds6
  gen --> ds7

  ds1 -->|CSV Traces| ext2
  ext2 --> ds3

  ds6 --> ec
  ds7 --> ec
  ds4 --> ec
  ds5 --> ec
  ei --> ec
  ea --> ec
  er --> ec
  ec --> ds6
  et --> ds7

  ds7 --> et

  %% Orchestration
  cli --> crm
  cli --> rppm
  cli --> gen
  cli --> ec
  cli --> et

  %% Styles
  classDef code fill:#add8e6,stroke:#333,stroke-width:1px
  classDef datastore fill:#90ee90,stroke:#333,stroke-width:1px
  classDef external fill:#ffa500,stroke:#333,stroke-width:1px
```
