# sachsahu21/photo architecture

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

- Interactive diagram: https://gitdiagram.com/sachsahu21/photo
- Repository: https://github.com/sachsahu21/photo

## Overview

This repository is a versioned monorepo for a local-first photo/video scanner. Each release folder (`v1` through `v6.2`) is a mostly self-contained application with its own `main.py`, `config.yaml`, `src/`, and usually `tests/` plus an optional `web/` Streamlit UI. The code in `z.old_code/` is archival; the actively documented baseline is `v4.0`, while later folders (`v5.x`, `v6.2`) extend the same pipeline with persistence, face indexing, and stronger checkpointing.

The primary runtime boundary is the local filesystem. The app scans user-selected folders on disk, not a hosted backend. Cloud-backed folders are treated as local sync targets, so OneDrive/cloud behavior is an operational concern rather than a separate service architecture.

The main entry point in each release is `main.py`, which drives an interactive CLI workflow. In `v4.0`, this CLI orchestrates scan/extract, resume-from-backup, deletion-by-workbook, and organization actions. A separate `web/streamlit_app.py` exists in newer releases as an optional dashboard layered on top of the same core modules.

Configuration is centralized in `config.yaml` and loaded through `config_manager.py`. This file defines scan scope, recursion, thread count, blur threshold, duplicate settings, and output locations. That configuration layer is the main control boundary for how the pipeline behaves across releases.

The core data flow starts with `scanner.py`, which walks the filesystem and extracts image/video metadata. Supporting modules such as `video_metadata.py`, `cloud_scanner.py`, and `geocoder.py` enrich records with media-specific details, GPS-derived location data, and cloud/folder-source handling where enabled. The scanner produces record objects that become the canonical in-memory dataset for downstream analysis.

Processing is often parallelized. `parallel_processor.py` provides the worker-pool layer, while `checkpoint_manager.py` and, in later versions, `global_checkpoint.py` preserve progress so long scans can resume safely. This makes scan-and-analyze a resumable batch pipeline rather than a single monolithic run.

Analysis is split into focused subsystems. `blur_detector.py` scores image sharpness, `duplicate_handler.py` groups identical files and selects the best copy, and `similar_detector.py` handles near-duplicate comparisons in later releases. Additional enrichment modules include `face_detector.py` and `face_indexer.py` for people detection/indexing, `image_clusterer.py` for grouping, `auto_tagger.py` for automated labels, and `thumbnail_generator.py` for preview assets.

The reporting boundary is explicit. `excel_writer.py` produces the multi-sheet workbook used for review and, in some workflows, deletion decisions. Later releases add `generate_report.py`, `analytics.py`, and `comparison_generator.py` to build summary views and side-by-side comparison artifacts. Backups such as `records-backup.pkl` and record-store modules in `v5+` make the scanned dataset durable across runs.

File mutation is isolated in `organizer.py`, which copies or moves assets into date-based folder structures, and `vault_maintenance.py`, which handles cleanup and repository-specific housekeeping in later versions. `people_sync.py` and metadata reconciliation modules in `v5+` keep derived metadata aligned with file organization changes.

The repository also contains a small quality layer: `tests/` focuses on scanner and blur logic, with additional pipeline tests in later versions such as `test_face_pipeline.py`. There are also run/test helpers like `run_full_test.py` and a notebook (`image_scan.ipynb`), but these are supporting assets rather than primary runtime components.

For an architecture diagram, the most important boxes are: local filesystem input, config-driven scan engine, parallel enrichment/analysis, checkpoint/resume state, report/output generation, and optional organization/mutation. The versioned folders should be shown as evolving snapshots of the same product line, not as independent services.

