# tamersarioglu/kykscraped architecture

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

- Interactive diagram: https://gitdiagram.com/tamersarioglu/kykscraped
- Repository: https://github.com/tamersarioglu/kykscraped

## Overview

This project is an Android application that displays daily menu information for KYK dormitories in Turkey. Its primary purpose is to allow users to view breakfast and dinner menus across 18 cities, leveraging real-time data fetching via web scraping along with modern UI techniques. The project follows Clean Architecture principles with the MVVM pattern, ensuring a clear separation between data handling, business logic, and user interface.

##### Main Components
- Data Layer:
- Contains APIs, Data Transfer Objects (DTOs), Mappers, and Repository implementations.
- Key files: MenuApiService.kt, MenuScraperService.kt, MenuMapper.kt, and MenuRepositoryImpl.kt.
- Involves external libraries like JSoup (for HTML parsing) and Ktor (for networking).
- Domain Layer:
- Encapsulates business logic with Models (e.g., City, DailyMenu), Use Cases (e.g., GetDailyMenusUseCase.kt), and repository interfaces.
- Provides the abstraction that the presentation layer depends on.
- Presentation Layer:
- Handles UI screens (like MenuScreen.kt), user interactions, and state management using ViewModels (e.g., MenuViewModel.kt).
- Employs Jetpack Compose for UI rendering, Material 3 for design, and follows MVVM principles.
- Dependency Injection:
- Managed via Hilt, as seen in files under the di directory (e.g., AppModule.kt, NetworkModule.kt).

##### Component Relationships and Data Flow
- The Presentation layer (UI and ViewModel) requests data via Use Cases in the Domain layer.
- The Domain layer communicates with the Data layer through repository interfaces.
- The Data layer fetches data from remote sources (web scraping via MenuScraperService and API calls via MenuApiService) and converts it using mappers.
- UI → ViewModel → Use Case → Repository → Remote/Data Source and back.

##### Architectural Patterns and Design Principles
- MVVM Pattern: Side-by-side comparison of View (Compose UI), ViewModel (state management), and Model (data) should be illustrated.
- Repository Pattern: Demonstrate how the repository abstracts data operations.
- Dependency Injection: Highlight Hilt as a mechanism enabling loose coupling among modules.
- Async operations: Notate that Kotlin Coroutines are used for handling asynchronous tasks and Flow for reactive streams.

##### Relevant Technologies, Frameworks, and Libraries
- Kotlin (programming language)
- Jetpack Compose and Material 3 for UI
- Hilt for dependency injection
- Kotlin Coroutines and Flow for async and reactive programming
- Ktor for networking
- JSoup for web scraping and HTML parsing
- Android Architecture Components (such as ViewModel)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        P_Main["Main UI (Activity)"]:::presentation
        P_Screen["Menu Screen UI"]:::presentation
        P_VM["MenuViewModel"]:::presentation
        P_Components["UI Components"]:::presentation
    end

    subgraph "Domain Layer"
        D_UseCase["GetDailyMenusUseCase"]:::domain
        D_City["City Model"]:::domain
        D_DailyMenu["DailyMenu Model"]:::domain
        D_Repo_Interface["MenuRepository Interface"]:::domain
    end

    subgraph "Data Layer"
        DT_Api["MenuApiService"]:::data
        DT_Scraper["MenuScraperService"]:::data
        DT_Mapper["MenuMapper"]:::data
        DT_Repo_Impl["MenuRepositoryImpl"]:::data
    end

    subgraph "Dependency Injection"
        DI_App["AppModule (Hilt DI)"]:::di
        DI_Net["NetworkModule (Hilt DI)"]:::di
    end

    subgraph "External Services"
        ES_JSoup["JSoup"]:::external
        ES_Ktor["Ktor"]:::external
    end

    %% Presentation to Domain Flow
    P_Main -->|"hosts"| P_Screen
    P_Screen -->|"triggers"| P_VM
    P_VM -->|"calls"| D_UseCase

    %% Domain to Data Flow
    D_UseCase -->|"uses"| D_Repo_Interface
    D_Repo_Interface -->|"implementedBy"| DT_Repo_Impl

    %% Data Layer Details
    DT_Repo_Impl -->|"mapsDataUsing"| DT_Mapper
    DT_Repo_Impl -->|"fetchesDataFrom"| DT_Api
    DT_Repo_Impl -->|"fetchesDataFrom"| DT_Scraper
    DT_Api -->|"networkingVia"| ES_Ktor
    DT_Scraper -->|"htmlParsedBy"| ES_JSoup

    %% Dependency Injection Relationships
    DI_App -->|"injectsInto"| P_VM
    DI_App -->|"injectsInto"| DT_Repo_Impl
    DI_Net -->|"providesTo"| DT_Api
    DI_Net -->|"providesTo"| DT_Scraper

    %% Styles for Layers
    classDef presentation fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef domain fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef data fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef di fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;

    %% Click Events
    click P_Main "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/presentation/MainActivity.kt"
    click P_Screen "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/presentation/menu/MenuScreen.kt"
    click P_VM "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/presentation/menu/MenuViewModel.kt"
    click P_Components "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/presentation/menu/components/MenuComponents.kt"
    
    click D_UseCase "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/domain/usecase/GetDailyMenusUseCase.kt"
    click D_City "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/domain/model/City.kt"
    click D_DailyMenu "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/domain/model/DailyMenu.kt"
    click D_Repo_Interface "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/domain/repository/MenuRepository.kt"

    click DT_Api "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/data/remote/MenuApiService.kt"
    click DT_Scraper "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/data/remote/MenuScraperService.kt"
    click DT_Mapper "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/data/mapper/MenuMapper.kt"
    click DT_Repo_Impl "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/data/repository/MenuRepositoryImpl.kt"

    click DI_App "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/di/AppModule.kt"
    click DI_Net "https://github.com/tamersarioglu/kykscraped/blob/main/app/src/main/java/com/tamersarioglu/kykscraped/di/NetworkModule.kt"
```
