# sbilalahmad/tfi_text_extractor architecture

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

- Interactive diagram: https://gitdiagram.com/sbilalahmad/tfi_text_extractor
- Repository: https://github.com/sbilalahmad/tfi_text_extractor

## Overview

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: [`app/src/main/java/com/example/tfi/ui/TextRecognitionScreen.kt`](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/TextRecognitionScreen.kt) (Recognition Screen), [`app/src/main/java/com/example/tfi/ml/TextRecognizer.kt`](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ml/TextRecognizer.kt) (Text Recognizer), [`app/build.gradle.kts`](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/build.gradle.kts) (Gradle Build), [`app/src/main/java/com/example/tfi/MainActivity.kt`](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/MainActivity.kt) (Main Activity)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_app["App Shell"]
  node_n_main["Main Activity<br/>activity host<br/>[MainActivity.kt]"]
  node_n_manifest["Manifest<br/>android config"]
end

subgraph group_g_ui["Compose UI"]
  node_n_screen["Recognition Screen<br/>compose screen"]
  node_n_state["UI State<br/>state model"]
  node_n_theme["App Theme<br/>compose theme<br/>[Theme.kt]"]
  node_n_colors["Colors<br/>theme tokens<br/>[Color.kt]"]
  node_n_type["Typography<br/>theme tokens<br/>[Type.kt]"]
end

subgraph group_g_ml["OCR Pipeline"]
  node_n_recognizer["Text Recognizer<br/>ml service<br/>[TextRecognizer.kt]"]
  node_n_image_utils["Image Utils<br/>image prep<br/>[ImageUtils.kt]"]
  node_n_camera(("CameraX Input<br/>camera integration"))
  node_n_gallery(("Gallery Input<br/>image source"))
  node_n_clipboard(("Clipboard<br/>platform action"))
end

subgraph group_g_android["Android Resources"]
  node_n_strings["Strings<br/>android resources<br/>[strings.xml]"]
  node_n_assets[("App Assets<br/>android resources")]
end

subgraph group_g_test["Tests"]
  node_n_unit_test["Unit Test<br/>test scaffold<br/>[ExampleUnitTest.kt]"]
  node_n_android_test["Instrumented Test<br/>android test scaffold"]
end

node_n_build["Gradle Build<br/>build config<br/>[build.gradle.kts]"]

node_n_main -->|"hosts"| node_n_screen
node_n_main -->|"declared in"| node_n_manifest
node_n_screen -->|"reads/writes"| node_n_state
node_n_screen -->|"invokes"| node_n_recognizer
node_n_screen -->|"prepares input"| node_n_image_utils
node_n_screen -->|"copies text"| node_n_clipboard
node_n_recognizer -->|"consumes"| node_n_image_utils
node_n_recognizer -.->|"accepts frames"| node_n_camera
node_n_recognizer -.->|"accepts images"| node_n_gallery
node_n_theme -->|"uses"| node_n_colors
node_n_theme -->|"uses"| node_n_type
node_n_screen -->|"styled by"| node_n_theme
node_n_screen -.->|"labels from"| node_n_strings
node_n_main -->|"built by"| node_n_build
node_n_recognizer -->|"depends on"| node_n_build
node_n_camera -.->|"supported by"| node_n_assets
node_n_clipboard -.->|"supported by"| node_n_assets
node_n_unit_test -.->|"runs under"| node_n_build
node_n_android_test -.->|"runs under"| node_n_build

click node_n_main "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/MainActivity.kt"
click node_n_manifest "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/AndroidManifest.xml"
click node_n_screen "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/TextRecognitionScreen.kt"
click node_n_state "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/TextRecognitionState.kt"
click node_n_theme "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/theme/Theme.kt"
click node_n_colors "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/theme/Color.kt"
click node_n_type "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/theme/Type.kt"
click node_n_recognizer "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ml/TextRecognizer.kt"
click node_n_image_utils "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/utils/ImageUtils.kt"
click node_n_strings "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/res/values/strings.xml"
click node_n_assets "https://github.com/sbilalahmad/tfi_text_extractor/tree/master/app/src/main/res"
click node_n_unit_test "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/test/java/com/example/tfi/ExampleUnitTest.kt"
click node_n_android_test "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/androidTest/java/com/example/tfi/ExampleInstrumentedTest.kt"
click node_n_build "https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/build.gradle.kts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_main,node_n_manifest toneBlue
class node_n_screen,node_n_state,node_n_theme,node_n_colors,node_n_type toneAmber
class node_n_recognizer,node_n_image_utils,node_n_camera,node_n_gallery,node_n_clipboard toneMint
class node_n_strings,node_n_assets toneRose
class node_n_unit_test,node_n_android_test toneIndigo
class node_n_build toneNeutral
```

## Components

### App Shell

Android entry point and manifest-level wiring.

- [Main Activity](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/MainActivity.kt): activity host · Android entry activity that hosts the Compose UI. · `app/src/main/java/com/example/tfi/MainActivity.kt`
- [Manifest](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/AndroidManifest.xml): android config · 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](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/TextRecognitionScreen.kt): compose screen · Main UI for selecting images, running OCR, and showing results. · `app/src/main/java/com/example/tfi/ui/TextRecognitionScreen.kt`
- [UI State](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/TextRecognitionState.kt): state model · State holder for the recognition flow and UI feedback. · `app/src/main/java/com/example/tfi/ui/TextRecognitionState.kt`
- [App Theme](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/theme/Theme.kt): compose theme · Shared colors, typography, and theme composition. · `app/src/main/java/com/example/tfi/ui/theme/Theme.kt`
- [Colors](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/theme/Color.kt): theme tokens · Color definitions used by the Compose theme. · `app/src/main/java/com/example/tfi/ui/theme/Color.kt`
- [Typography](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ui/theme/Type.kt): theme tokens · 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](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/ml/TextRecognizer.kt): ml service · Wraps on-device OCR and returns extracted text. · `app/src/main/java/com/example/tfi/ml/TextRecognizer.kt`
- [Image Utils](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/java/com/example/tfi/utils/ImageUtils.kt): image prep · Converts Android image inputs into OCR-ready form. · `app/src/main/java/com/example/tfi/utils/ImageUtils.kt`
- **CameraX Input**: camera integration · Captures images from the device camera for recognition.
- **Gallery Input**: image source · Selects existing images as OCR input.
- **Clipboard**: platform action · Copies recognized text for sharing or reuse.

### Android Resources

Platform resources and packaging configuration.

- [Strings](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/main/res/values/strings.xml): android resources · User-facing text resources for the app. · `app/src/main/res/values/strings.xml`
- [App Assets](https://github.com/sbilalahmad/tfi_text_extractor/tree/master/app/src/main/res): android resources · Icons, themes, and XML support files for packaging and runtime setup. · `app/src/main/res`

### Tests

Unit and instrumented test scaffolding.

- [Unit Test](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/test/java/com/example/tfi/ExampleUnitTest.kt): test scaffold · Local JVM test scaffold. · `app/src/test/java/com/example/tfi/ExampleUnitTest.kt`
- [Instrumented Test](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/src/androidTest/java/com/example/tfi/ExampleInstrumentedTest.kt): android test scaffold · Device/emulator test scaffold. · `app/src/androidTest/java/com/example/tfi/ExampleInstrumentedTest.kt`

### Other components

- [Gradle Build](https://github.com/sbilalahmad/tfi_text_extractor/blob/master/app/build.gradle.kts): build config · Module build setup and dependency wiring. · `app/build.gradle.kts`

## Connections

- 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.