Main entry points: [`v4.0/src/parallel_processor.py`](https://github.com/sachsahu21/photo/blob/main/v4.0/src/parallel_processor.py) (Workers), [`v4.0/main.py`](https://github.com/sachsahu21/photo/blob/main/v4.0/main.py) (CLI entry), [`v4.0/src/scanner.py`](https://github.com/sachsahu21/photo/blob/main/v4.0/src/scanner.py) (Scanner), [`v5.0/src/metadata_store.py`](https://github.com/sachsahu21/photo/blob/main/v5.0/src/metadata_store.py) (Metadata store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs & control"]
  node_local_fs[("Local files<br/>filesystem input")]
  node_config["Config<br/>yaml control<br/>[config.yaml]"]
end

subgraph group_runtime["Core pipeline"]
  node_main["CLI entry<br/>orchestrator<br/>[main.py]"]
  node_scanner["Scanner<br/>filesystem crawler<br/>[scanner.py]"]
  node_video_meta["Media meta<br/>media enrichment<br/>[video_metadata.py]"]
  node_cloud_scan["Cloud scan<br/>source adapter<br/>[cloud_scanner.py]"]
  node_geocoder["Geocoder<br/>location enrichment<br/>[geocoder.py]"]
  node_parallel["Workers<br/>parallel processor"]
  node_checkpoint[("Checkpoint<br/>resume state")]
  node_blur{{"Blur score<br/>quality analysis<br/>[blur_detector.py]"}}
  node_dupes{{"Duplicates<br/>dedupe analysis"}}
  node_similar{{"Similarity<br/>near-dup analysis"}}
  node_faces{{"Faces<br/>people indexing<br/>[face_indexer.py]"}}
  node_cluster_tag{{"Cluster/tag<br/>grouping & labels<br/>[image_clusterer.py]"}}
  node_thumbs["Thumbnails<br/>preview generation"]
  node_store[("Metadata store<br/>persistence layer<br/>[metadata_store.py]")]
  node_organizer["Organizer<br/>file mutation<br/>[organizer.py]"]
  node_maintenance["Vault maint.<br/>housekeeping"]
end

subgraph group_outputs["Outputs & review"]
  node_excel["Workbook<br/>review report<br/>[excel_writer.py]"]
  node_report["Reports<br/>summary output<br/>[generate_report.py]"]
  node_backup[("Backup<br/>snapshot<br/>[records-backup.pkl]")]
  node_web["Dashboard<br/>optional UI<br/>[streamlit_app.py]"]
end

subgraph group_archive["Legacy archive"]
  node_oldcode["Old code<br/>archival scripts<br/>[main.py]"]
end

node_local_fs -->|"scan"| node_scanner
node_config -->|"load"| node_main
node_main -->|"orchestrate"| node_scanner
node_main -->|"review"| node_excel
node_main -->|"mutate"| node_organizer
node_main -.->|"optional"| node_web
node_scanner -->|"enrich"| node_video_meta
node_scanner -->|"adapt"| node_cloud_scan
node_scanner -->|"locate"| node_geocoder
node_scanner -->|"fan out"| node_parallel
node_parallel -->|"resume"| node_checkpoint
node_parallel -->|"score"| node_blur
node_parallel -->|"dedupe"| node_dupes
node_parallel -->|"compare"| node_similar
node_parallel -->|"index"| node_faces
node_parallel -->|"group"| node_cluster_tag
node_parallel -->|"render"| node_thumbs
node_parallel -->|"persist"| node_store
node_store -->|"snapshot"| node_backup
node_store -->|"summarize"| node_report
node_excel -->|"extend"| node_report
node_organizer -->|"clean"| node_maintenance
node_organizer -->|"reconcile"| node_store
node_oldcode -.->|"evolved into"| node_main

click node_config "https://github.com/sachsahu21/photo/blob/main/v4.0/config.yaml"
click node_main "https://github.com/sachsahu21/photo/blob/main/v4.0/main.py"
click node_scanner "https://github.com/sachsahu21/photo/blob/main/v4.0/src/scanner.py"
click node_video_meta "https://github.com/sachsahu21/photo/blob/main/v4.0/src/video_metadata.py"
click node_cloud_scan "https://github.com/sachsahu21/photo/blob/main/v4.0/src/cloud_scanner.py"
click node_geocoder "https://github.com/sachsahu21/photo/blob/main/v4.0/src/geocoder.py"
click node_parallel "https://github.com/sachsahu21/photo/blob/main/v4.0/src/parallel_processor.py"
click node_checkpoint "https://github.com/sachsahu21/photo/blob/main/v4.0/src/checkpoint_manager.py"
click node_blur "https://github.com/sachsahu21/photo/blob/main/v4.0/src/blur_detector.py"
click node_dupes "https://github.com/sachsahu21/photo/blob/main/v4.0/src/duplicate_handler.py"
click node_similar "https://github.com/sachsahu21/photo/blob/main/v4.0/src/similar_detector.py"
click node_faces "https://github.com/sachsahu21/photo/blob/main/v5.0/src/face_indexer.py"
click node_cluster_tag "https://github.com/sachsahu21/photo/blob/main/v4.0/src/image_clusterer.py"
click node_thumbs "https://github.com/sachsahu21/photo/blob/main/v4.0/src/thumbnail_generator.py"
click node_store "https://github.com/sachsahu21/photo/blob/main/v5.0/src/metadata_store.py"
click node_organizer "https://github.com/sachsahu21/photo/blob/main/v4.0/src/organizer.py"
click node_maintenance "https://github.com/sachsahu21/photo/blob/main/v5.0/src/vault_maintenance.py"
click node_excel "https://github.com/sachsahu21/photo/blob/main/v4.0/src/excel_writer.py"
click node_report "https://github.com/sachsahu21/photo/blob/main/v5.2/src/generate_report.py"
click node_backup "https://github.com/sachsahu21/photo/blob/main/v3.1/records-backup.pkl"
click node_web "https://github.com/sachsahu21/photo/blob/main/v4.0/web/streamlit_app.py"
click node_oldcode "https://github.com/sachsahu21/photo/blob/main/z.old_code/v1/main.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_local_fs,node_config toneBlue
class node_main,node_scanner,node_video_meta,node_cloud_scan,node_geocoder,node_parallel,node_checkpoint,node_blur,node_dupes,node_similar,node_faces,node_cluster_tag,node_thumbs,node_store,node_organizer,node_maintenance toneAmber
class node_excel,node_report,node_backup,node_web toneMint
class node_oldcode toneRose
```

## Components

### Inputs & control

Local filesystem sources and config-driven behavior

- **Local files**: filesystem input · User-selected folders on disk; the primary runtime boundary
- [Config](https://github.com/sachsahu21/photo/blob/main/v4.0/config.yaml): yaml control · Centralized scan and processing settings loaded from config.yaml · `v4.0/config.yaml`

### Core pipeline

Scan, enrich, analyze, and mutate photo/video records

- [CLI entry](https://github.com/sachsahu21/photo/blob/main/v4.0/main.py): orchestrator · Interactive command-line entrypoint for each release · `v4.0/main.py`
- [Scanner](https://github.com/sachsahu21/photo/blob/main/v4.0/src/scanner.py): filesystem crawler · Walks folders and builds canonical media records · `v4.0/src/scanner.py`
- [Media meta](https://github.com/sachsahu21/photo/blob/main/v4.0/src/video_metadata.py): media enrichment · Extracts video and file-level metadata for records · `v4.0/src/video_metadata.py`
- [Cloud scan](https://github.com/sachsahu21/photo/blob/main/v4.0/src/cloud_scanner.py): source adapter · Treats synced cloud folders as local scan targets where enabled · `v4.0/src/cloud_scanner.py`
- [Geocoder](https://github.com/sachsahu21/photo/blob/main/v4.0/src/geocoder.py): location enrichment · Converts GPS metadata into human-readable place data · `v4.0/src/geocoder.py`
- [Workers](https://github.com/sachsahu21/photo/blob/main/v4.0/src/parallel_processor.py): parallel processor · Worker-pool layer for resumable batch processing · `v4.0/src/parallel_processor.py`
- [Checkpoint](https://github.com/sachsahu21/photo/blob/main/v4.0/src/checkpoint_manager.py): resume state · Persists scan progress so long runs can resume safely · `v4.0/src/checkpoint_manager.py`
- [Blur score](https://github.com/sachsahu21/photo/blob/main/v4.0/src/blur_detector.py): quality analysis · Scores image sharpness and quality · `v4.0/src/blur_detector.py`
- [Duplicates](https://github.com/sachsahu21/photo/blob/main/v4.0/src/duplicate_handler.py): dedupe analysis · Groups exact duplicates and chooses preferred copies · `v4.0/src/duplicate_handler.py`
- [Similarity](https://github.com/sachsahu21/photo/blob/main/v4.0/src/similar_detector.py): near-dup analysis · Finds near-duplicate media in later releases · `v4.0/src/similar_detector.py`
- [Faces](https://github.com/sachsahu21/photo/blob/main/v5.0/src/face_indexer.py): people indexing · Detects faces and builds people indexes in later releases · `v5.0/src/face_indexer.py`
- [Cluster/tag](https://github.com/sachsahu21/photo/blob/main/v4.0/src/image_clusterer.py): grouping & labels · Clusters media and generates auto-tags · `v4.0/src/image_clusterer.py`
- [Thumbnails](https://github.com/sachsahu21/photo/blob/main/v4.0/src/thumbnail_generator.py): preview generation · Builds preview assets for review workflows · `v4.0/src/thumbnail_generator.py`
- [Metadata store](https://github.com/sachsahu21/photo/blob/main/v5.0/src/metadata_store.py): persistence layer · Durable record store and path reconciliation in v5+ · `v5.0/src/metadata_store.py`
- [Organizer](https://github.com/sachsahu21/photo/blob/main/v4.0/src/organizer.py): file mutation · Copies or moves media into date-based folder structures · `v4.0/src/organizer.py`
- [Vault maint.](https://github.com/sachsahu21/photo/blob/main/v5.0/src/vault_maintenance.py): housekeeping · Cleanup and repository-specific maintenance in later releases · `v5.0/src/vault_maintenance.py`

### Outputs & review

Reports, backups, and optional dashboard

- [Workbook](https://github.com/sachsahu21/photo/blob/main/v4.0/src/excel_writer.py): review report · Produces the multi-sheet Excel review workbook · `v4.0/src/excel_writer.py`
- [Reports](https://github.com/sachsahu21/photo/blob/main/v5.2/src/generate_report.py): summary output · Higher-level analytics and comparison artifacts in later releases · `v5.2/src/generate_report.py`
- [Backup](https://github.com/sachsahu21/photo/blob/main/v3.1/records-backup.pkl): snapshot · Serialized record backups for durable recovery between runs · `v3.1/records-backup.pkl`
- [Dashboard](https://github.com/sachsahu21/photo/blob/main/v4.0/web/streamlit_app.py): optional UI · Streamlit review UI layered over the same core pipeline · `v4.0/web/streamlit_app.py`

### Legacy archive

Earlier experimental code and historical scripts

- [Old code](https://github.com/sachsahu21/photo/blob/main/z.old_code/v1/main.py): archival scripts · Historical scripts and earlier scanner generations · `z.old_code/v1/main.py`

## Connections

- Local files → Scanner: scan · Scanner walks the selected folders
- Config → CLI entry: load · Configuration drives the CLI workflow
- CLI entry → Scanner: orchestrate · Main entrypoint starts scans and follow-on actions
- CLI entry → Workbook: review · CLI can generate workbook outputs for inspection
- CLI entry → Organizer: mutate · CLI can trigger organization and file moves
- CLI entry → Dashboard: optional · Later releases expose the same core functions through Streamlit
- Scanner → Media meta: enrich · Scanner captures media-specific metadata
- Scanner → Cloud scan: adapt · Cloud-synced folders are handled as local sources
- Scanner → Geocoder: locate · GPS-derived location enrichment
- Scanner → Workers: fan out · Batch work is parallelized for long scans
- Workers → Checkpoint: resume · Progress is checkpointed for safe restarts
- Workers → Blur score: score · Quality scoring runs as part of analysis
- Workers → Duplicates: dedupe · Exact duplicate grouping happens downstream
- Workers → Similarity: compare · Near-duplicate comparison is added in later releases
- Workers → Faces: index · Face detection/indexing extends the analysis pipeline
- Workers → Cluster/tag: group · Media are clustered and auto-tagged
- Workers → Thumbnails: render · Preview assets are generated for review
- Workers → Metadata store: persist · Later releases store records durably across runs
- Metadata store → Backup: snapshot · Record state can be backed up between sessions
- Metadata store → Reports: summarize · Stored records feed analytics and generated reports
- Workbook → Reports: extend · Workbook review evolves into richer reporting artifacts
- Organizer → Vault maint.: clean · Maintenance follows file organization and workspace changes
- Organizer → Metadata store: reconcile · Metadata and paths are reconciled after file moves
- Old code → CLI entry: evolved into · Archived scripts show the earlier generations of the same product
