# gsrathoreniks/scratchify architecture

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

- Interactive diagram: https://gitdiagram.com/gsrathoreniks/scratchify
- Repository: https://github.com/gsrathoreniks/scratchify

## Overview

##### Project Type & Purpose
- Scratchify is a **Compose Multiplatform SDK** (library) for building scratch‐card surfaces on Android & iOS.
- It ships as a Kotlin Multiplatform (`scratchify`) module and provides an Android sample app (`sample/`) showcasing its usage.

##### File Structure
- Top-Level Modules
– `scratchify/` (core library)
– `sample/` (Android example app)
- `scratchify/src/commonMain/kotlin/...`
– `api/`
- `ScratchifyController` – primary composable controller
- `Scratchify` – Composable entry point
- `ScratchGridTracker` – tracks scratched cells
- `config/` – brush & scratch settings
– `internal/extension/` – helper extensions for Compose Modifiers & Offsets
- `sample/src/main/...`
– `MainActivity.kt` – hosts the Compose UI demo
– `ui/theme/` – theming resources
– Android resources (drawables, mipmaps, values)
- Build & Config
– `build.gradle.kts`, Gradle wrapper, versions TOML, proguard, etc.

##### Extract Key Architectural Insights
- **Core Layer** (`scratchify`)
- Platform‐agnostic business logic and UI composables
- Config abstraction enabling brush customization & callbacks
- **Platform Integration**
- JVM/Android Publishing (Gradle setup, Maven Central)
- Expected to publish iOS artifacts via Compose Multiplatform tooling
- **Sample App** (`sample`)
- Demonstrates integration: adds `scratchify` dependency, invokes `Scratchify(...)` in a Compose hierarchy
- Shows lifecycle & event callbacks (`onScratchStarted`, etc.)

a. Main Components
- **Library Module (“Scratchify”)**
– API Layer: `Scratchify` Composable, `ScratchifyController`
– Scratch Tracker: `ScratchGridTracker`
– Configuration: `ScratchifyConfig`, `ScratchifyBrushConfig`
– Extensions: UI helper functions in `internal/extension`
- **Platform Targets**
– Android (JVM) / iOS (Kotlin/Native)
- **Sample App**
– UI Layer: `MainActivity` + Compose UI
– Theming & Resources
- **Build & Distribution**
– Gradle/Maven Central
b. Relationships & Data Flow
– Sample App → depends on → Scratchify Library
– Sample UI calls → `Scratchify` Composable → delegates to → `ScratchifyController`
– Controller updates → `ScratchGridTracker` → emits → scratch progress/completion callbacks
– Callbacks propagate back up to the Sample App for business logic (reveal after X%)
c. Architectural Patterns & Principles
– **Separation of Concerns**: UI Composables vs. Business Logic vs. Configuration
– **Kotlin Multiplatform**: shared code in `commonMain`, no platform‐specific code in core
– **Composable Architecture**: declarative UI, unidirectional data flow (state in controller, events out)
d. Key Technologies
– Kotlin Multiplatform (Gradle Kotlin DSL)
– Jetpack Compose Multiplatform (UI)
– Gradle (build, publishing)

