# forwall100/rewind architecture

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

- Interactive diagram: https://gitdiagram.com/forwall100/rewind
- Repository: https://github.com/forwall100/rewind

## Overview

##### Project Type and Purpose
- Rewind is a background service and console application for automated screenshot capture. Its main purpose is to periodically capture computer screens, perform OCR (with Tesseract) on the images to extract text, and enable users to search screenshots either by recognized text or by the timestamp.
- The project is built in Python, uses a systemd service for background execution, and manages storage via an SQLite database.

##### Analysis of File Structure
- Top-level files like PKGBUILD, setup.py, and setup.sh indicate that this project is packaged for easy installation (specifically for Arch Linux).
- The existence of a systemd service file (rewind-screenshot.service) and a shell script (rewind.sh) shows that the application is intended to run as a background process.
- The main functional logic resides in the “rewind” directory with files:
- rewind.py – likely the entry point or main control logic.
- screenshot_service.py – which probably contains the routines for periodically capturing screenshots, performing OCR, and checking for duplicates.
- Other files such as config.yaml, requirements.txt, and the README provide configuration parameters, dependency management, and an explanation of how the application runs.

##### Main Components
a. Systemd Service & Launcher:
- Systemd service (rewind-screenshot.service) as the orchestration layer that launches the screenshot capture process automatically when the user logs in.
b. Screenshot Capture Module:
- That the application (via rewind.sh or directly through the Python package) periodically takes screenshots.
- Integration with external screenshot utilities such as “grim” for Wayland, or “scrot” for X11.
c. OCR & Image Processing Module:
- Connection to Tesseract OCR (and its data packages) used to extract text from images.
- Where image processing and duplicate prevention occur. Duplicate detection uses perceptual hashing (pHash) and also text similarity checks.
d. Database Storage:
e. Console-Based UI:
- Console application component which allows users to search and navigate through screenshots by text or timestamp.
f. Configuration Management:
- Configuration file (config.yaml) and highlight that it serves to set parameters such as screenshot frequency, OCR languages, and similarity thresholds.

##### Relationships and Interactions
- The Systemd Service triggers the Screenshot Capture Module at regular intervals.
- The Capture Module then takes a screenshot, sends it to the OCR and Processing Module.
- The OCR Module extracts text, computes the pHash, and checks for duplicates using similarity thresholds.
- If the image is unique, the processed data (screenshot binary and text) is saved to the SQLite Database.
- The Console UI then queries the database to enable text or timeline-based searches.
- The system scheduler (systemd) to the capture/processing daemon.
- The daemon to the OCR/deduplication routines.
- The routines to the data storage (SQLite).
- The storage to the UI.

##### Architectural Patterns & Design Principles
- The project follows a modular design by separating the background screenshot/processing service from the interactive console UI.
- There is clear separation between configuration management, data capture, processing (OCR and de-duplication), and data storage.
- The design leverages an event/timer-driven mechanism that is managed externally by systemd.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Background Service (rewind-screenshot.service)"]:::service
    subgraph "Screenshot Capture Module"
        B["Main Controller (rewind.py)"]:::capture
        C["Screenshot Service (screenshot_service.py)"]:::capture
    end
    D["OCR & Duplicate Prevention Module (Tesseract & pHash)"]:::processing
    E["Database Storage (SQLite DB)"]:::database
    F["Console UI (Search & Navigation)"]:::ui
    G["Configuration (config.yaml)"]:::config
    H["External Screenshot Utility (grim/scrot)"]:::external
    I["External OCR Engine (Tesseract)"]:::external

    A -->|"launches"| B
    B -->|"triggers"| C
    C -->|"captures_and_sends"| D
    D -->|"saves_data_to"| E
    E -->|"queried_by"| F
    G -->|"configures"| B
    G -->|"configures"| D
    C -->|"uses"| H
    D -->|"integrates"| I

    click A "https://github.com/forwall100/rewind/blob/main/rewind-screenshot.service"
    click B "https://github.com/forwall100/rewind/blob/main/rewind/rewind.py"
    click C "https://github.com/forwall100/rewind/blob/main/rewind/screenshot_service.py"
    click G "https://github.com/forwall100/rewind/blob/main/config.yaml"
    click E "https://github.com/forwall100/rewind/blob/main/~/.config/rewind/screenshots.db"

    classDef service fill:#f6d365,stroke:#e39a3b,stroke-width:2px;
    classDef capture fill:#cfc,stroke:#080,stroke-width:2px;
    classDef processing fill:#cceeff,stroke:#0044cc,stroke-width:2px;
    classDef database fill:#fadadd,stroke:#ff69b4,stroke-width:2px;
    classDef ui fill:#ffedcc,stroke:#ffaa00,stroke-width:2px;
    classDef config fill:#e0e0e0,stroke:#bbbbbb,stroke-width:2px;
    classDef external fill:#eeeeee,stroke:#888888,stroke-dasharray:5,stroke-width:2px;
```
