# iktakahiro/fargon2 architecture

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

- Interactive diagram: https://gitdiagram.com/iktakahiro/fargon2
- Repository: https://github.com/iktakahiro/fargon2

## Overview

1. **What this repository is**
   - `fargon2` is a Flutter plugin package, not a standalone app.
   - Its purpose is to expose Argon2 password hashing to Dart code while executing the actual hashing natively on Android and iOS.

2. **Public API boundary**
   - The main package surface is `lib/fargon2.dart`.
   - That Dart layer is the only code consumers are meant to call directly; the README example shows creating a `Fargon2` instance and calling `hash(...)`.

3. **Cross-platform execution model**
   - The architecture is split into three layers:
     - Dart API in Flutter
     - Native platform plugin code
     - Platform-specific hashing implementation
   - Data flows from Dart inputs such as passphrase, salt, mode, and tuning parameters into native code, and the computed hash string returns back to Dart.

4. **Android subsystem**
   - Android implementation lives under `android/`.
   - The plugin entrypoint is `android/src/main/kotlin/dev/iktakahiro/fargon2/Fargon2Plugin.kt`.
   - This is the Android boundary where Flutter method calls are received and forwarded into the native hashing logic.

5. **iOS subsystem**
   - iOS implementation lives under `ios/`.
   - The plugin code is split across `ios/Classes/Fargon2Plugin.h`, `ios/Classes/Fargon2Plugin.m`, and `ios/Classes/SwiftFargon2Plugin.swift`.
   - This suggests an iOS plugin boundary with a Swift implementation plus Objective-C compatibility/registration glue.

6. **Hashing domain**
   - The core domain concept is Argon2 hashing, with support for the Argon2 variants mentioned in the README: `argon2id`, `argon2i`, and `argon2d`.
   - The plugin accepts Argon2 cost parameters such as hash length, iterations, parallelism, and memory size, which are central to the runtime behavior and output.

7. **Platform-native dependency boundary**
   - The repository is a wrapper around platform-native Argon2-capable libraries rather than implementing the algorithm entirely in Dart.
   - The README credits `CatCrypto` and `argon2kt`, indicating the real hashing work is delegated to native dependencies or their equivalents under the hood.

8. **Example application**
   - `example/` is a full Flutter app used to demonstrate and validate the plugin on both platforms.
   - It contains its own Android and iOS host projects plus `example/lib/main.dart` and a widget test, so it serves as the integration reference for consumers.

9. **Testing and CI**
   - Repository-level tests live in `test/fargon2_test.dart`.
   - GitHub Actions workflow `/.github/workflows/test.yaml` runs Flutter tests, making the CI boundary focused on package validation rather than deployment.

10. **Build and packaging structure**
   - `pubspec.yaml`, `analysis_options.yaml`, and `.fvm/fvm_config.json` define the Dart/Flutter toolchain and style constraints.
   - Android and iOS subprojects are configured as plugin host builds, with Gradle and CocoaPods metadata present in each platform folder.

11. **Platform integration details**
   - The plugin is packaged for Android with Gradle files and an `AndroidManifest.xml`, and for iOS with a `.podspec`, Xcode project files, and Flutter xcconfig assets.
   - This is the standard Flutter plugin layout for shipping one Dart package with two native implementations.

12. **Operationally important diagram view**
   - If you draw the architecture, the main arrow should be: Flutter app code → `fargon2` Dart API → Android/iOS plugin layer → Argon2 native implementation → hashed result back to Dart.
   - The example app is a separate consumer of that same path, and CI/test files validate the package boundary.

