# radumarias/ciphershell-kotlin architecture

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

- Interactive diagram: https://gitdiagram.com/radumarias/ciphershell-kotlin
- Repository: https://github.com/radumarias/ciphershell-kotlin

## Overview

##### Project Type and Purpose
- This is a Kotlin Multiplatform GUI application (“ciphershell-kotlin”) that provides a desktop and Android front-end for the Rust-based `rencfs` encryption engine.
- It uses a small Java-bridge wrapper (in the `rencfsWrapper` module) to call into native Rust code, and Compose Multiplatform for UI, along with SQLDelight for local vault persistence.

##### High-Level Modules (Top-Level Components)
a. Native Engine
- Rust library (`rencfs`) compiled for multiple OS/ABI targets.
b. JNI/Java Bridge
- Module: `rencfsWrapper` — loads the Rust library via JNI and exposes Kotlin-friendly APIs.
c. Multiplatform Core
- Module: `rencfsMultiplatform`
- Contains common code:
– UI (`Compose` Composable screens, navigation, theme)
– Domain (use cases for vault creation, selection, walkthrough)
– Data layer (SQLDelight schema, DAO, repository)
– DI modules (platform-agnostic Koin/Dagger style setup)
d. Platform Hosts
- `rencfsAndroid` — Android application:
– AndroidManifest, Activities, resource files
– Platform DI (AndroidModule.kt)
– Platform-specific drivers (SQLDelight Android driver)
- `rencfsDesktop` — Desktop application (JVM):
– Main entrypoint, Window hosting Compose
– Platform DI (DesktopModule.kt)
– SQLDelight JDBC driver
e. Build Orchestration
- Root Gradle scripts, settings.gradle.kts, CI workflows

##### Component Relationships and Data Flows
- UI Layer (Compose screens in `commonMain`) emits user events (e.g., “Create vault”).
- Events route through navigation handlers to appropriate screen Composable.
- Composables call UseCase interfaces (e.g., `OnCreateVaultUseCaseImpl`).
- UseCases talk to the VaultRepository (common interface).
- For actual encryption I/O: VaultRepository calls into rencfsWrapper APIs (brown hexagon).
- The Rust engine reads/writes encrypted data on disk.
- Results bubble back through wrapper → repository → UseCase → UI, updating Compose UIState.

##### Architectural Patterns and Design Principles
- Clean separation of concerns: UI / Domain / Data / Native integration
- Dependency Injection (DI) modules per platform (`AndroidModule`, `DesktopModule`) plus common modules (`UIModule`, `VaultModule`, `SQLDelightModule`) for wiring.
- Single source of truth for UI state (unidirectional data flow in Compose).
- Kotlin Multiplatform: share business logic and UI definitions across Android and Desktop.
- SQLDelight: type-safe data layer with separate drivers per platform.
- JNI Bridge: clear boundary between managed Kotlin code and native Rust code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Platform Hosts
    AndroidApp["Android App<br/>(rencfsAndroid)"]:::module
    DesktopApp["Desktop App<br/>(rencfsDesktop)"]:::module

    %% Multiplatform Core
    subgraph "Multiplatform Core"
        UI["Compose UI"]:::module
        Domain["Domain / UseCases"]:::module
        Data["Data Layer"]:::module
        DI["Common DI Modules"]:::module
    end

    %% Infrastructure
    Wrapper["rencfsWrapper (JNI Bridge)"]:::hexagon
    Engine["rencfs (Rust Native Engine)"]:::rust
    DB[(SQLite Vault DB)]:::cylinder

    %% Build Orchestration
    Gradle[/Gradle/]:::module

    %% Connections
    AndroidApp -->|"start UI"| UI
    DesktopApp -->|"start UI"| UI
    UI -->|"invoke UseCase"| Domain
    Domain -->|"call VaultRepository"| Data
    Data -->|"read/write metadata"| DB
    Data -->|"encrypt/decrypt"| Wrapper
    Wrapper -->|"JNI call"| Engine
    Engine -->|"IO encrypted data"| DB

    Gradle -.-> AndroidApp
    Gradle -.-> DesktopApp
    Gradle -.-> UI
    Gradle -.-> Wrapper
    Gradle -.-> Engine

    %% Click Events
    click AndroidApp "https://github.com/radumarias/ciphershell-kotlin/tree/main/rencfsAndroid"
    click DesktopApp "https://github.com/radumarias/ciphershell-kotlin/tree/main/rencfsDesktop"
    click UI "https://github.com/radumarias/ciphershell-kotlin/blob/main/rencfsMultiplatform/src/commonMain/kotlin/rs/xor/rencfs/krencfs/RencfsComposeMainApp.kt"
    click Domain "https://github.com/radumarias/ciphershell-kotlin/tree/main/rencfsMultiplatform/src/commonMain/kotlin/rs/xor/rencfs/krencfs/domain"
    click Data "https://github.com/radumarias/ciphershell-kotlin/tree/main/rencfsMultiplatform/src/commonMain/kotlin/rs/xor/rencfs/krencfs/data/sqldelight"
    click DI "https://github.com/radumarias/ciphershell-kotlin/blob/main/rencfsMultiplatform/src/commonMain/kotlin/rs/xor/rencfs/krencfs/di/UIModule.kt"
    click Wrapper "https://github.com/radumarias/ciphershell-kotlin/tree/main/rencfsWrapper"
    click Engine "https://github.com/radumarias/ciphershell-kotlin/tree/main/rencfs"

    %% Styles
    classDef module fill:#add8e6,stroke:#333,stroke-width:1px
    classDef hexagon shape:hexagon,fill:#f5deb3,stroke:#333,stroke-width:1px
    classDef rust fill:#90ee90,stroke:#333,stroke-width:1px
    classDef cylinder shape:cylinder,fill:#fffacd,stroke:#333,stroke-width:1px
```
