# trosydman/realstation architecture

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

- Interactive diagram: https://gitdiagram.com/trosydman/realstation
- Repository: https://github.com/trosydman/realstation

## Overview

##### Project Type & Purpose
- The RealStation project is an Android mobile app built using 100% Kotlin and Jetpack Compose.
- Its purpose is to display a list of real estate items fetched from a remote endpoint. When a user selects an item, the app navigates to a details screen showing more information.
- The architecture is based on the MVI (Model-View-Intent) pattern combined with UDF (Unidirectional Data Flow) and follows additional principles like CLEAN, SOLID, and the Repository pattern.

##### Analyzing the File Structure
- The project is structured into several layers:
- The “ui” package contains all the presentation components (composables, screens, view models for list and details, navigation, theme).
- The “domain” package includes interfaces (such as the repository abstraction) and domain models, plus mapping utilities under “utils.”
- The “data” package implements data retrieval through RealStateRepositoryImpl, defines remote models in “remote/model,” and manages dependency injection (DI) through DataModule.
- Additional directories such as “extensions” and “utils” provide utility functions and coroutine dispatchers.
- Dependency management is handled using Gradle with a TOML file for version catalogs, while Hilt is used for Dependency Injection.

##### Main Components to be Represented
a. Presentation/UI Layer:
- MainActivity: The single-activity entry point.
- RealStateListScreen: Displays the list of real estate listings.
- RealStateDetailsScreen: Shows detailed information when an item is selected.
- ViewModels: RealStateListViewModel and RealStateDetailsViewModel that manage UI state (RealStateListUIState and RealStateDetailsUIState) through MVI + UDF.
- Composable components and Material Design theming (with separate design for light and dark themes).

b. Domain Layer:
- RealStateRepository interface: Defines the contract for data operations.
- Domain models (e.g., RealState) and mappers that convert between data and UI models (via DomainMapper and UIMapper).

c. Data Layer:
- RealStateRepositoryImpl: Implements data retrieval logic.
- Remote layers include:
- AvivAPI: Retrofit interface to consume the external JSON endpoint.
- NetworkConnectionInterceptor: Handles network call changes.
- DTOs and corresponding mappers (RealStateDTO, RealStateDTOMapper, RealStateListDTO, RealStateListDTOMapper) that convert network responses to usable data models.

d. Dependency Injection (DI):
- Modules in “data/di” (DataModule) and “ui/di” (UIModule) to inject required dependencies (repository, API client, coroutine dispatchers, etc.).

e. Utility Components:
- Extensions (e.g., BigDecimalX) and additional modules within “utils” for resources and coroutine dispatchers.

##### Relationships and Interactions
- UI components (screens and view models) retrieve data by calling methods on the domain layer through the injected RealStateRepository.
- The domain layer abstracts the underlying implementation which, in the data layer, calls the AvivAPI with Retrofit.
- Dependency injection modules supply the concrete implementations for the repository, network clients, and coroutine dispatchers to both the UI and data layers.

##### Architectural Patterns & Design Principles
- The use of MVI alongside UDF for managing UI state and events.
- Repository pattern that abstracts data fetching.
- Single-Activity pattern with composable screens.
- Clean architecture separation between UI, Domain, and Data layers.
- SOLID principles ensuring each component has a distinct responsibility.

## Diagram (Mermaid)

