# ironmanyg/echojournal architecture

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

- Interactive diagram: https://gitdiagram.com/ironmanyg/echojournal
- Repository: https://github.com/ironmanyg/echojournal

## Overview

##### Main components
- User Interface / Presentation Layer:
- Composed mostly of Jetpack Compose UI screens and components (e.g., SplashScreen, Entries Screen, Create Record Screen, etc.)
- Navigation components (root, journal screens, entry screens)
- Custom design system including themed components, Chip, FAB, TopAppBar, and other custom widgets.
- Domain Layer:
- Contains business logic such as AudioLog, Mood, AudioPlayer, AudioRecorder, and various domain models.
- Holds use cases and state management classes for MVI (such as ViewModels, Events, and States).
- Data Layer:
- Repositories and data sources that abstract out local database access and data mappers.
- Local data sources (Room database with DAOs, entities, and data mappers).
- Dependency injection modules for data (e.g., CoreDataModule and DatabaseModule).
- Infrastructure / Framework Integrations:
- Integration of native Android tools like MediaRecorder and MediaPlayer for recording and playback.
- External libraries such as Kotlin Coroutines, Flow, and Timber for logging.
- Configuration and Build:
- Gradle files and build scripts illustrating the project’s dependency management.
- Environment configuration files (.gitignore, gradle.properties, etc.)

##### Relationships and interactions
- The Presentation layer (UI screens and Compose components) sends user intents to ViewModels.
- The ViewModels interact with the Domain layer, which handles business logic and state.
- Domain calls into repositories defined in the Data layer which handle data operations either from local data sources (Room database) or potentially remote (future expansion).
- The Data layer uses DAOs and mappers to convert between entities and domain models.
- Dependency injection (set up via Koin) binds these layers together and manages lifecycle dependencies.
- User actions such as recording or playing audio trigger native Android services (MediaRecorder/MediaPlayer).

##### Important architectural patterns and design principles
- MVI (Model-View-Intent): Ensures a unidirectional data flow, making state management predictable and easier to debug.
- Repository Pattern: Abstracts the data sources from the domain logic, making switching between local and remote sources smoother.
- Separation of Concerns: Clear division between UI (presentation), domain (business logic), and data (storage/access).
- Single Module MVP: Although simple now, the current architecture enables a smoother transition to a multi-module structure if necessary in the future.

##### Relevant technologies and frameworks
- Kotlin and Jetpack Compose for application development.
- Android Architecture Components (like ViewModel, StateFlow, and Navigation Compose).
- Room for local database operations.
- Koin for dependency injection.
- Media APIs (MediaRecorder and MediaPlayer) for audio capabilities.

- In the Presentation layer, include components such as UI screens, Composable functions, and Navigation.
- In the Domain layer, outline business models, use cases, and ViewModels along with the MVI pattern components like Events and States.

##### Additional detailed notes
- Though the project is single-module, clearly delineate layered responsibilities to aid any future scalability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI1["UI Screens & Navigation"]:::presentation
        UI2["Jetpack Compose UI & Custom Widgets"]:::presentation
        UI3["Journal Entries & Entry Screens"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DM1["Business Models & Use Cases"]:::domain
        DM2["ViewModels & MVI Components"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        DL1["Repositories & Data Sources"]:::data
        DL2["Local Database & DAOs"]:::data
        DL3["Data Mappers"]:::data
    end

    %% Dependency Injection
    subgraph "Dependency Injection"
        DI1["Core & Database DI Modules"]:::di
        DI2["App & Feature DI Modules"]:::di
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        INF1["Audio Recording & Playback Integration"]:::infra
    end

    %% Configuration & Build
    subgraph "Configuration & Build"
        CFG1["Gradle & Build Scripts"]:::config
        CFG2["Environment & Version Files"]:::config
    end

    %% Flow connections
    UI1 -->|"sendsIntents"| UI3
    UI3 -->|"triggers"| DM2
    DM2 -->|"executesLogic"| DM1
    DM2 -->|"callsRepository"| DL1
    DL1 -->|"queries"| DL2
    DL1 -->|"mapsDataWith"| DL3
    DM1 -->|"utilizes"| INF1

    %% Dependency Injection connections
    DI1 -->|"injectsInto"| DM2
    DI1 -->|"injectsInto"| DL1
    DI2 -->|"injectsInto"| UI1

    %% Configuration connections
    CFG1 -->|"configures"| DI1
    CFG1 -->|"configures"| DI2
    CFG2 -->|"supports"| CFG1

    %% Styles
    classDef presentation fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef domain fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef data fill:#cce5ff,stroke:#003399,stroke-width:2px;
    classDef di fill:#e6ccff,stroke:#6600cc,stroke-width:2px;
    classDef infra fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef config fill:#d9d9d9,stroke:#333333,stroke-width:2px;

    %% Click Events
    click UI1 "https://github.com/ironmanyg/echojournal/blob/master/app/src/main/java/dev/gaddal/echojournal/core/presentation/ui/navigation/JournalNavGraph.kt"
    click UI2 "https://github.com/ironmanyg/echojournal/tree/master/app/src/main/java/dev/gaddal/echojournal/core/presentation/designsystem"
    click UI3 "https://github.com/ironmanyg/echojournal/blob/master/app/src/main/java/dev/gaddal/echojournal/journal/entries/EntriesScreen.kt"

    click DM1 "https://github.com/ironmanyg/echojournal/tree/master/app/src/main/java/dev/gaddal/echojournal/core/domain"
    click DM2 "https://github.com/ironmanyg/echojournal/blob/master/app/src/main/java/dev/gaddal/echojournal/journal/entries/EntriesViewModel.kt"

    click DL1 "https://github.com/ironmanyg/echojournal/tree/master/app/src/main/java/dev/gaddal/echojournal/core/data"
    click DL2 "https://github.com/ironmanyg/echojournal/tree/master/app/src/main/java/dev/gaddal/echojournal/core/database"
    click DL3 "https://github.com/ironmanyg/echojournal/tree/master/app/src/main/java/dev/gaddal/echojournal/core/database/mappers"

    click DI1 "https://github.com/ironmanyg/echojournal/blob/master/app/src/main/java/dev/gaddal/echojournal/core/data/di/CoreDataModule.kt"
    click DI2 "https://github.com/ironmanyg/echojournal/blob/master/app/src/main/java/dev/gaddal/echojournal/di/AppModule.kt"

    click INF1 "https://github.com/ironmanyg/echojournal/tree/master/app/src/main/java/dev/gaddal/echojournal/core/domain/playback"

    click CFG1 "https://github.com/ironmanyg/echojournal/blob/master/build.gradle.kts"
    click CFG2 "https://github.com/ironmanyg/echojournal/blob/master/.gitignore"
```