Main entry points: [`lib/fargon2.dart`](https://github.com/iktakahiro/fargon2/blob/main/lib/fargon2.dart) (Fargon2 API), [`android/src/main/kotlin/dev/iktakahiro/fargon2/Fargon2Plugin.kt`](https://github.com/iktakahiro/fargon2/blob/main/android/src/main/kotlin/dev/iktakahiro/fargon2/Fargon2Plugin.kt) (Android bridge), [`ios/Classes/SwiftFargon2Plugin.swift`](https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/SwiftFargon2Plugin.swift) (iOS bridge), [`ios/Classes/Fargon2Plugin.m`](https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/Fargon2Plugin.m) (iOS glue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_dart["Dart package"]
  node_n_pub_api["Fargon2 API<br/>flutter API<br/>[fargon2.dart]"]
  node_n_pubspec["Package spec<br/>package metadata<br/>[pubspec.yaml]"]
  node_n_readme["README<br/>usage docs<br/>[README.md]"]
end

subgraph group_grp_android["Android plugin"]
  node_n_android_plugin["Android bridge<br/>method-channel plugin<br/>[Fargon2Plugin.kt]"]
  node_n_android_manifest["Android manifest<br/>plugin manifest"]
  node_n_android_gradle["Android build<br/>gradle config<br/>[build.gradle]"]
end

subgraph group_grp_ios["iOS plugin"]
  node_n_ios_swift["iOS bridge<br/>swift plugin"]
  node_n_ios_objc["iOS glue<br/>objc bridge<br/>[Fargon2Plugin.m]"]
  node_n_ios_header["iOS header<br/>objc header<br/>[Fargon2Plugin.h]"]
  node_n_ios_podspec["Podspec<br/>cocoapods config<br/>[fargon2.podspec]"]
end

subgraph group_grp_example["Example app"]
  node_n_example_main["Example app<br/>flutter app<br/>[main.dart]"]
  node_n_example_android["Example Android<br/>host app<br/>[build.gradle]"]
  node_n_example_ios["Example iOS<br/>host app"]
  node_n_example_android_main["MainActivity<br/>android host<br/>[MainActivity.kt]"]
  node_n_example_ios_app["AppDelegate<br/>ios host<br/>[AppDelegate.swift]"]
end

subgraph group_grp_quality["Quality and release"]
  node_n_tests["Package tests<br/>dart tests<br/>[fargon2_test.dart]"]
  node_n_ci["CI workflow<br/>github actions<br/>[test.yaml]"]
  node_n_tooling["Tooling<br/>dart/flutter config"]
end

node_n_readme -->|"documents"| node_n_pub_api
node_n_pubspec -->|"exposes"| node_n_pub_api
node_n_pub_api -->|"calls"| node_n_android_plugin
node_n_pub_api -->|"calls"| node_n_ios_swift
node_n_android_plugin -->|"registered by"| node_n_android_manifest
node_n_android_plugin -->|"built with"| node_n_android_gradle
node_n_android_plugin -.->|"returns hash"| node_n_pub_api
node_n_ios_swift -->|"bridged by"| node_n_ios_objc
node_n_ios_objc -->|"declares"| node_n_ios_header
node_n_ios_swift -->|"packaged by"| node_n_ios_podspec
node_n_ios_swift -.->|"returns hash"| node_n_pub_api
node_n_example_main -->|"uses"| node_n_pub_api
node_n_example_android_main -->|"hosts"| node_n_android_plugin
node_n_example_ios_app -->|"hosts"| node_n_ios_swift
node_n_example_android -->|"builds"| node_n_example_android_main
node_n_example_ios -->|"builds"| node_n_example_ios_app
node_n_tests -->|"validates"| node_n_pub_api
node_n_ci -->|"runs"| node_n_tests
node_n_tooling -.->|"constrains"| node_n_pub_api

click node_n_pub_api "https://github.com/iktakahiro/fargon2/blob/main/lib/fargon2.dart"
click node_n_pubspec "https://github.com/iktakahiro/fargon2/blob/main/pubspec.yaml"
click node_n_readme "https://github.com/iktakahiro/fargon2/blob/main/README.md"
click node_n_android_plugin "https://github.com/iktakahiro/fargon2/blob/main/android/src/main/kotlin/dev/iktakahiro/fargon2/Fargon2Plugin.kt"
click node_n_android_manifest "https://github.com/iktakahiro/fargon2/blob/main/android/src/main/AndroidManifest.xml"
click node_n_android_gradle "https://github.com/iktakahiro/fargon2/blob/main/android/build.gradle"
click node_n_ios_swift "https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/SwiftFargon2Plugin.swift"
click node_n_ios_objc "https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/Fargon2Plugin.m"
click node_n_ios_header "https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/Fargon2Plugin.h"
click node_n_ios_podspec "https://github.com/iktakahiro/fargon2/blob/main/ios/fargon2.podspec"
click node_n_example_main "https://github.com/iktakahiro/fargon2/blob/main/example/lib/main.dart"
click node_n_example_android "https://github.com/iktakahiro/fargon2/blob/main/example/android/app/build.gradle"
click node_n_example_ios "https://github.com/iktakahiro/fargon2/tree/main/example/ios/Podfile"
click node_n_example_android_main "https://github.com/iktakahiro/fargon2/blob/main/example/android/app/src/main/kotlin/dev/iktakahiro/fargon2_example/MainActivity.kt"
click node_n_example_ios_app "https://github.com/iktakahiro/fargon2/blob/main/example/ios/Runner/AppDelegate.swift"
click node_n_tests "https://github.com/iktakahiro/fargon2/blob/main/test/fargon2_test.dart"
click node_n_ci "https://github.com/iktakahiro/fargon2/blob/main/.github/workflows/test.yaml"
click node_n_tooling "https://github.com/iktakahiro/fargon2/blob/main/analysis_options.yaml"

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_n_pub_api,node_n_pubspec,node_n_readme toneBlue
class node_n_android_plugin,node_n_android_manifest,node_n_android_gradle toneAmber
class node_n_ios_swift,node_n_ios_objc,node_n_ios_header,node_n_ios_podspec toneMint
class node_n_example_main,node_n_example_android,node_n_example_ios,node_n_example_android_main,node_n_example_ios_app toneRose
class node_n_tests,node_n_ci,node_n_tooling toneIndigo
```

## Components

### Dart package

Public Flutter-facing API and package metadata

- [Fargon2 API](https://github.com/iktakahiro/fargon2/blob/main/lib/fargon2.dart): flutter API · Main Dart entrypoint exposed to consumers · `lib/fargon2.dart`
- [Package spec](https://github.com/iktakahiro/fargon2/blob/main/pubspec.yaml): package metadata · Flutter plugin package declaration and dependency wiring · `pubspec.yaml`
- [README](https://github.com/iktakahiro/fargon2/blob/main/README.md): usage docs · Public usage examples and platform notes · `README.md`

### Android plugin

Android host integration and native bridge

- [Android bridge](https://github.com/iktakahiro/fargon2/blob/main/android/src/main/kotlin/dev/iktakahiro/fargon2/Fargon2Plugin.kt): method-channel plugin · Receives Flutter calls on Android and forwards them natively · `android/src/main/kotlin/dev/iktakahiro/fargon2/Fargon2Plugin.kt`
- [Android manifest](https://github.com/iktakahiro/fargon2/blob/main/android/src/main/AndroidManifest.xml): plugin manifest · Android plugin registration and host metadata · `android/src/main/AndroidManifest.xml`
- [Android build](https://github.com/iktakahiro/fargon2/blob/main/android/build.gradle): gradle config · Android plugin build and packaging configuration · `android/build.gradle`

### iOS plugin

iOS host integration and native bridge

- [iOS bridge](https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/SwiftFargon2Plugin.swift): swift plugin · Swift-side Flutter plugin implementation · `ios/Classes/SwiftFargon2Plugin.swift`
- [iOS glue](https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/Fargon2Plugin.m): objc bridge · Objective-C registration and compatibility layer · `ios/Classes/Fargon2Plugin.m`
- [iOS header](https://github.com/iktakahiro/fargon2/blob/main/ios/Classes/Fargon2Plugin.h): objc header · Public native interface for the iOS plugin target · `ios/Classes/Fargon2Plugin.h`
- [Podspec](https://github.com/iktakahiro/fargon2/blob/main/ios/fargon2.podspec): cocoapods config · iOS plugin packaging and dependency metadata · `ios/fargon2.podspec`

### Example app

Integration sample that exercises the plugin

- [Example app](https://github.com/iktakahiro/fargon2/blob/main/example/lib/main.dart): flutter app · Sample consumer app demonstrating plugin use · `example/lib/main.dart`
- [Example Android](https://github.com/iktakahiro/fargon2/blob/main/example/android/app/build.gradle): host app · Android host project for the sample app · `example/android/app/build.gradle`
- [Example iOS](https://github.com/iktakahiro/fargon2/tree/main/example/ios/Podfile): host app · iOS host project for the sample app · `example/ios/Podfile`
- [MainActivity](https://github.com/iktakahiro/fargon2/blob/main/example/android/app/src/main/kotlin/dev/iktakahiro/fargon2_example/MainActivity.kt): android host · Android launcher activity for the sample · `example/android/app/src/main/kotlin/dev/iktakahiro/fargon2_example/MainActivity.kt`
- [AppDelegate](https://github.com/iktakahiro/fargon2/blob/main/example/ios/Runner/AppDelegate.swift): ios host · iOS application delegate for the sample · `example/ios/Runner/AppDelegate.swift`

### Quality and release

Tests, CI, and toolchain configuration

- [Package tests](https://github.com/iktakahiro/fargon2/blob/main/test/fargon2_test.dart): dart tests · Repository-level validation of the Dart surface · `test/fargon2_test.dart`
- [CI workflow](https://github.com/iktakahiro/fargon2/blob/main/.github/workflows/test.yaml): github actions · Automated Flutter test execution on push/PR · `.github/workflows/test.yaml`
- [Tooling](https://github.com/iktakahiro/fargon2/blob/main/analysis_options.yaml): dart/flutter config · Analyzer, Flutter version, and package tooling constraints · `analysis_options.yaml`

## Connections

- README → Fargon2 API: documents · README shows the intended consumer-facing API
- Package spec → Fargon2 API: exposes · Package metadata publishes the Dart entrypoint
- Fargon2 API → Android bridge: calls · Dart API forwards hashing requests to Android
- Fargon2 API → iOS bridge: calls · Dart API forwards hashing requests to iOS
- Android bridge → Android manifest: registered by · Android plugin is surfaced through the platform manifest
- Android bridge → Android build: built with · Android bridge is packaged by the Gradle plugin build
- Android bridge → Fargon2 API: returns hash · Native result flows back through the Dart boundary
- iOS bridge → iOS glue: bridged by · Swift plugin is exposed through Objective-C glue
- iOS glue → iOS header: declares · Objective-C layer exposes the native plugin interface
- iOS bridge → Podspec: packaged by · iOS bridge is distributed as a CocoaPods plugin
- iOS bridge → Fargon2 API: returns hash · Native result flows back through the Dart boundary
- Example app → Fargon2 API: uses · Sample app consumes the public Dart API
- MainActivity → Android bridge: hosts · Example Android app loads the Android plugin path
- AppDelegate → iOS bridge: hosts · Example iOS app loads the iOS plugin path
- Example Android → MainActivity: builds · Android sample project builds the launcher activity
- Example iOS → AppDelegate: builds · iOS sample project builds the app delegate
- Package tests → Fargon2 API: validates · Repository tests exercise the Dart API boundary
- CI workflow → Package tests: runs · GitHub Actions executes the test suite
- Tooling → Fargon2 API: constrains · Analyzer and Flutter tool versions shape the package surface
