# shubrotodas10/tourvision architecture

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

- Interactive diagram: https://gitdiagram.com/shubrotodas10/tourvision
- Repository: https://github.com/shubrotodas10/tourvision

## Overview

1. **Repository shape**
   - This is a small, single-process Python pipeline rather than a multi-service application.
   - The core orchestrator appears to be `tourVision.py` (the README references `pipeline_new.py`, but the file tree shows `tourVision.py` as the main entry point).

2. **Primary purpose**
   - The system converts a folder of property photos into a polished tour video.
   - The architecture is a linear media-processing pipeline: local images in → AI classification → AI video generation → local video stitching → final MP4 out.

3. **Input boundary: property image folders**
   - Source media lives under `images/{PROPERTY_CODE}/`.
   - The pipeline expects typical photo formats such as `.webp`, `.jpg`, and `.jpeg`.
   - Each property is treated as a separate batch keyed by a property code.

4. **Configuration and environment**
   - Runtime settings are driven by constants in the script, including property code, source/output paths, transition duration, and target video length.
   - Secrets are externalized through `.env`, primarily the `GEMINI_API_KEY`.
   - This makes the pipeline environment-driven, with behavior changing per property and per deployment machine.

5. **AI classification subsystem**
   - Google Gemini Vision (`gemini-2.0-flash`) is used to inspect each image and infer room/scene labels.
   - This stage is responsible for turning unstructured photos into structured scene groups like bedroom, kitchen, living room, exterior, and amenities.
   - The output of this stage is the key data model for the rest of the pipeline: images grouped by detected room type.

6. **Scene grouping and selection logic**
   - After classification, images are grouped by label to create room-specific scene sets.
   - For rooms with multiple images, the pipeline selects the best pair for transition-friendly clips.
   - This stage is the main decision boundary that determines clip ordering and how many generated scenes the final tour will contain.

7. **Video generation subsystem**
   - Google Veo 3.1 Fast (`veo-3.1-fast-generate-preview`) is used to generate cinematic clips from the selected images.
   - Single-image scenes are prompted as smooth panorama-style shots.
   - Multi-image scenes are prompted as frame-bridge or transition shots, giving the tour motion between views.
   - This is an external cloud AI boundary: local code submits prompts and images, then waits for asynchronous generation results.

8. **Local media assembly**
   - MoviePy is used after generation to stitch the scene clips into one final video.
   - The final assembly applies crossfades and timing adjustments so the total output matches the target duration.
   - This is the main local post-processing boundary, separate from the cloud AI generation step.

9. **Output artifacts**
   - Generated assets are written under `output/{PROPERTY_CODE}/`.
   - The pipeline produces per-scene MP4s as well as a final stitched property tour, typically `final_property_tour_{PROPERTY_CODE}.mp4`.
   - The output folder is therefore the terminal artifact boundary for each batch run.

10. **Usage tracking and observability**
   - API usage is logged to `token_counter.csv`.
   - The log captures timestamp, property ID, process name, model, execution time, and token counts.
   - This is a lightweight audit/finance subsystem rather than a monitoring stack, but it materially affects the architecture because every AI call is tracked.

11. **Core helper responsibilities**
   - The README calls out helpers for packaging image data for Gemini and Veo, cleaning JSON-like AI responses, and recording API hits.
   - These helpers act as adapters between local files and model-specific request formats.
   - They are important because they isolate provider-specific input/output handling from the orchestration flow.

12. **Operational model**
   - The repo is designed for batch execution per property, not interactive use.
   - A typical run scans one property folder, generates all clips, then exits after writing outputs and logs.
   - This makes the architecture easy to diagram as a single pipeline with clear stages and file-system checkpoints.

13. **External dependencies that define the system**
   - Google Gemini and Veo are the critical external services; without them, the pipeline cannot classify images or generate clips.
   - MoviePy is the local composition library that turns generated scenes into the final deliverable.
   - Python 3.8+ is the runtime baseline.

14. **Key architectural boundaries to show in a diagram**
   - Local filesystem boundary: images in, MP4s and CSV out.
   - Cloud AI boundary: Gemini for labeling and Veo for clip generation.
   - Local composition boundary: MoviePy stitching and duration control.
   - These three boundaries define the repository’s architecture more accurately than individual functions do.

Main entry points: [`tourVision.py`](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py) (TourVision)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local_pipeline["Local pipeline"]
  node_tourvision_entry["TourVision<br/>python orchestrator<br/>[tourVision.py]"]
  node_run_config["Runtime config<br/>constants/env<br/>[tourVision.py]"]
  node_env_secrets["Env secrets<br/>dotenv"]
  node_image_packager["Image packager<br/>adapter<br/>[tourVision.py]"]
  node_response_cleaner["Response cleaner<br/>parser<br/>[tourVision.py]"]
  node_room_groups[("Room groups<br/>scene index<br/>[tourVision.py]")]
  node_scene_picker["Scene picker<br/>selection logic<br/>[tourVision.py]"]
  node_veo_prompting["Veo prompts<br/>prompt builder<br/>[tourVision.py]"]
  node_moviepy_stitcher["MoviePy stitcher<br/>composer<br/>[tourVision.py]"]
