# google/android-fhir architecture

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

- Interactive diagram: https://gitdiagram.com/google/android-fhir
- Repository: https://github.com/google/android-fhir

## Overview

##### Main architectural components
- FHIR Engine and Database: This includes the “engine” module, which provides the core data synchronization, local storage, and FHIR REST operations (including database schema and migration logic). Also include key libraries that handle FHIR resource queries, search, and indexing.
- Knowledge and Terminology: The “knowledge” module and associated schemas, DAO classes, and npm package handling components form the backend for FHIR knowledge management and terminology support.
- Data Capture and UI Components: The “datacapture” and related modules (e.g., “catalog”, “demo”, “codelabs”) provide user interface components, fragments, adapters, and view models that allow questionnaire rendering and user data collection.
- Workflow and Business Rules: The “workflow” and “workflow_demo” modules encapsulate the logic for executing clinical workflows and integrating business rules (e.g., CQL processing) into the mobile application.
- External Contributions and Extensions: The “contrib” folders (e.g. barcode, locationwidget) show how the SDK can be extended with extra UI elements or specialized functionality.
- Build / Infrastructure and CI: Parts like the Gradle build scripts, GitHub workflows (under “.github”), and container configurations (under “.devcontainer”) should be represented to indicate how the project is built, tested, and integrated as part of continuous delivery.
- Documentation and Community: The “docs” folder and related markdown resources signal that documentation and community guidelines are also an important part of the ecosystem.

##### Component relationships and data flows
- That the Knowledge module and Workflow modules are layered on top of the Engine – they rely on FHIR data but also add clinical logic, terminology resolution, and process automation.

##### Architectural patterns and design principles
- Modularization: Emphasize the Gradle multi-module structure—each subproject is responsible for a set of related functionalities and is loosely coupled.
- Separation of concerns: Distinguish between the domain-specific core (FHIR Engine, Knowledge, and Workflow), the presentation layer (datacapture, demo, catalog), and extension points (contrib).
- Offline-first design: Mark the data syncing components and local database as central to enabling offline capability.
- Extensibility: Note how additional features (from the “contrib” folder) use common interfaces to plug into the main engine and UI frameworks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile UI and Sample Applications
    subgraph "Mobile UI and Sample Applications"
        DataCapture["Data Capture"]:::ui
        Catalog["Catalog"]:::ui
        Codelabs["Codelabs"]:::ui
        WorkflowDemo["Workflow Demo"]:::ui
    end

    %% Core Business Logic
    subgraph "Core Business Logic"
        FHIR_Engine["FHIR Engine & Database"]:::backend
        Knowledge["Knowledge & Terminology"]:::backend
        Workflow_Core["Workflow & Business Logic"]:::backend
        WorkflowTesting["Workflow Testing"]:::backend
    end

    %% External Extensions
    subgraph "External Extensions"
        Extensions["Extensions"]:::extension
        Barcode["Barcode Extension"]:::extension
        Location["Location Widget"]:::extension
    end

    %% Support and Infrastructure
    subgraph "Support and Infrastructure"
        Build_Github["GitHub Workflows"]:::support
        DevContainer["Dev Container"]:::support
        Gradle_Build["Gradle Build Scripts"]:::support
        BuildSrc["BuildSrc"]:::support
        Documentation["Documentation & Community"]:::support
    end

    %% Relationships between UI and Core
    DataCapture -->|"CRUD"| FHIR_Engine
    Catalog -->|"CRUD"| FHIR_Engine
    Codelabs -->|"CRUD"| FHIR_Engine
    WorkflowDemo -->|"workflow"| Workflow_Core
    Workflow_Core -->|"syncs"| FHIR_Engine
    WorkflowTesting -->|"tests"| Workflow_Core
    Knowledge -->|"queries"| FHIR_Engine

    %% Extensions relationships
    Extensions -->|"plugins"| FHIR_Engine
    Extensions -->|"integrates"| DataCapture
    Barcode -->|"extension"| Extensions
    Location -->|"extension"| Extensions

    %% Support relationships (dotted arrows for support components)
    Build_Github --- FHIR_Engine
    DevContainer --- FHIR_Engine
    Gradle_Build --- FHIR_Engine
    BuildSrc --- FHIR_Engine
    Documentation --- FHIR_Engine
    Documentation --- DataCapture

    %% Click Events
    click FHIR_Engine "https://github.com/google/android-fhir/tree/master/engine/src/main/java/com/google/android/fhir/"
    click Knowledge "https://github.com/google/android-fhir/tree/master/knowledge/"
    click DataCapture "https://github.com/google/android-fhir/tree/master/datacapture/"
    click Catalog "https://github.com/google/android-fhir/tree/master/catalog/"
    click Codelabs "https://github.com/google/android-fhir/tree/master/codelabs/datacapture/"
    click Workflow_Core "https://github.com/google/android-fhir/tree/master/workflow/"
    click WorkflowDemo "https://github.com/google/android-fhir/tree/master/workflow_demo/"
    click WorkflowTesting "https://github.com/google/android-fhir/tree/master/workflow-testing/"
    click Extensions "https://github.com/google/android-fhir/tree/master/contrib/"
    click Barcode "https://github.com/google/android-fhir/tree/master/contrib/barcode"
    click Location "https://github.com/google/android-fhir/tree/master/contrib/locationwidget"
    click Build_Github "https://github.com/google/android-fhir/tree/master/.github/"
    click DevContainer "https://github.com/google/android-fhir/tree/master/.devcontainer/"
    click Gradle_Build "https://github.com/google/android-fhir/blob/master/build.gradle.kts"
    click BuildSrc "https://github.com/google/android-fhir/tree/master/buildSrc/"
    click Documentation "https://github.com/google/android-fhir/tree/master/docs/"

    %% Styles
    classDef backend fill:#AED581,stroke:#33691E,stroke-width:2px;
    classDef ui fill:#81D4FA,stroke:#01579B,stroke-width:2px;
    classDef extension fill:#FFCC80,stroke:#E65100,stroke-width:2px;
    classDef support fill:#B2EBF2,stroke:#006064,stroke-width:2px;
```
