How sbilalahmad/tfi_text_extractor works
1. Repository shape
- This is a single-module Android app (app/) written in Kotlin.
- The app is built with Gradle Kotlin DSL and uses Jetpack Compose for UI.
- There is no backend service or multi-module separation; the architecture is client-side only.
2. App entry point
- MainActivity.kt is the Android entry activity and likely serves as the Compose host.
- The activity is the bridge between the Android lifecycle and the Compose-based screen tree.
3. Presentation layer
- ui/TextRecognitionScreen.kt is the main feature screen.
- ui/TextRecognitionState.kt holds the UI state for the text-recognition flow, likely including selected image, loading/error flags, and recognized text.
- This suggests a state-driven Compose architecture where the screen reacts to state changes rather than directly owning business logic.
4. OCR / ML subsystem
- ml/TextRecognizer.kt is the core text-extraction component.
- Based on the README and package name, this wraps Google ML Kit’s on-device text recognition API.
- This is the main non-UI service boundary: image input goes in, recognized text comes out.
5. Image handling boundary
- utils/ImageUtils.kt likely performs image preparation before OCR, such as converting Android image sources into the format expected by ML Kit.
- This separates platform/image plumbing from the recognition logic and keeps the OCR layer focused on inference.
6. User interaction flow
- The app supports text extraction from either gallery images or camera captures, per the README.
- A typical flow is: user chooses or captures an image → UI passes the image to the recognition pipeline → OCR runs → recognized text is shown in the Compose screen.
- The screen likely also exposes a copy-to-clipboard action, which is a separate Android platform interaction.
7. Platform integrations
- The README mentions CameraX, so camera capture is likely handled through Android camera APIs rather than a custom camera backend.
- Clipboard access is another platform integration used to copy recognized text.
- Permissions and manifest declarations are centralized in AndroidManifest.xml.
8. UI theming and design system
- ui/theme/Color.kt, Theme.kt, and Type.kt define the Compose theme layer.
- This is a supporting subsystem rather than business logic, but it affects how screens are composed and styled consistently.
9. Resources and Android packaging
- res/ contains app assets and configuration: colors, strings, themes, launcher icons, and XML config files.
- file_paths.xml, backup rules, and data extraction rules indicate standard Android platform setup, not application logic.
- These resources support runtime behavior but do not form a separate feature boundary.
10. Testing boundary
- src/test and src/androidTest show both local unit tests and instrumented Android tests.
- The current tree suggests testing is present but limited to the default scaffold, so the main architecture is still centered on runtime feature code.
11. High-level data flow
- Input source: gallery image or camera frame.
- Processing: image normalization/prep in ImageUtils, then OCR in TextRecognizer using ML Kit.
- Output: recognized text stored in UI state and rendered by TextRecognitionScreen.
- Secondary action: copied to clipboard for sharing.
12. Architecture summary
- The repo is organized as a small layered Android app: platform entry point, Compose UI/state, image preprocessing, and ML Kit-based OCR.
- The key boundary to draw is between the UI/state layer and the ML-driven recognition layer, with Android camera/image utilities as supporting integration points.
Main entry points: TextRecognitionScreen.kt Recognition Screen · TextRecognizer.kt Text Recognizer · build.gradle.kts Gradle Build · MainActivity.kt Main Activity
Components 17
App Shell
Android entry point and manifest-level wiring.
- Main Activity · Android entry activity that hosts the Compose UI.
app/src/main/java/com/example/tfi/MainActivity.kt - Manifest · Declares the app component and platform permissions/setup.
app/src/main/AndroidManifest.xml
Compose UI
State-driven screen and theming for the text recognition flow.
- Recognition Screen · Main UI for selecting images, running OCR, and showing results.
app/src/main/java/com/example/tfi/ui/TextRecognitionScreen.kt - UI State · State holder for the recognition flow and UI feedback.
app/src/main/java/com/example/tfi/ui/TextRecognitionState.kt - App Theme · Shared colors, typography, and theme composition.
app/src/main/java/com/example/tfi/ui/theme/Theme.kt - Colors · Color definitions used by the Compose theme.
app/src/main/java/com/example/tfi/ui/theme/Color.kt - Typography · Typography definitions used by the Compose theme.
app/src/main/java/com/example/tfi/ui/theme/Type.kt
OCR Pipeline
Image preparation and on-device text recognition.
- Text Recognizer · Wraps on-device OCR and returns extracted text.
app/src/main/java/com/example/tfi/ml/TextRecognizer.kt - Image Utils · Converts Android image inputs into OCR-ready form.
app/src/main/java/com/example/tfi/utils/ImageUtils.kt - CameraX Input · Captures images from the device camera for recognition.
- Gallery Input · Selects existing images as OCR input.
- Clipboard · Copies recognized text for sharing or reuse.
Android Resources
Platform resources and packaging configuration.
- Strings · User-facing text resources for the app.
app/src/main/res/values/strings.xml - App Assets · Icons, themes, and XML support files for packaging and runtime setup.
app/src/main/res
Tests
Unit and instrumented test scaffolding.
- Unit Test · Local JVM test scaffold.
app/src/test/java/com/example/tfi/ExampleUnitTest.kt - Instrumented Test · Device/emulator test scaffold.
app/src/androidTest/java/com/example/tfi/ExampleInstrumentedTest.kt
Other components
- Gradle Build · Module build setup and dependency wiring.
app/build.gradle.kts
Connections 19
- Main Activity → Recognition Screen: hosts · Activity sets up the Compose screen tree.
- Main Activity → Manifest: declared in · Manifest registers the entry activity.
- Recognition Screen → UI State: reads/writes · Screen reacts to and updates recognition state.
- Recognition Screen → Text Recognizer: invokes · UI triggers OCR on selected images.
- Recognition Screen → Image Utils: prepares input · Screen uses image conversion utilities before OCR.
- Recognition Screen → Clipboard: copies text · Recognized text can be copied to clipboard.
- Text Recognizer → Image Utils: consumes · Recognition expects OCR-ready image input.
- Text Recognizer → CameraX Input: accepts frames · Camera captures can feed the recognition pipeline.
- Text Recognizer → Gallery Input: accepts images · Gallery-picked images can feed the recognition pipeline.
- App Theme → Colors: uses · Theme composes shared color tokens.
- App Theme → Typography: uses · Theme composes shared typography tokens.
- Recognition Screen → App Theme: styled by · Recognition screen uses the Compose theme.
- Recognition Screen → Strings: labels from · Screen text is sourced from string resources.
- Main Activity → Gradle Build: built by · Module build config defines the app runtime and dependencies.
- Text Recognizer → Gradle Build: depends on · OCR implementation is enabled by build dependencies.
- CameraX Input → App Assets: supported by · Camera and file-path configuration live in app resources.
- Clipboard → App Assets: supported by · Platform behavior is packaged with app resources and manifest setup.
- Unit Test → Gradle Build: runs under · Unit tests are configured in the module build.
- Instrumented Test → Gradle Build: runs under · Instrumented tests are configured in the module build.