end

subgraph group_cloud_ai["Cloud AI"]
  node_gemini_vision{{"Gemini Vision<br/>ai classifier"}}
  node_veo_generator{{"Veo generator<br/>ai video"}}
end

subgraph group_artifacts["Artifacts"]
  node_property_images[("Property photos<br/>image batch")]
  node_scene_mp4s[("Scene MP4s<br/>generated clips")]
  node_final_tour[("Final tour<br/>mp4 deliverable")]
  node_usage_log["Token log<br/>csv audit"]
end

node_run_config -->|"drive run"| node_tourvision_entry
node_env_secrets -->|"API key"| node_tourvision_entry
node_property_images -->|"load photos"| node_image_packager
node_tourvision_entry -->|"prepare input"| node_image_packager
node_image_packager -->|"classify"| node_gemini_vision
node_gemini_vision -->|"raw labels"| node_response_cleaner
node_response_cleaner -->|"normalize"| node_room_groups
node_room_groups -->|"select scenes"| node_scene_picker
node_scene_picker -->|"build prompts"| node_veo_prompting
node_veo_prompting -->|"generate clip"| node_veo_generator
node_veo_generator -->|"write clips"| node_scene_mp4s
node_scene_mp4s -->|"assemble"| node_moviepy_stitcher
node_moviepy_stitcher -->|"export video"| node_final_tour
node_tourvision_entry -->|"record usage"| node_usage_log
node_gemini_vision -->|"audit call"| node_usage_log
node_veo_generator -->|"audit call"| node_usage_log

click node_tourvision_entry "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py"
click node_run_config "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py"
click node_image_packager "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py"
click node_response_cleaner "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py"
click node_room_groups "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py"
click node_scene_picker "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py"
click node_veo_prompting "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py"
click node_moviepy_stitcher "https://github.com/shubrotodas10/tourvision/blob/main/tourVision.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_tourvision_entry,node_run_config,node_env_secrets,node_image_packager,node_response_cleaner,node_room_groups,node_scene_picker,node_veo_prompting,node_moviepy_stitcher toneBlue
class node_gemini_vision,node_veo_generator toneAmber
class node_property_images,node_scene_mp4s,node_final_tour,node_usage_log toneMint
```

## Components

### Local pipeline

Batch orchestration and filesystem-driven processing inside Python

- [TourVision](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): python orchestrator · Main batch entrypoint that drives one property tour run · `tourVision.py`
- [Runtime config](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): constants/env · Property code, paths, durations, and model settings · `tourVision.py`
- **Env secrets**: dotenv · External API credentials such as GEMINI_API_KEY
- [Image packager](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): adapter · Prepares local photos for Gemini requests · `tourVision.py`
- [Response cleaner](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): parser · Normalizes JSON-like model responses into usable labels · `tourVision.py`
- [Room groups](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): scene index · Grouped images by detected room or scene label · `tourVision.py`
- [Scene picker](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): selection logic · Chooses best images or pairs for each scene · `tourVision.py`
- [Veo prompts](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): prompt builder · Builds panorama or transition prompts from selected images · `tourVision.py`
- [MoviePy stitcher](https://github.com/shubrotodas10/tourvision/blob/main/tourVision.py): composer · Concatenates clips with crossfades and timing control · `tourVision.py`

### Cloud AI

External model calls for image understanding and video generation

- **Gemini Vision**: ai classifier · Labels photos by room or scene type
- **Veo generator**: ai video · Generates cinematic clips from selected images

### Artifacts

Input media, generated video, and usage logs

- **Property photos**: image batch · Source images under images/{PROPERTY_CODE}/
- **Scene MP4s**: generated clips · Per-scene video outputs written before final assembly
- **Final tour**: mp4 deliverable · Completed property tour video
- **Token log**: csv audit · Records model usage, timing, and token counts

## Connections

- Runtime config → TourVision: drive run · Supplies property, path, and timing settings
- Env secrets → TourVision: API key · Provides Gemini authentication
- Property photos → Image packager: load photos · Reads a property image batch for processing
- TourVision → Image packager: prepare input · Starts packaging images for classification
- Image packager → Gemini Vision: classify · Sends images to the vision model
- Gemini Vision → Response cleaner: raw labels · Returns structured or semi-structured label output
- Response cleaner → Room groups: normalize · Converts model output into room-based groups
- Room groups → Scene picker: select scenes · Feeds grouped images into selection logic
- Scene picker → Veo prompts: build prompts · Creates prompt strategy from chosen images
- Veo prompts → Veo generator: generate clip · Submits prompt and image context to Veo
- Veo generator → Scene MP4s: write clips · Stores generated per-scene MP4 artifacts
- Scene MP4s → MoviePy stitcher: assemble · Provides clips for final composition
- MoviePy stitcher → Final tour: export video · Writes the completed property tour MP4
- TourVision → Token log: record usage · Logs model calls, timing, and tokens
- Gemini Vision → Token log: audit call · Tracks classification usage
- Veo generator → Token log: audit call · Tracks video generation usage
