# google/fhir-gateway architecture

> Architecture diagram of the GitHub repository google/fhir-gateway, 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/fhir-gateway
- Repository: https://github.com/google/fhir-gateway

## Overview

##### Main Components
- Core Proxy Server (the “server” module): Implements the core functionality of receiving FHIR requests, validating JWT tokens, applying access control logic (via access-checkers) and forwarding queries to the FHIR store.
- Access-Checker Plugins (the “plugins” module): These encapsulate the per-request authorization logic. There are sample plugins (e.g., for checking patient or list-based authorization) that can be dynamically loaded into the proxy.
- Executable Application (the “exec” module): Provides a complete Spring Boot application that packages the proxy server and access-checker plugins together so that they can be run as an executable jar.
- Configuration & Environment: Includes configuration parameters (environment variables) like PROXY_TO, TOKEN_ISSUER, ACCESS_CHECKER, and BACKEND_TYPE that dictate runtime behavior and integration with external services.
- External FHIR Data Store: An external FHIR server or store (such as HAPI FHIR or GCP FHIR store) that the proxy forwards validated queries to.
- Identity Provider/Authorization Server (IDP/AuthZ): Although not implemented within this project, it is a critical external component that issues access tokens (JWT) which the proxy validates.
- Docker & CI/CD Components: Dockerfiles, GitHub workflows, and related scripts indicate that the system is designed to be deployed in containers and built using CI/CD pipelines.

##### Architectural Relationships and Data Flow
- Requests originate from the client (e.g., a FHIR client application) and target the FHIR Gateway.
- The gateway first verifies the presence and validity of a Bearer access token. This token’s claims are used by the access-checker plugins.
- Depending on the token’s contents (e.g., “patient_list” or “patient_id”), the appropriate plugin in the plugins module evaluates whether to allow or deny the request.
- If approved, the proxy (server module) forwards the request to the designated backend FHIR store (which can be HAPI, GCP, etc.).
- The response from the FHIR store is relayed back through the gateway to the client.
- Optional components include using Docker images, service accounts (for GCP), and other security configurations that tie into the deployment and operational environment.

##### Architectural Patterns and Design Principles
- Modular Design: The separation of the core proxy logic (server) from the access-checker plugins (plugins) offers extensibility and separation of concerns.
- Layered Architecture: There are distinct layers including the HTTP interface (Spring Boot Web layer), application/service layer (authentication & access control logic), and integration layer (communication with external FHIR servers).
- Dependency Injection and Component Scanning: The project leverages Spring Boot (especially in the exec module) to automatically discover and wire up components, such as the automatic detection of plugins via @ComponentScan.
- Proxy Pattern: The application functions as an intermediary, securing and routing communication between FHIR clients and the underlying FHIR datastore.

##### Relevant Technologies, Frameworks, and Tools
- Java & Maven: The project follows a standard Java project structure with multiple Maven modules (server, plugins, exec, etc.).
- Spring Boot: Used primarily in the “exec” module to simplify server setup and dependency management.
- Docker: Provided Dockerfiles and Docker Compose files indicate containerization for deployment.
- CI/CD Tools: GitHub workflows (such as CodeQL and Codecov) for automated testing and security analysis.
- HAPI FHIR: The proxy is built on a HAPI FHIR Plain Server, one of the popular FHIR server frameworks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    FHIRClient["FHIR Client"]:::external
    IDP["Identity Provider/AuthZ"]:::external
    ExternalFHIR["External FHIR Data Store"]:::external

    %% Deployment & CI/CD
    Deploy["Docker & CI/CD Components"]:::infrastructure

    %% Gateway (Executable Application) Subgraph
    subgraph "Gateway (Executable Application)"
        EXE["Executable Application"]:::internal
        CPS["Core Proxy Server"]:::internal
        ACP["Access-Checker Plugins"]:::internal
        CE["Configuration & Environment"]:::internal

        EXE -->|"routes to"| CPS
        CPS -->|"invokes"| ACP
        CE -->|"configures"| CPS
        CE -->|"configures"| ACP
    end

    %% Data flow
    IDP -->|"issuesJWT"| FHIRClient
    FHIRClient -->|"FHIRRequest(withJWT)"| EXE
    CPS -->|"forwardsRequest"| ExternalFHIR
    Deploy ---|"deploys via container"| EXE

    %% Click Events
    click CPS "https://github.com/google/fhir-gateway/tree/main/server/"
    click ACP "https://github.com/google/fhir-gateway/tree/main/plugins/"
    click EXE "https://github.com/google/fhir-gateway/tree/main/exec/"
    click CE "https://github.com/google/fhir-gateway/tree/main/docker/"
    click ExternalFHIR "https://github.com/google/fhir-gateway/blob/main/docker/hapi-proxy-compose.yaml"
    click IDP "https://github.com/google/fhir-gateway/tree/main/docker/keycloak/"
    click Deploy "https://github.com/google/fhir-gateway/tree/main/.github/workflows/"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#FFD700,stroke:#000,stroke-width:2px;
```