```mermaid
graph TD
  %% UI Layer
  subgraph "UI Layer"
    A["MainActivity"]:::ui
    B["RealStateListScreen"]:::ui
    C["RealStateDetailsScreen"]:::ui
    D["RealStateListViewModel"]:::ui
    E["RealStateDetailsViewModel"]:::ui
    F["Composable Components"]:::ui
    G["Theme & Material Design"]:::ui
  end

  %% Domain Layer
  subgraph "Domain Layer"
    H["RealStateRepository (Interface)"]:::domain
    I["RealState (Domain Model)"]:::domain
    J["Domain Mappers (DomainMapper & UIMapper)"]:::domain
  end

  %% Data Layer
  subgraph "Data Layer"
    K["RealStateRepositoryImpl"]:::data
    L["AvivAPI"]:::dataCyl
    M["NetworkConnectionInterceptor"]:::data
    N["RealStateDTO"]:::data
    O["RealStateDTOMapper"]:::data
    P["RealStateListDTO"]:::data
    Q["RealStateListDTOMapper"]:::data
  end

  %% Dependency Injection
  subgraph "Dependency Injection"
    R["DataModule"]:::di
    S["UIModule"]:::di
  end

  %% Utilities
  subgraph "Utilities"
    T["Extension Functions (BigDecimalX)"]:::utils
    U["App Utilities (Resources & Dispatchers)"]:::utils
  end

  %% UI Flow Connections
  A -->|"launches"| B
  A -->|"launches"| C
  B -->|"triggers"| D
  C -->|"triggers"| E

  %% ViewModel to Domain
  D -->|"fetchData"| H
  E -->|"fetchData"| H

  %% Domain Implementation Flow
  H -->|"implemented_by"| K

  %% Data Layer interactions
  K -->|"calls"| L
  K -->|"calls"| M
  L -->|"mappedBy"| O
  L -->|"mappedBy"| Q
  O -->|"converts_to"| J
  Q -->|"converts_to"| J
  J -->|"produces"| I
  I -->|"updates_UI"| D
  I -->|"updates_UI"| E

  %% Dependency Injection Provision
  R --> K
  S --> D
  S --> E

  %% Utilities support (indicative)
  U --> A
  T --> K

  %% Class Definitions with Colors
  classDef ui fill:#CDEBFF,stroke:#2B70F5,stroke-width:2px;
  classDef domain fill:#E2FFD9,stroke:#37A52B,stroke-width:2px;
  classDef data fill:#FFF7CD,stroke:#E2A200,stroke-width:2px;
  classDef dataCyl fill:#FFF7CD,stroke:#E2A200,stroke-width:2px,stroke-dasharray: 5 5;
  classDef di fill:#FEE2E2,stroke:#D93A3A,stroke-width:2px;
  classDef utils fill:#F3D1F4,stroke:#A832A6,stroke-width:2px;

  %% Click Events
  click A "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/MainActivity.kt"
  click B "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/ui/list/RealStateListScreen.kt"
  click C "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/ui/details/RealStateDetailsScreen.kt"
  click D "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/ui/list/RealStateListViewModel.kt"
  click E "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/ui/details/RealStateDetailsViewModel.kt"
  click F "https://github.com/trosydman/realstation/tree/main/app/src/main/kotlin/com/cmesquita/realstation/ui/components/"
  click G "https://github.com/trosydman/realstation/tree/main/app/src/main/kotlin/com/cmesquita/realstation/ui/theme/"
  click H "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/domain/RealStateRepository.kt"
  click I "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/domain/model/RealState.kt"
  click J "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/domain/utils/DomainMapper.kt"
  click K "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/RealStateRepositoryImpl.kt"
  click L "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/remote/AvivAPI.kt"
  click M "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/remote/NetworkConnectionInterceptor.kt"
  click N "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/remote/model/RealStateDTO.kt"
  click O "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/remote/model/RealStateDTOMapper.kt"
  click P "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/remote/model/RealStateListDTO.kt"
  click Q "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/remote/model/RealStateListDTOMapper.kt"
  click R "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/data/di/DataModule.kt"
  click S "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/ui/di/UIModule.kt"
  click T "https://github.com/trosydman/realstation/blob/main/app/src/main/kotlin/com/cmesquita/realstation/extensions/BigDecimalX.kt"
  click U "https://github.com/trosydman/realstation/tree/main/app/src/main/kotlin/com/cmesquita/realstation/utils/"
```
