# google/jetpack-camera-app architecture

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

- Interactive diagram: https://gitdiagram.com/google/jetpack-camera-app
- Repository: https://github.com/google/jetpack-camera-app

## Overview

##### Project type and purpose
- Jetpack Camera App (JCA) is a modular, multi-module Android camera application built in Kotlin using CameraX and Jetpack Compose.
- It serves as a reference implementation for camera features (image/video capture, HDR, multi-stream, dual concurrent camera, etc.) and follows Modern Android Development (MAD) best practices (MVVM, DI, modularization, thorough testing).

##### File structure
Top-level modules:
- app – the Android application module; hosts the AndroidManifest, MainActivity, navigation (Routes.kt), application class, and aggregates feature modules.
- feature/* – Compose-backed UI feature modules (preview, settings, permissions, postcapture). Each provides its own ViewModel, UI Composables, navigation routes, and tests.
- core/common – domain-level utilities, DI modules, tracing, ref-counted utilities.
- core/camera – camera-use-case implementations built atop CameraX and native C++ JNI hooks (opengl_debug_jni.cpp, etc.). Provides CameraUseCase abstractions, session management, effects pipeline.
- data/media – media repositories that wrap Android’s MediaStore for saving/c fetching media.
- data/settings – settings repository built on Proto-DataStore (local data store for app settings).
- benchmark – microbenchmark suite for startup, first-frame, capture latency.
- build scripts, CI (GitHub workflows), formatting (Spotless), wrapper.

##### README for architectural insights
- “Clear separation between UI and data layers.”
- “Split into multiple modules to isolate features, domain logic, data access, and native code.”
- MVVM: ViewModel in each feature, business logic in core modules, repositories in data modules.

##### Detailed coverage
- High-level module structure and dependencies.
- Drill down to show critical components: MainActivity → Routes → [feature modules].
- ViewModel dependencies on Repositories and UseCases.
- How settings flows from DataStore to UI, and how media flows from ImageCapture to MediaStore.
- JNI C++ effects pipeline in core/camera.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        AppModule["app/src/main\nApp Module"]:::presentation
        MainActivity["MainActivity.kt"]:::presentation
        ApplicationClass["JetpackCameraApplication.kt"]:::presentation
        Routes["Routes.kt"]:::presentation
        JcaApp["JcaApp.kt"]:::presentation
        MainVM["MainActivityViewModel.kt"]:::presentation

        PreviewFeature["feature/preview\nPreview Feature"]:::presentation
        SettingsFeature["feature/settings\nSettings Feature"]:::presentation
        PermissionsFeature["feature/permissions\nPermissions Feature"]:::presentation
        PostCaptureFeature["feature/postcapture\nPost-Capture Feature"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer" 
        direction TB
        CoreCommon["core/common\nCommon Utilities & DI"]:::domain
        CoreCamera["core/camera\nCamera Use-Cases & Session"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MediaData["data/media\nMedia Repository"]:::data
        SettingsData["data/settings\nSettings Repository"]:::data
    end

    %% Native Layer
    subgraph "Native / Hardware Integration"
        direction TB
        JNI["core/camera/src/main/cpp\nJNI & Effects Pipeline"]:::native
    end

    %% External Services
    subgraph "External Platform Services"
        direction TB
        CameraX["CameraX APIs"]:::external
        Camera2HAL["Camera2 HAL"]:::external
        DeviceCam["Device Camera Hardware"]:::external
        MediaStore["Android MediaStore"]:::external
        DataStore["Android DataStore"]:::external
        PermissionsMgr["Permissions Manager"]:::external
    end

    %% CI & Benchmark
    subgraph "CI / Benchmarking"
        direction TB
        Benchmark["benchmark\nPerformance Benchmarks"]:::ci
        CI[".github/workflows\nCI & Build Scripts"]:::ci
    end

    %% Relationships
    AppModule -->|hosts| MainActivity
    AppModule --> ApplicationClass
    AppModule --> Routes
    AppModule --> JcaApp
    AppModule --> MainVM

    MainActivity -->|launches| JcaApp
    JcaApp -->|navigates via| Routes
    Routes -->|routes to| PreviewFeature
    Routes -->|routes to| SettingsFeature
    Routes -->|routes to| PermissionsFeature
    Routes -->|routes to| PostCaptureFeature

    PreviewFeature -->|uses| PreviewFeatureViewModel(PreviewViewModel):::presentation
    SettingsFeature -->|uses| SettingsVM(SettingsViewModel):::presentation
    PermissionsFeature -->|uses| PermissionsVM(PermissionsViewModel):::presentation
    PostCaptureFeature -->|uses| PostCaptureVM(PostCaptureViewModel):::presentation

    PreviewFeatureViewModel --> CoreCamera
    SettingsVM --> SettingsData
    PermissionsVM --> PermissionsMgr
    PostCaptureVM --> SettingsData

    CoreCamera -->|invokes| CameraX
    CoreCamera -->|native hooks| JNI
    CoreCommon --> CoreCamera

    MediaData --> MediaStore
    SettingsData --> DataStore

    CameraX --> Camera2HAL
    Camera2HAL --> DeviceCam

    Benchmark --> CoreCamera
    Benchmark --> AppModule

    CI --> AppModule
    CI --> CoreCommon
    CI --> CoreCamera
    CI --> MediaData
    CI --> SettingsData

    %% Click Events
    click MainActivity "https://github.com/google/jetpack-camera-app/blob/main/app/src/main/java/com/google/jetpackcamera/MainActivity.kt"
    click ApplicationClass "https://github.com/google/jetpack-camera-app/blob/main/app/src/main/java/com/google/jetpackcamera/JetpackCameraApplication.kt"
    click Routes "https://github.com/google/jetpack-camera-app/blob/main/app/src/main/java/com/google/jetpackcamera/ui/Routes.kt"
    click JcaApp "https://github.com/google/jetpack-camera-app/blob/main/app/src/main/java/com/google/jetpackcamera/ui/JcaApp.kt"
    click MainVM "https://github.com/google/jetpack-camera-app/blob/main/app/src/main/java/com/google/jetpackcamera/MainActivityViewModel.kt"

    click PreviewFeature "https://github.com/google/jetpack-camera-app/tree/main/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview"
    click SettingsFeature "https://github.com/google/jetpack-camera-app/tree/main/feature/settings/src/main/java/com/google/jetpackcamera/settings"
    click PermissionsFeature "https://github.com/google/jetpack-camera-app/tree/main/feature/permissions/src/main/java/com/google/jetpackcamera/permissions"
    click PostCaptureFeature "https://github.com/google/jetpack-camera-app/tree/main/feature/postcapture/src/main/java/com/google/jetpackcamera/feature/postcapture"

    click CoreCommon "https://github.com/google/jetpack-camera-app/tree/main/core/common/src/main/java/com/google/jetpackcamera/core/common"
    click CoreCamera "https://github.com/google/jetpack-camera-app/tree/main/core/camera/src/main/java/com/google/jetpackcamera/core/camera"
    click JNI "https://github.com/google/jetpack-camera-app/tree/main/core/camera/src/main/cpp"

    click MediaData "https://github.com/google/jetpack-camera-app/tree/main/data/media/src/main/kotlin/com/google/jetpackcamera/data/media"
    click SettingsData "https://github.com/google/jetpack-camera-app/tree/main/data/settings/src/main/java/com/google/jetpackcamera/settings"

    click Benchmark "https://github.com/google/jetpack-camera-app/tree/main/benchmark/src/main/java/com/google/jetpackcamera/benchmark"
    click CI "https://github.com/google/jetpack-camera-app/tree/main/.github/workflows"

    %% Styles
    classDef presentation fill:#D6EAF8,stroke:#2980B9,stroke-width:1px
    classDef domain fill:#D5F5E3,stroke:#28B463,stroke-width:1px
    classDef data fill:#FCF3CF,stroke:#D4AC0D,stroke-width:1px
    classDef native fill:#F5B7B1,stroke:#C0392B,stroke-width:1px
    classDef external fill:#E5E7E9,stroke:#7F8C8D,stroke-width:1px
    classDef ci fill:#EBDEF0,stroke:#9B59B6,stroke-width:1px
```
