How gsrathoreniks/scratchify works
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.