# rjtbst/productsnap architecture

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

- Interactive diagram: https://gitdiagram.com/rjtbst/productsnap
- Repository: https://github.com/rjtbst/productsnap

## Overview

##### Project Type & Purpose
- AdSnap Studio is a Streamlit-based, single-page web app (“frontend”) that orchestrates AI-driven image generation and manipulation (“backend”) by calling Bria AI’s external APIs.
- It has no database or long-term storage; it relies on in-memory workflows and external service calls.

##### File Structure
- Top-level:
- app.py – Streamlit entry point (UI + controller)
- requirements.txt / .env – dependency list and API key
- components/ – Streamlit UI widgets
- uploader.py, sidebar.py, image_preview.py
- workflows/ – orchestration logic
- generate_ad_set.py
- services/ – feature-specific modules that wrap Bria API calls
- erase_foreground.py, generative_fill.py, hd_image_generation.py, lifestyle_shot.py, packshot.py, prompt_enhancement.py, shadow.py
- utils/ – (future) shared helper functions

##### README Insights
- Core features correspond to service modules (background removal, prompt enhancement, shadows, lifestyle shots, HD generation).
- UI config options map directly to parameters fed into the orchestration logic in workflows/generate_ad_set.py.

##### Main Components & Their Relationships
a. User & Browser
– End user interacts via browser running the Streamlit UI.
b. Streamlit App (app.py + components/)
– Renders UI, captures user input, displays results.
c. Workflow Orchestrator (generate_ad_set.py)
– Central business logic: sequences calls to service modules based on UI settings.
d. Service Layer (services/*.py)
– Each module wraps calls to a specific Bria AI endpoint for image generation or manipulation.
e. External API (Bria AI)
– The “data store” / engine: HD generation, background removal, shadows, etc.
f. Configuration (.env)
– Supplies BRIA_API_KEY to service modules.

Data Flow:
User → Streamlit UI → Workflow → Service Modules → Bria API → Service Modules → Workflow → Streamlit UI → User

##### Architectural Patterns & Design Principles
- Layered Architecture:
- Presentation Layer (UI components)
- Application/Orchestration Layer (workflows)
- Service/Integration Layer (external API adapters)
- Single responsibility per service module.
- Clear separation: UI never calls Bria API directly; all calls pass through workflows and service wrappers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    User["User"]:::external
    Browser["Browser"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Streamlit["Streamlit App (app.py)"]:::presentation
        componentsDir["UI Components (components/)"]:::presentation
        Sidebar["sidebar.py"]:::presentation
        Uploader["uploader.py"]:::presentation
        Preview["image_preview.py"]:::presentation
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        direction TB
        Workflow["generate_ad_set.py"]:::orchestration
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        Erase["erase_foreground.py"]:::service
        Fill["generative_fill.py"]:::service
        HD["hd_image_generation.py"]:::service
        Lifestyle["lifestyle_shot.py"]:::service
        Packshot["packshot.py"]:::service
        Prompt["prompt_enhancement.py"]:::service
        Shadow["shadow.py"]:::service
    end

    %% Config & Dependencies
    Config[".env"]:::config
    Deps["requirements.txt"]:::config

    %% External API
    External["Bria AI API"]:::external

    %% Data Flows
    User -->|"interacts via"| Streamlit
    Browser --> Streamlit
    componentsDir --> Streamlit
    Streamlit --> Sidebar
    Streamlit --> Uploader
    Streamlit --> Preview
    Streamlit -->|"invokes orchestration"| Workflow
    Config --> Workflow
    Deps --> Streamlit

    Workflow -->|calls erase_foreground| Erase
    Workflow -->|calls generative_fill| Fill
    Workflow -->|calls hd_image_generation| HD
    Workflow -->|calls lifestyle_shot| Lifestyle
    Workflow -->|calls packshot| Packshot
    Workflow -->|calls prompt_enhancement| Prompt
    Workflow -->|calls shadow| Shadow

    Erase -->|requests| External
    Fill -->|requests| External
    HD -->|requests| External
    Lifestyle -->|requests| External
    Packshot -->|requests| External
    Prompt -->|requests| External
    Shadow -->|requests| External

    External ---|returns result| Erase
    External ---|returns result| Fill
    External ---|returns result| HD
    External ---|returns result| Lifestyle
    External ---|returns result| Packshot
    External ---|returns result| Prompt
    External ---|returns result| Shadow

    Erase -->|returns| Workflow
    Fill -->|returns| Workflow
    HD -->|returns| Workflow
    Lifestyle -->|returns| Workflow
    Packshot -->|returns| Workflow
    Prompt -->|returns| Workflow
    Shadow -->|returns| Workflow

    Workflow -->|returns images| Streamlit
    Streamlit -->|renders| Preview
    Streamlit -->|displays UI| Browser

    %% Click Events
    click Streamlit "https://github.com/rjtbst/productsnap/blob/master/app.py"
    click componentsDir "https://github.com/rjtbst/productsnap/tree/master/components/"
    click Sidebar "https://github.com/rjtbst/productsnap/blob/master/components/sidebar.py"
    click Uploader "https://github.com/rjtbst/productsnap/blob/master/components/uploader.py"
    click Preview "https://github.com/rjtbst/productsnap/blob/master/components/image_preview.py"
    click Workflow "https://github.com/rjtbst/productsnap/blob/master/workflows/generate_ad_set.py"
    click Erase "https://github.com/rjtbst/productsnap/blob/master/services/erase_foreground.py"
    click Fill "https://github.com/rjtbst/productsnap/blob/master/services/generative_fill.py"
    click HD "https://github.com/rjtbst/productsnap/blob/master/services/hd_image_generation.py"
    click Lifestyle "https://github.com/rjtbst/productsnap/blob/master/services/lifestyle_shot.py"
    click Packshot "https://github.com/rjtbst/productsnap/blob/master/services/packshot.py"
    click Prompt "https://github.com/rjtbst/productsnap/blob/master/services/prompt_enhancement.py"
    click Shadow "https://github.com/rjtbst/productsnap/blob/master/services/shadow.py"
    click Config "https://github.com/rjtbst/productsnap/blob/master/.env"
    click Deps "https://github.com/rjtbst/productsnap/blob/master/requirements.txt"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef orchestration fill:#90EE90,stroke:#000,stroke-width:1px
    classDef service fill:#98FB98,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:1px

    class Streamlit,componentsDir,Sidebar,Uploader,Preview presentation
    class Workflow orchestration
    class Erase,Fill,HD,Lifestyle,Packshot,Prompt,Shadow service
    class User,Browser,External external
    class Config,Deps config
```
