# square/picasso architecture

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

- Interactive diagram: https://gitdiagram.com/square/picasso
- Repository: https://github.com/square/picasso

## Overview

##### Main Components
- Core Library Module ("picasso"):
- Contains the main image loading API (e.g., classes like Picasso.kt, RequestCreator.kt, BitmapHunter.kt, etc.).
- Manages image fetching, caching, image request handling, and transformations.
- Extension Modules:
- "picasso-compose": Provides integrations for Compose UI.
- "picasso-pollexor": Likely supports specialized request transformations (as hinted by classes like PollexorRequestTransformer.kt).
- "picasso-stats": Implements event listeners and logging (for gathering image-loading metrics).
- "picasso-paparazzi-sample" & "picasso-sample": Serve as sample/test applications that demonstrate usage of the library.
- API Definition Files:
- The modules have “api” directories (e.g., picasso/api/picasso.api, picasso-compose/api/picasso-compose.api) which define public interfaces and contracts.
- Testing & Samples:
- Multiple test directories and snapshot resources provide test cases, validating the behavior of each component.
- Build and Deployment Infrastructure:
- Gradle build scripts (build.gradle, gradle.properties, etc.) indicate a multi-module Gradle project and include workflows (in .github/workflows) for building and releasing.
- Website Module:
- The “website” folder holds static HTML, CSS, and JavaScript assets, implying that the project also includes documentation or a landing page for the library.

##### Relationships and Interactions
- The core “picasso” module acts as the central component:
- It handles network requests (using classes like NetworkRequestHandler).
- It manages caching policies (using classes like MemoryPolicy and PlatformLruCache).
- It defines the API for image requests (Request, RequestCreator, etc.).
- The “picasso-compose” module integrates (or adapts) the core functionality to work with Android’s Compose UI framework.
- “picasso-pollexor” sits alongside the core to modify or transform image requests, possibly intercepting and customizing the images.
- “picasso-stats” listens to various image loading events for logging and metrics, and its integration likely taps into calls made by the core library.
- The sample applications demonstrate how the modules interconnect in actual usage, showing UI components interacting with the library.
- Build and dependency management across modules is handled by the project’s Gradle scripts and common configuration files.

##### Architectural Patterns
- Separation of Concerns: Each module (core, Compose integration, request transformation, stats) is separated into its own Gradle project/submodule.
- API-Driven Design: The presence of “api” directories in multiple modules emphasizes clear contracts between components.
- Test-Driven/Verified Components: Each module has its own tests (src/test/ directories) which confirm the expected behavior of individual components.
- Layered Architecture: Lower layers handle low-level tasks (networking, caching) while higher layers expose simplified APIs to consuming applications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Applications"
        A1["Picasso Sample App"]:::sample
        A2["Picasso Paparazzi Sample App"]:::sample
        A3["Website/Documentation Module"]:::docs
    end

    subgraph "Core and Extensions"
        C["Core Image Loading Module"]:::core
        C1["Picasso Compose Integration"]:::extension
        C2["Request Transformer Module"]:::extension
        C3["Statistics & Monitoring"]:::extension
    end

    subgraph "Infrastructure"
        I["Build & Deployment Infrastructure"]:::infra
    end

    A1 -->|"uses"| C
    A2 -->|"uses"| C
    A3 -->|"documents"| C

    C1 -->|"integrates"| C
    C -->|"triggers"| C2
    C -->|"logs"| C3

    I -->|"builds"| C
    I -->|"builds"| C1
    I -->|"builds"| C2
    I -->|"builds"| C3
    I -->|"builds"| A1
    I -->|"builds"| A2
    I -->|"builds"| A3

    click C "https://github.com/square/picasso/tree/master/picasso/"
    click C1 "https://github.com/square/picasso/tree/master/picasso-compose/"
    click C2 "https://github.com/square/picasso/blob/master/picasso-pollexor/src/main/java/com/squareup/picasso3/pollexor/PollexorRequestTransformer.kt"
    click C3 "https://github.com/square/picasso/tree/master/picasso-stats/"
    click A1 "https://github.com/square/picasso/tree/master/picasso-sample/"
    click A2 "https://github.com/square/picasso/tree/master/picasso-paparazzi-sample/"
    click A3 "https://github.com/square/picasso/tree/master/website/"
    click I "https://github.com/square/picasso/tree/master/.github/workflows/"

    classDef core fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef extension fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef sample fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef docs fill:#e6ccff,stroke:#663399,stroke-width:2px;
    classDef infra fill:#ffffcc,stroke:#999900,stroke-width:2px;
```
