# approov/approov-service-okhttp architecture

> Architecture diagram of the GitHub repository approov/approov-service-okhttp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/approov/approov-service-okhttp
- Repository: https://github.com/approov/approov-service-okhttp

## Overview

##### Project type and purpose
- This is an Android/Java library module (“approov-service”) that wraps the Approov SDK to secure HTTP API calls made via OkHttp.
- It is not a standalone app but a drop-in interceptor and utility set that apps include to (a) fetch Approov tokens, (b) mutate or sign outgoing HTTP requests, and (c) handle Approov-related exceptions.

##### File structure
- Top-level: CI workflows (.github/workflows), Maven publish helpers (.maven), root Gradle files (build.gradle, settings.gradle, gradle wrapper).
- Core module: `approov-service/`
– build.gradle, pom.xml, proguard rules → build and packaging config.
– src/main/AndroidManifest.xml → manifest entries for Android library.
– src/main/java/io/approov/service → ApproovService plus OkHttp interceptor extensions, exceptions, request-mutation classes.
– src/main/java/io/approov/util/http/sfv → Structured Fields parsing/generation (third-party code).
– src/main/java/io/approov/util/sig → HTTP message-signing utility (third-party code).
– src/test → unit tests for signature utilities.

##### README for additional insights
- Confirms the goal: simplify integration of Approov SDK with OkHttp.
- Mentions included third-party code for SFV and HTTPSIG with their licenses.

##### Final advice
- Be detailed: break down the Approov-Service into Interceptor, Service, SFV and Sig packages.
- External interactions (Approov SDK & Cloud, API Server).
- Do not overthink—separate the system into every logical component and show their interactions clearly.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    App["Android App"]:::app
    OkHttpClient["OkHttpClient"]:::app

    %% Library Layer
    subgraph "Approov-Service Library"
        direction TB
        subgraph "Build & Config"
            direction TB
            BuildGradle["build.gradle"]:::config
            Pom["pom.xml"]:::config
            Proguard["proguard-rules.pro"]:::config
            Manifest["AndroidManifest.xml"]:::config
        end
        subgraph "Interceptor Module"
            ApproovInterceptor["ApproovInterceptor"]:::lib
        end
        subgraph "Service Module"
            ApproovService["ApproovService"]:::lib
        end
        subgraph "Mutation & Signing"
            RequestMutations["RequestMutations"]:::lib
            DefaultSigning["DefaultMessageSigning"]:::lib
        end
        subgraph "Exceptions"
            ApproovException["ApproovException"]:::lib
            NetworkException["ApproovNetworkException"]:::lib
            RejectionException["ApproovRejectionException"]:::lib
        end
        subgraph "Third-Party Utils"
            SFV["SFV Utilities"]:::lib
            Sig["Sig Utilities"]:::lib
        end
    end

    %% External Systems
    SDK["Approov SDK"]:::external
    Cloud["Approov Cloud Service"]:::external
    APIServer["Target API Server"]:::external

    %% Data Flow
    App -->|configures| OkHttpClient
    OkHttpClient -->|registers| ApproovInterceptor
    ApproovInterceptor -->|fetch token| ApproovService
    ApproovService -->|native call| SDK
    SDK -->|token| ApproovService
    ApproovService -->|returns token| ApproovInterceptor
    ApproovInterceptor -->|mutate request| RequestMutations
    ApproovInterceptor -->|sign request| DefaultSigning
    RequestMutations --> SFV
    DefaultSigning --> Sig
    ApproovInterceptor -->|inject headers| OkHttpClient
    OkHttpClient -->|send request| APIServer
    APIServer -->|validate token| Cloud
    APIServer -->|response / errors| OkHttpClient
    OkHttpClient -->|throws exceptions| ApproovException
    OkHttpClient -->|throws exceptions| NetworkException
    OkHttpClient -->|throws exceptions| RejectionException
    ApproovException --> App
    NetworkException --> App
    RejectionException --> App

    %% Click Events
    click BuildGradle "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/build.gradle"
    click Pom "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/pom.xml"
    click Proguard "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/proguard-rules.pro"
    click Manifest "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/AndroidManifest.xml"
    click ApproovInterceptor "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/java/io/approov/service/okhttp/ApproovInterceptorExtensions.java"
    click RequestMutations "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/java/io/approov/service/okhttp/ApproovRequestMutations.java"
    click DefaultSigning "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/java/io/approov/service/okhttp/ApproovDefaultMessageSigning.java"
    click ApproovService "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/java/io/approov/service/okhttp/ApproovService.java"
    click ApproovException "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/java/io/approov/service/okhttp/ApproovException.java"
    click NetworkException "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/java/io/approov/service/okhttp/ApproovNetworkException.java"
    click RejectionException "https://github.com/approov/approov-service-okhttp/blob/main/approov-service/src/main/java/io/approov/service/okhttp/ApproovRejectionException.java"
    click SFV "https://github.com/approov/approov-service-okhttp/tree/main/approov-service/src/main/java/io/approov/util/http/sfv/"
    click Sig "https://github.com/approov/approov-service-okhttp/tree/main/approov-service/src/main/java/io/approov/util/sig/"

    %% Styles
    classDef app fill:#f8cecc,stroke:#b85450;
    classDef lib fill:#dae8fc,stroke:#6c8ebf;
    classDef external fill:#d5e8d4,stroke:#82b366;
    classDef config fill:#fff2cc,stroke:#d6b656;
```
