# xuningjack/apikeylib architecture

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

- Interactive diagram: https://gitdiagram.com/xuningjack/apikeylib
- Repository: https://github.com/xuningjack/apikeylib

## Overview

1. **Repository purpose**
   - This is an Android project centered on **request-signature generation** for network calls.
   - The core problem it solves is: take request parameters, normalize them, and produce a sign/authorization string using **sorting + concatenation + MD5**, with part of the logic implemented in native C++.

2. **Top-level structure**
   - The repo has two main runtime modules:
     - **`apikeylib`**: reusable library containing the signing logic.
     - **`app`**: sample Android application that demonstrates how to call the library.
   - Supporting files at the root are standard Gradle/Android build infrastructure.

3. **Core library boundary: `apikeylib`**
   - `apikeylib` is the architectural center of the repo.
   - Its public Java entry point is **`com.jack.apikeylib.SignHelper`**.
   - This module also contains the native implementation under `src/main/cpp`, indicating the library is designed to keep at least part of the signing algorithm in JNI/native code.

4. **Public API surface**
   - The README exposes two main signing flows:
     - **Authorization/sign generation from request body**: sort `map`-style parameters by key, concatenate values, then append `user_token`, `appkey`, and `timestamp`, and MD5 the result.
     - **MD5-based native encryption flow**: compute MD5-based signing by passing a sign string through a native method.
   - From an architecture standpoint, `SignHelper` is the API boundary that consumers should use; the rest is implementation detail.

5. **Native implementation layer**
   - The `cpp` subtree contains the low-level cryptographic and string utilities:
     - `api_helper.cpp/.h`: likely the JNI bridge and/or native orchestration layer.
     - `encrypt/md5.cpp/.h`: MD5 implementation.
     - `encrypt/base64.h`, `encrypt/urlEncode.h`: helper utilities for encoding/decoding.
     - `string_helper.h`: string manipulation helpers.
   - This layer is where the signing algorithm’s sensitive or performance-critical parts live.

6. **Data flow for signing**
   - Expected flow is:
     - The app or another client constructs request parameters.
     - Parameters are normalized by key ordering and value concatenation.
     - Additional fields such as `user_token`, `appkey`, and `timestamp` are appended depending on the signing mode.
     - The final string is hashed with MD5.
     - The result is returned to Java and then to the caller for use as an authorization/sign header or request parameter.
   - The repo is about **deterministic transformation**, not persistence or networking.

7. **Android sample app**
   - The `app` module is a demonstration client, not the core product.
   - `MainActivity` and `EncryptUtil` suggest the app provides a UI or simple wrapper to test or showcase the signing functions.
   - `activity_main.xml` and the Android resources support this sample UI, likely to let developers verify generated signatures.

8. **Build and integration architecture**
   - The library uses **Gradle** plus **CMake**, showing a mixed Java + native build.
   - `build.gradle`, `settings.gradle`, and `gradle/wrapper` define the Android build pipeline.
   - `apikeylib/CMakeLists.txt` and `api_helper.cpp` indicate the native code is compiled as part of the Android library and packaged into the AAR/apk.

9. **Packaging and runtime dependencies**
   - The library is self-contained; there are no visible backend services, databases, or third-party runtime systems in the tree.
   - The only meaningful runtime boundary is between:
     - Java/Kotlin Android code in the app/library
     - JNI native C++ code inside `apikeylib`
   - That boundary matters because the signing implementation is split across managed and native code.

10. **Security/obfuscation implication**
   - Keeping part of the sign logic in native code suggests an intent to make the algorithm less exposed than a pure-Java implementation.
   - `proguard-rules.pro` in both modules indicates the project is prepared for Android code shrinking/obfuscation.

11. **How to draw the architecture**
   - A useful diagram would show:
     - **App UI / caller**
       → **`EncryptUtil` / `SignHelper` Java API**
       → **JNI bridge (`api_helper`)**
       → **native crypto utilities (`md5`, encoding helpers)**
       → **signature output returned to Java**
   - The `app` module should be shown as a consumer of the `apikeylib` module, not as part of the signing engine itself.

