# psubhajit042-tech/scengen architecture

> Architecture diagram of the GitHub repository psubhajit042-tech/scengen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/psubhajit042-tech/scengen
- Repository: https://github.com/psubhajit042-tech/scengen

## Overview

ScenGen automates scenario-driven Android GUI tests: an engineer selects an app and scenario, the agent observes the screen, reasons about an action, executes it through ADB, checks the result, and records replayable output. UIED and PaddleOCR supply widgets; a local Ollama-served Qwen2.5-VL handles action decisions and visual checks. The graph represents the root `testbot/` runtime; the README says `scen/testbot/` is a parallel copy. The OCR lab is a separate documented experimentation lane. Some subsystem links are documented or indexed rather than shown in full excerpts.

Main entry points: [`testbot/core.py`](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/core.py) (TestAgent FSM), [`testbot/memory.py`](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/memory.py) (Run memory), [`testbot/uied/detect_compo/ip_region_proposal.py`](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/ip_region_proposal.py) (Component proposal), [`testbot/roles/observer.py`](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/observer.py) (Screen observer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Test orchestration"]
  node_core["TestAgent FSM<br/>[core.py]"]
  node_registry["App scenarios<br/>[config.py]"]
  node_observer["Screen observer<br/>[observer.py]"]
  node_decider["Action decider<br/>[decider.py]"]
  node_executor["Action executor<br/>[executor.py]"]
  node_supervisor["Step supervisor<br/>[supervisor.py]"]
  node_recorder["Test recorder<br/>[recorder.py]"]
end

subgraph group_perception["Screen perception"]
  node_detector["Widget detector<br/>[detect.py]"]
  node_proposal["Component proposal"]
  node_ipdetect["Image detection<br/>[ip_detection.py]"]
  node_preprocess["Image preprocessing"]
  node_components["Component model<br/>[Component.py]"]
  node_bbox["Bounding boxes<br/>[Bbox.py]"]
  node_drawing["Detection drawing<br/>[ip_draw.py]"]
  node_fileutils["Detection files<br/>[file_utils.py]"]
  node_textdetect["OCR text detection<br/>[text_detection.py]"]
  node_ocr["PaddleOCR adapter<br/>[ocr.py]"]
  node_textmodel["Text elements<br/>[Text.py]"]
  node_merger["Widget merge<br/>[merge.py]"]
  node_element["Merged element model<br/>[Element.py]"]
end

subgraph group_reasoning["VLM reasoning"]
  node_actionprompt["Action prompts<br/>[decider.py]"]
  node_superprompt["Check prompts<br/>[supervisor.py]"]
  node_vlmclient["Ollama VLM client<br/>[llm.py]"]
end

subgraph group_device["Device and records"]
  node_memory["Run memory<br/>[memory.py]"]
  node_device_manager["ADB device control<br/>[device.py]"]
  node_logger["Runtime logging<br/>[logger.py]"]
end

subgraph group_experiments["OCR experiments"]
  node_ocr_lab["OCR benchmark and tuning<br/>[run_pipeline.py]"]
end

node_engineer(("Test operator"))
node_ollama(("Ollama Qwen VLM"))
node_android(("Android device"))

node_engineer -->|"starts test"| node_core
node_core -->|"loads scenarios"| node_registry
node_core -->|"coordinates"| node_observer
node_core -->|"coordinates"| node_decider
node_core -->|"coordinates"| node_executor
node_core -->|"coordinates"| node_supervisor
node_core -->|"coordinates"| node_recorder
node_core -->|"uses run state"| node_memory
node_core -->|"manages device"| node_device_manager
node_observer -->|"captures screen"| node_device_manager
node_observer -->|"extracts widgets"| node_detector
node_observer -->|"stores observations"| node_memory
node_detector -->|"detects components"| node_proposal
node_detector -->|"detects text"| node_textdetect
node_detector -->|"merges detections"| node_merger
node_proposal -->|"preprocesses image"| node_preprocess
node_proposal -->|"finds regions"| node_ipdetect
node_proposal -->|"draws regions"| node_drawing
node_proposal -->|"saves results"| node_fileutils
node_ipdetect -->|"builds components"| node_components
node_components -->|"uses bounds"| node_bbox
node_textdetect -->|"recognizes text"| node_ocr
node_textdetect -->|"creates text elements"| node_textmodel
node_merger -->|"builds merged elements"| node_element
node_decider -->|"builds prompts"| node_actionprompt
node_decider -->|"requests decisions"| node_vlmclient
node_decider -->|"reads run context"| node_memory
node_supervisor -->|"builds check prompts"| node_superprompt
node_supervisor -->|"checks screenshots"| node_vlmclient
node_supervisor -->|"reads run context"| node_memory
node_vlmclient -->|"sends multimodal requests"| node_ollama
node_executor -->|"issues actions"| node_device_manager
node_executor -->|"updates action history"| node_memory
node_device_manager -->|"controls via ADB"| node_android
node_recorder -->|"records history"| node_memory
node_recorder -->|"exports chat logs"| node_vlmclient
node_ocr_lab -.->|"tests OCR models"| node_ocr

click node_core "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/core.py"
click node_registry "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/config.py"
click node_observer "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/observer.py"
click node_decider "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/decider.py"
click node_executor "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/executor.py"
click node_supervisor "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/supervisor.py"
click node_recorder "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/recorder.py"
click node_memory "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/memory.py"
click node_detector "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect.py"
click node_proposal "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/ip_region_proposal.py"
click node_ipdetect "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/ip_detection.py"
click node_preprocess "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/ip_preprocessing.py"
click node_components "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/Component.py"
click node_bbox "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/Bbox.py"
click node_drawing "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/ip_draw.py"
click node_fileutils "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/file_utils.py"
click node_textdetect "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_text/text_detection.py"
click node_ocr "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_text/ocr.py"
click node_textmodel "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_text/Text.py"
click node_merger "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_merge/merge.py"
click node_element "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_merge/Element.py"
click node_actionprompt "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/prompt/decider.py"
click node_superprompt "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/prompt/supervisor.py"
click node_vlmclient "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/llm.py"
click node_device_manager "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/device.py"
click node_logger "https://github.com/psubhajit042-tech/scengen/blob/main/testbot/logger.py"
click node_ocr_lab "https://github.com/psubhajit042-tech/scengen/blob/main/ocr_lab/scripts/run_pipeline.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core,node_registry,node_observer,node_decider,node_executor,node_supervisor,node_recorder toneBlue
class node_detector,node_proposal,node_ipdetect,node_preprocess,node_components,node_bbox,node_drawing,node_fileutils,node_textdetect,node_ocr,node_textmodel,node_merger,node_element toneAmber
class node_actionprompt,node_superprompt,node_vlmclient toneMint
class node_memory,node_device_manager,node_logger toneRose
class node_ocr_lab,node_engineer,node_ollama,node_android toneIndigo
```

## Components

### Test orchestration

- [TestAgent FSM](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/core.py): `testbot/core.py`
- [App scenarios](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/config.py): `testbot/config.py`
- [Screen observer](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/observer.py): `testbot/roles/observer.py`
- [Action decider](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/decider.py): `testbot/roles/decider.py`
- [Action executor](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/executor.py): `testbot/roles/executor.py`
- [Step supervisor](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/supervisor.py): `testbot/roles/supervisor.py`
- [Test recorder](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/roles/recorder.py): `testbot/roles/recorder.py`

### Screen perception

- [Widget detector](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect.py): `testbot/uied/detect.py`
- [Component proposal](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/ip_region_proposal.py): `testbot/uied/detect_compo/ip_region_proposal.py`
- [Image detection](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/ip_detection.py): `testbot/uied/detect_compo/lib_ip/ip_detection.py`
- [Image preprocessing](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/ip_preprocessing.py): `testbot/uied/detect_compo/lib_ip/ip_preprocessing.py`
- [Component model](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/Component.py): `testbot/uied/detect_compo/lib_ip/Component.py`
- [Bounding boxes](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/Bbox.py): `testbot/uied/detect_compo/lib_ip/Bbox.py`
- [Detection drawing](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/ip_draw.py): `testbot/uied/detect_compo/lib_ip/ip_draw.py`
- [Detection files](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_compo/lib_ip/file_utils.py): `testbot/uied/detect_compo/lib_ip/file_utils.py`
- [OCR text detection](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_text/text_detection.py): `testbot/uied/detect_text/text_detection.py`
- [PaddleOCR adapter](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_text/ocr.py): `testbot/uied/detect_text/ocr.py`
- [Text elements](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_text/Text.py): `testbot/uied/detect_text/Text.py`
- [Widget merge](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_merge/merge.py): `testbot/uied/detect_merge/merge.py`
- [Merged element model](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/uied/detect_merge/Element.py): `testbot/uied/detect_merge/Element.py`

### VLM reasoning

- [Action prompts](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/prompt/decider.py): `testbot/prompt/decider.py`
- [Check prompts](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/prompt/supervisor.py): `testbot/prompt/supervisor.py`
- [Ollama VLM client](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/llm.py): `testbot/llm.py`

### Device and records

- [Run memory](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/memory.py): `testbot/memory.py`
- [ADB device control](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/device.py): `testbot/device.py`
- [Runtime logging](https://github.com/psubhajit042-tech/scengen/blob/main/testbot/logger.py): `testbot/logger.py`

### OCR experiments

- [OCR benchmark and tuning](https://github.com/psubhajit042-tech/scengen/blob/main/ocr_lab/scripts/run_pipeline.py): `ocr_lab/scripts/run_pipeline.py`

### Other components

- **Test operator**
- **Ollama Qwen VLM**
- **Android device**

## Connections

- Test operator → TestAgent FSM: starts test
- TestAgent FSM → App scenarios: loads scenarios (evidence: `testbot/core.py`)
- TestAgent FSM → Screen observer: coordinates (evidence: `testbot/core.py`)
- TestAgent FSM → Action decider: coordinates (evidence: `testbot/core.py`)
- TestAgent FSM → Action executor: coordinates (evidence: `testbot/core.py`)
- TestAgent FSM → Step supervisor: coordinates (evidence: `testbot/core.py`)
- TestAgent FSM → Test recorder: coordinates (evidence: `testbot/core.py`)
- TestAgent FSM → Run memory: uses run state (evidence: `testbot/core.py`)
- TestAgent FSM → ADB device control: manages device (evidence: `testbot/core.py`)
- Screen observer → ADB device control: captures screen (evidence: `testbot/roles/observer.py`)
- Screen observer → Widget detector: extracts widgets (evidence: `testbot/roles/observer.py`)
- Screen observer → Run memory: stores observations
- Widget detector → Component proposal: detects components (evidence: `testbot/uied/detect.py`)
- Widget detector → OCR text detection: detects text (evidence: `testbot/uied/detect.py`)
- Widget detector → Widget merge: merges detections (evidence: `testbot/uied/detect.py`)
- Component proposal → Image preprocessing: preprocesses image (evidence: `testbot/uied/detect_compo/ip_region_proposal.py`)
- Component proposal → Image detection: finds regions (evidence: `testbot/uied/detect_compo/ip_region_proposal.py`)
- Component proposal → Detection drawing: draws regions (evidence: `testbot/uied/detect_compo/ip_region_proposal.py`)
- Component proposal → Detection files: saves results (evidence: `testbot/uied/detect_compo/ip_region_proposal.py`)
- Image detection → Component model: builds components (evidence: `testbot/uied/detect_compo/lib_ip/ip_detection.py`)
- Component model → Bounding boxes: uses bounds (evidence: `testbot/uied/detect_compo/lib_ip/Component.py`)
- OCR text detection → PaddleOCR adapter: recognizes text (evidence: `testbot/uied/detect_text/text_detection.py`)
- OCR text detection → Text elements: creates text elements (evidence: `testbot/uied/detect_text/text_detection.py`)
- Widget merge → Merged element model: builds merged elements (evidence: `testbot/uied/detect_merge/merge.py`)
- Action decider → Action prompts: builds prompts (evidence: `testbot/roles/decider.py`)
- Action decider → Ollama VLM client: requests decisions (evidence: `testbot/roles/decider.py`)
- Action decider → Run memory: reads run context (evidence: `testbot/roles/decider.py`)
- Step supervisor → Check prompts: builds check prompts (evidence: `testbot/roles/supervisor.py`)
- Step supervisor → Ollama VLM client: checks screenshots (evidence: `testbot/roles/supervisor.py`)
- Step supervisor → Run memory: reads run context (evidence: `testbot/roles/supervisor.py`)
- Ollama VLM client → Ollama Qwen VLM: sends multimodal requests
- Action executor → ADB device control: issues actions (evidence: `testbot/roles/executor.py`)
- Action executor → Run memory: updates action history (evidence: `testbot/roles/executor.py`)
- ADB device control → Android device: controls via ADB
- Test recorder → Run memory: records history (evidence: `testbot/roles/recorder.py`)
- Test recorder → Ollama VLM client: exports chat logs (evidence: `testbot/roles/recorder.py`)
- OCR benchmark and tuning → PaddleOCR adapter: tests OCR models
