# duxins/alog architecture

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

- Interactive diagram: https://gitdiagram.com/duxins/alog
- Repository: https://github.com/duxins/alog

## Overview

##### Main components of the system
- iOS Frontend:
- Primary application code under Sources/App (including AppDelegate, SceneDelegate, and various main views).
- Organized Modules in Sources/Modules (e.g., Recording, Export, Premium, Settings, Summary, Timeline). These likely follow an MVVM or MVC architecture.
- Components such as basic UI controls (located in Sources/Components) and styles (in Sources/Styles).
- Data modeling and persistence managed in Sources/DataModel (using Core Data, as indicated by the .xcdatamodeld files).
- Extensions in Sources/Extentions to enrich system libraries.
- Shared Library:
- Common utility classes such as Connectivity, Localization, notification names, and audio recording that reside in the Shared directory.
- Swift Packages:
- Packages/XLang and Packages/XLog hold reusable code libraries, which may provide localization and logging functionalities respectively.
- Server-Side Component:
- Server directory contains the Cloudflare Worker code (especially in Server/src/worker.js) and related configuration (prettier and package.json). This component handles API requests (including OpenAI API interactions and HMAC validations as described in the README).
- Companion Targets:
- Watch and WatchWidget folders that include separate codebases and assets to support the Apple Watch experience.
- Build and Deployment Tools:
- XCodeGen (driven by the project.yml and .arkana.yml) is used for project file generation.
- Fastlane folders and scripts for managing the build, tests, screenshots, and deployment pipelines.
- Environment/Configuration:
- .env file for environment variables, and additional config files (e.g., .github/workflows for CI).

##### Relationships and interactions
- The main iOS application communicates with external services via API calls to the deployed Cloudflare Worker. This worker handles requests that involve authentication (HMAC) and calls to OpenAI.
- The app uses shared libraries and Swift packages to modularize core features like localization (XLang) and logging (XLog), ensuring separation of concerns.
- The data layer managed via Core Data (Sources/DataModel) interacts with UI modules (in Sources/Modules) to display and modify user-generated notes or memos.
- Companion apps, like the Watch and WatchWidget, reuse portions of the primary business logic but tailor their interfaces to the watch-specific experience.
- Build-deployment tooling (XCodeGen and Fastlane) acts as an orchestration layer that ties together generation, testing, and releasing steps.

##### Architectural patterns and design principles
- Use of layered architecture – clear separation between:
- Presentation/UI (Views, Components, Modules)
- Business Logic/Services (under Sources/Services such as AudioPlayer, OpenAI, Transcription)
- Data Model (Core Data and extensions)
- Modularity through Swift packages and shared utilities promotes code reuse and maintainability.
- The server-side is treated as a remote microservice (Cloudflare Worker), emphasizing low-coupling between the client app and backend API.
- Deployment pipelines with CI (GitHub workflows) and Fastlane scripts further underline a modern, automated development lifecycle.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% iOS Frontend Subgraph
    subgraph "iOS Frontend"
        A["Application Code"]:::frontend
        M["Modules"]:::frontend
        U["UI Components"]:::frontend
        D["Data Model"]:::frontend
        E["Extensions"]:::frontend
    end

    %% Shared Libraries & Swift Packages Subgraph
    subgraph "Shared & Swift Packages"
        SLib["Shared Library"]:::shared
        XLang["Swift Package (XLang)"]:::package
        XLog["Swift Package (XLog)"]:::package
    end

    %% Services Layer
    SLayer["Services Layer"]:::service

    %% Server-Side Component
    Server["Cloudflare Worker Server"]:::server

    %% Companion Apps Subgraph
    subgraph "Companion Apps"
        Watch["Apple Watch"]:::frontend
        WatchWidget["Watch Widget"]:::frontend
    end

    %% Build/Deployment Tools Subgraph
    subgraph "Build/Deployment Tools"
        XCodeGen["Project Generation"]:::build
        Fastlane["Automation Scripts (Fastlane)"]:::build
        Env["Env Config (.env.example)"]:::build
    end

    %% Connections between iOS Frontend components
    %% Application Code uses Shared Library
    A -->|"uses"| SLib
    %% Modules calls Services Layer for API interactions
    M -->|"callsAPI"| SLayer
    %% UI Components present data from Data Model
    U -->|"presentsData"| D

    %% Services Layer dependencies on Shared & Swift Packages
    SLayer -->|"dependsOn"| SLib
    SLayer -->|"dependsOn"| XLang
    SLayer -->|"dependsOn"| XLog

    %% Services Layer communicates with Cloudflare Worker Server
    SLayer -->|"callsAPI"| Server

    %% Companion Apps share common logic from Modules (implicitly)
    M -->|"sharedLogic"| Watch
    M -->|"sharedLogic"| WatchWidget

    %% Build/Deployment Tools interactions
    XCodeGen -->|"generates"| A
    XCodeGen -->|"generates"| Server
    Fastlane -->|"automates"| A
    Fastlane -->|"automates"| Server
    Env -->|"configures"| XCodeGen
    Env -->|"configures"| Fastlane

    %% Click Events
    click A "https://github.com/duxins/alog/tree/release/v0.3.1/Sources/App"
    click M "https://github.com/duxins/alog/tree/release/v0.3.1/Sources/Modules"
    click U "https://github.com/duxins/alog/tree/release/v0.3.1/Sources/Components"
    click D "https://github.com/duxins/alog/tree/release/v0.3.1/Sources/DataModel"
    click E "https://github.com/duxins/alog/tree/release/v0.3.1/Sources/Extentions"
    click SLayer "https://github.com/duxins/alog/tree/release/v0.3.1/Sources/Services"
    click SLib "https://github.com/duxins/alog/tree/release/v0.3.1/Shared"
    click XLang "https://github.com/duxins/alog/tree/release/v0.3.1/Packages/XLang"
    click XLog "https://github.com/duxins/alog/tree/release/v0.3.1/Packages/XLog"
    click Server "https://github.com/duxins/alog/blob/release/v0.3.1/Server/src/worker.js"
    click Watch "https://github.com/duxins/alog/tree/release/v0.3.1/Watch"
    click WatchWidget "https://github.com/duxins/alog/tree/release/v0.3.1/WatchWidget"
    click XCodeGen "https://github.com/duxins/alog/blob/release/v0.3.1/.arkana.yml"
    click Fastlane "https://github.com/duxins/alog/tree/release/v0.3.1/fastlane"
    click Env "https://github.com/duxins/alog/blob/release/v0.3.1/.env.example"

    %% Class definitions for colors and styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef shared fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef service fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef server fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef package fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef build fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