##### Levels of Detail
- At the **high level**, show modules & their dependencies.
- **Zoom in** on the library internals:
– API layer → Controller → Tracker → Config → UI extension
1. User drags finger →
2. Composable reports offset →
3. Controller updates tracker →
4. Tracker triggers onScratchProgress →
5. Controller requests recompose →
6. UI shows updated overlay.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Modules
    subgraph "Scratchify Library" 
        direction TB
        subgraph "API Layer"
            direction TB
            Scratchify["Scratchify() Composable"]:::core
            ScratchifyController["ScratchifyController"]:::core
        end
        subgraph "Tracker"
            direction TB
            ScratchGridTracker["ScratchGridTracker"]:::core
        end
        subgraph "Config"
            direction TB
            ScratchifyConfig["ScratchifyConfig"]:::core
            ScratchifyBrushConfig["ScratchifyBrushConfig"]:::core
        end
        subgraph "Extensions"
            direction TB
            ModifierExt["ModifierExt"]:::core
            OffsetExt["OffsetExt"]:::core
        end
    end

    subgraph "Sample App (Android Demo)"
        direction TB
        MainActivity["MainActivity"]:::sample
        subgraph "UI Entry Point"
            direction TB
            SampleUI["Sample UI (Compose Setup)"]:::sample
        end
        subgraph "Theming"
            direction TB
            Color["Color.kt"]:::sample
            Theme["Theme.kt"]:::sample
            Type["Type.kt"]:::sample
        end
        subgraph "Resources"
            direction TB
            Drawables["Drawable & Mipmap Resources"]:::sample
            Values["Values (colors, strings)"]:::sample
        end
    end

    subgraph "Platform Targets"
        direction TB
        Android["Android (JVM)"]:::platform
        iOS["iOS (Kotlin/Native)"]:::platform
    end

    subgraph "Build & Publishing"
        direction TB
        GradleDSL["Gradle Build Scripts"]:::build
        MavenCentral["Maven Central"]:::build
    end

    %% Dependencies & Data Flow
    MainActivity -->|"depends on"| Scratchify
    SampleUI -->|"invoke Scratchify()"| Scratchify
    Scratchify -->|"delegates to"| ScratchifyController
    ScratchifyController -->|"uses"| ScratchGridTracker
    ScratchGridTracker -.->|"emit onScratchProgress"| MainActivity

    Scratchify -->|publish artifacts| GradleDSL
    GradleDSL -->|publishes to| MavenCentral

    Scratchify -->|targets| Android
    Scratchify -->|targets| iOS

    %% Click Events
    click Scratchify "https://github.com/gsrathoreniks/scratchify/blob/master/scratchify/src/commonMain/kotlin/com/gsrathoreniks/scratchify/api/Scratchify.kt"
    click ScratchifyController "https://github.com/gsrathoreniks/scratchify/blob/master/scratchify/src/commonMain/kotlin/com/gsrathoreniks/scratchify/api/ScratchifyController.kt"
    click ScratchGridTracker "https://github.com/gsrathoreniks/scratchify/blob/master/scratchify/src/commonMain/kotlin/com/gsrathoreniks/scratchify/api/ScratchGridTracker.kt"
    click ScratchifyConfig "https://github.com/gsrathoreniks/scratchify/blob/master/scratchify/src/commonMain/kotlin/com/gsrathoreniks/scratchify/api/config/ScratchifyConfig.kt"
    click ScratchifyBrushConfig "https://github.com/gsrathoreniks/scratchify/blob/master/scratchify/src/commonMain/kotlin/com/gsrathoreniks/scratchify/api/config/ScratchifyBrushConfig.kt"
    click ModifierExt "https://github.com/gsrathoreniks/scratchify/blob/master/scratchify/src/commonMain/kotlin/com/gsrathoreniks/scratchify/internal/extension/ModifierExt.kt"
    click OffsetExt "https://github.com/gsrathoreniks/scratchify/blob/master/scratchify/src/commonMain/kotlin/com/gsrathoreniks/scratchify/internal/extension/OffsetExt.kt"
    click MainActivity "https://github.com/gsrathoreniks/scratchify/blob/master/sample/src/main/java/com/gsrathoreniks/sample/MainActivity.kt"
    click SampleUI "https://github.com/gsrathoreniks/scratchify/tree/master/sample/src/main/java/com/gsrathoreniks/sample/ui/"
    click Color "https://github.com/gsrathoreniks/scratchify/blob/master/sample/src/main/java/com/gsrathoreniks/sample/ui/theme/Color.kt"
    click Theme "https://github.com/gsrathoreniks/scratchify/blob/master/sample/src/main/java/com/gsrathoreniks/sample/ui/theme/Theme.kt"
    click Type "https://github.com/gsrathoreniks/scratchify/blob/master/sample/src/main/java/com/gsrathoreniks/sample/ui/theme/Type.kt"

    %% Styles
    classDef core fill:#E0F7FA,stroke:#0288D1,color:#000
    classDef sample fill:#E8F5E9,stroke:#388E3C,color:#000
    classDef platform fill:#FFF3E0,stroke:#F57C00,color:#000
    classDef build fill:#EEEEEE,stroke:#757575,color:#000
```
