# vitorpamplona/amethyst architecture

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

- Interactive diagram: https://gitdiagram.com/vitorpamplona/amethyst
- Repository: https://github.com/vitorpamplona/amethyst

## Overview

##### Main Architectural Components
- User Interface Layer: Represent the Amethyst app’s UI built using Jetpack Compose along with Android Activity/Fragment components.
- Repository/Model Layer: Show components that store and manage “Notes” (events) and “User” objects in an in-memory persistent repository. These classes also use observable patterns to update viewmodels as events come in.
- Service/Network Layer: Illustrate the service layer responsible for assembling Nostr filters, keeping persistent connections to Nostr relays, and transferring events from the network to the repository.
- Key Management/Security: Include the component that interacts with the Android KeyStore to securely store the user’s private and public keys.
- Additional Modules: Optionally represent “ammolite” (for relay management and possibly a lighter client component), “commons” (for shared utilities), and “benchmark” (for performance testing) as supplementary blocks which interact with the overall system.

##### Relationships and Communication
- Optionally, connect “ammolite” with the network/relay stack to indicate its role in relay communications.

##### Architectural Patterns and Design Principles
- Separation of concerns by grouping components into boundaries such as UI, Domain/Repository, and Network/Service.
- MVVM/reactive data flow by showing how ViewModels subscribe to updates from the Repository.

##### Key Technologies/Frameworks
- That the platform is Android running on Java 17+ and Kotlin.
- Use of LiveData/Flow for reactive state updates.
- Integration with Android KeyStore for secure key management.
- Mention of Gradle as the build and dependency management system.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    UI["User Interface Layer (Jetpack Compose)"]:::ui

    %% MVVM Layer
    VM["ViewModel and State Management (MVVM, LiveData/Flow)"]:::mvvm

    %% Domain/Repository Layer
    REP["Repository/Model Layer (Notes, Users)"]:::repo

    %% Network/Service Layer
    SER["Service/Network Layer (WebSocket, Relay Connections)"]:::net
    QUA["Quartz Library (Nostr Protocol Logic)"]:::lib
    AMM["Ammolite (Relay Management)"]:::extra

    %% Security and Key Management
    KEY["Key Management/Security (Android KeyStore)"]:::sec

    %% Data Flow
    UI -->|"triggers"| VM
    VM -->|"updates"| REP
    REP -->|"pushes_events"| SER
    SER -->|"streams_events"| REP
    SER -->|"protocol_parsing"| QUA
    AMM -->|"relay_support"| SER

    %% Key Management influence
    KEY -->|"sign/verify"| REP
    KEY -->|"auth_keys"| SER

    %% Click Events
    click UI "https://github.com/vitorpamplona/amethyst/tree/main/amethyst/src/main/java/com/vitorpamplona/amethyst/ui"
    click VM "https://github.com/vitorpamplona/amethyst/tree/main/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen"
    click REP "https://github.com/vitorpamplona/amethyst/tree/main/amethyst/src/main/java/com/vitorpamplona/amethyst/model"
    click SER "https://github.com/vitorpamplona/amethyst/tree/main/amethyst/src/main/java/com/vitorpamplona/amethyst/service"
    click QUA "https://github.com/vitorpamplona/amethyst/tree/main/quartz/"
    click KEY "https://github.com/vitorpamplona/amethyst/blob/main/amethyst/src/main/java/com/vitorpamplona/amethyst/EncryptedStorage.kt"
    click AMM "https://github.com/vitorpamplona/amethyst/tree/main/ammolite/"

    %% Styles
    classDef ui fill:#FFCCCC,stroke:#CC0000,stroke-width:2px,color:#000
    classDef mvvm fill:#CCFFCC,stroke:#009900,stroke-width:2px,color:#000
    classDef repo fill:#CCCCFF,stroke:#0000CC,stroke-width:2px,color:#000
    classDef net fill:#FFFFCC,stroke:#CCCC00,stroke-width:2px,color:#000
    classDef lib fill:#CCFFFF,stroke:#009999,stroke-width:2px,color:#000
    classDef sec fill:#FFEECC,stroke:#CC6600,stroke-width:2px,color:#000
    classDef extra fill:#FFEEDD,stroke:#CC3300,stroke-width:2px,color:#000
```