12. **What is not present**
   - There is no evidence of server components, message queues, persistence, analytics, or external APIs.
   - This repo is primarily a **client-side Android signing library with a demo app** rather than a full system.

Main entry points: [`apikeylib/src/main/cpp/api_helper.cpp`](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/api_helper.cpp) (JNI bridge), [`app/src/main/java/cn/jack/apikeynativelib/EncryptUtil.java`](https://github.com/xuningjack/apikeylib/blob/master/app/src/main/java/cn/jack/apikeynativelib/EncryptUtil.java) (EncryptUtil), [`app/src/main/java/cn/jack/apikeynativelib/MainActivity.java`](https://github.com/xuningjack/apikeylib/blob/master/app/src/main/java/cn/jack/apikeynativelib/MainActivity.java) (MainActivity), [`apikeylib/src/main/java/com/jack/apikeylib/SignHelper.java`](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/java/com/jack/apikeylib/SignHelper.java) (SignHelper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build"]
  node_root_build["Gradle build<br/>android build<br/>[build.gradle]"]
  node_settings["Settings<br/>module wiring<br/>[settings.gradle]"]
end

subgraph group_library["apikeylib"]
  node_cmake["CMake<br/>native build<br/>[CMakeLists.txt]"]
  node_lib_manifest["Lib manifest<br/>android manifest"]
  node_sign_helper["SignHelper<br/>Java API<br/>[SignHelper.java]"]
  node_api_helper["JNI bridge<br/>native bridge<br/>[api_helper.cpp]"]
  node_md5["MD5 core<br/>crypto impl<br/>[md5.cpp]"]
  node_string_helper["String utils<br/>native utils<br/>[string_helper.h]"]
  node_base64["Base64<br/>encoding utils<br/>[base64.h]"]
  node_url_encode["URL encode<br/>encoding utils<br/>[urlEncode.h]"]
end

subgraph group_app["app"]
  node_app_manifest["App manifest<br/>android manifest"]
  node_main_activity["MainActivity<br/>sample UI<br/>[MainActivity.java]"]
  node_encrypt_util["EncryptUtil<br/>sample wrapper<br/>[EncryptUtil.java]"]
  node_activity_layout["UI layout<br/>android layout<br/>[activity_main.xml]"]
end

node_settings -->|"includes"| node_root_build
node_root_build -->|"drives"| node_cmake
node_cmake -->|"compiles"| node_api_helper
node_api_helper -->|"uses"| node_md5
node_api_helper -->|"uses"| node_string_helper
node_api_helper -->|"uses"| node_base64
node_api_helper -->|"uses"| node_url_encode
node_sign_helper -->|"calls native"| node_api_helper
node_main_activity -->|"uses"| node_encrypt_util
node_encrypt_util -->|"calls"| node_sign_helper
node_main_activity -->|"renders"| node_activity_layout
node_app_manifest -->|"declares"| node_main_activity
node_lib_manifest -->|"exposes"| node_sign_helper
node_encrypt_util -.->|"tests"| node_api_helper

click node_root_build "https://github.com/xuningjack/apikeylib/blob/master/build.gradle"
click node_settings "https://github.com/xuningjack/apikeylib/blob/master/settings.gradle"
click node_cmake "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/CMakeLists.txt"
click node_lib_manifest "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/AndroidManifest.xml"
click node_sign_helper "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/java/com/jack/apikeylib/SignHelper.java"
click node_api_helper "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/api_helper.cpp"
click node_md5 "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/encrypt/md5.cpp"
click node_string_helper "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/string_helper.h"
click node_base64 "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/encrypt/base64.h"
click node_url_encode "https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/encrypt/urlEncode.h"
click node_app_manifest "https://github.com/xuningjack/apikeylib/blob/master/app/src/main/AndroidManifest.xml"
click node_main_activity "https://github.com/xuningjack/apikeylib/blob/master/app/src/main/java/cn/jack/apikeynativelib/MainActivity.java"
click node_encrypt_util "https://github.com/xuningjack/apikeylib/blob/master/app/src/main/java/cn/jack/apikeynativelib/EncryptUtil.java"
click node_activity_layout "https://github.com/xuningjack/apikeylib/blob/master/app/src/main/res/layout/activity_main.xml"

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_root_build,node_settings toneBlue
class node_cmake,node_lib_manifest,node_sign_helper,node_api_helper,node_md5,node_string_helper,node_base64,node_url_encode toneAmber
class node_app_manifest,node_main_activity,node_encrypt_util,node_activity_layout toneMint
```

## Components

### Build

Gradle and native build setup

- [Gradle build](https://github.com/xuningjack/apikeylib/blob/master/build.gradle): android build · Top-level Gradle and wrapper configuration · `build.gradle`
- [Settings](https://github.com/xuningjack/apikeylib/blob/master/settings.gradle): module wiring · Project module registration · `settings.gradle`

### apikeylib

Reusable signature library

- [CMake](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/CMakeLists.txt): native build · Native build definition for the library · `apikeylib/CMakeLists.txt`
- [Lib manifest](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/AndroidManifest.xml): android manifest · Library component declaration · `apikeylib/src/main/AndroidManifest.xml`
- [SignHelper](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/java/com/jack/apikeylib/SignHelper.java): Java API · Public signing entry point for consumers · `apikeylib/src/main/java/com/jack/apikeylib/SignHelper.java`
- [JNI bridge](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/api_helper.cpp): native bridge · Native orchestration and Java-native boundary · `apikeylib/src/main/cpp/api_helper.cpp`
- [MD5 core](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/encrypt/md5.cpp): crypto impl · Native MD5 hashing implementation · `apikeylib/src/main/cpp/encrypt/md5.cpp`
- [String utils](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/string_helper.h): native utils · String normalization and helper routines · `apikeylib/src/main/cpp/string_helper.h`
- [Base64](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/encrypt/base64.h): encoding utils · Native base64 helper header · `apikeylib/src/main/cpp/encrypt/base64.h`
- [URL encode](https://github.com/xuningjack/apikeylib/blob/master/apikeylib/src/main/cpp/encrypt/urlEncode.h): encoding utils · Native URL encoding helper header · `apikeylib/src/main/cpp/encrypt/urlEncode.h`

### app

Sample Android client

- [App manifest](https://github.com/xuningjack/apikeylib/blob/master/app/src/main/AndroidManifest.xml): android manifest · Sample app declaration · `app/src/main/AndroidManifest.xml`
- [MainActivity](https://github.com/xuningjack/apikeylib/blob/master/app/src/main/java/cn/jack/apikeynativelib/MainActivity.java): sample UI · Demo screen that exercises signing · `app/src/main/java/cn/jack/apikeynativelib/MainActivity.java`
- [EncryptUtil](https://github.com/xuningjack/apikeylib/blob/master/app/src/main/java/cn/jack/apikeynativelib/EncryptUtil.java): sample wrapper · App-side helper for invoking the library · `app/src/main/java/cn/jack/apikeynativelib/EncryptUtil.java`
- [UI layout](https://github.com/xuningjack/apikeylib/blob/master/app/src/main/res/layout/activity_main.xml): android layout · Sample UI layout for signature testing · `app/src/main/res/layout/activity_main.xml`

## Connections

- Settings → Gradle build: includes · Registers modules in the Gradle build
- Gradle build → CMake: drives · Top-level build triggers native compilation
- CMake → JNI bridge: compiles · Builds the JNI/native entry point
- JNI bridge → MD5 core: uses · Delegates hashing to native MD5 code
- JNI bridge → String utils: uses · Relies on string normalization helpers
- JNI bridge → Base64: uses · Uses encoding utilities in native code
- JNI bridge → URL encode: uses · Uses URL encoding utilities in native code
- SignHelper → JNI bridge: calls native · Java API delegates sensitive work to JNI
- MainActivity → EncryptUtil: uses · UI invokes app-side wrapper methods
- EncryptUtil → SignHelper: calls · App wrapper calls the reusable library API
- MainActivity → UI layout: renders · Activity is backed by the sample layout
- App manifest → MainActivity: declares · Application entry component
- Lib manifest → SignHelper: exposes · Library package exports the public API surface
- EncryptUtil → JNI bridge: tests · Sample wrapper may exercise native signing behavior
