# erknvl/mlit_sdk architecture

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

- Interactive diagram: https://gitdiagram.com/erknvl/mlit_sdk
- Repository: https://github.com/erknvl/mlit_sdk

## Overview

##### Project type and purpose
- This is an SDK (a client library), not a full‐stack app.
- Purpose: Provide a Dart/Flutter interface to MLIT’s REST APIs, with caching and functional error handling.

##### File structure
- **lib/src/domain**
- *entities* (core data models)
- *value_objects* (immutable simple types)
- *repositories* (interfaces)
- *failures* (error types)
- **lib/src/application**
- *services* (use‐case handlers per domain: real_estate, facilities, hazard, urban_planning)
- **lib/src/infrastructure**
- *config* (API client & Dio settings)
- *datasources*
– *remote* (calls MLIT REST)
– *local* (cache layer)
- *dtos* (data transfer objects matching JSON)
- *mappers* (DTO ↔ domain entity)
- *repositories* (implements domain repository interfaces)
- **Entry point**: `createMLITSdk()` in `lib/mlit_sdk.dart` builds MLITSdk instance and wires configuration, services, and repos.

##### Key README insights
- Highlights services exposed (transactionService, landPriceService, appraisalService, facilitiesService, hazardService, etc.).
- Explains caching (local data source) and error handling (Either<Failure, T>).
- Shows SDK configuration (API key, cache TTL, logging).

##### Essential elements
- Each component’s name and responsibility
- Distinction between interfaces and implementations
- Indication of transformation steps (JSON → DTO → Entity)
- Caching branch (Local vs. Remote)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Consumer
    Consumer["Consumer Code"]:::external

    %% SDK Core
    subgraph "SDK Core"
        direction TB
        MLITSdkFactory["createMLITSdk() / MLITSdk / MLITSdkConfig"]:::sdkCore
        ApiClientConfig["ApiClientConfig"]:::sdkCore
        DioConfig["DioConfig"]:::sdkCore
        ApiEndpoints["ApiEndpoints"]:::sdkCore
    end

    %% Application Services
    subgraph "Application Services"
        direction TB
        BaseService["BaseService"]:::app
        FacilitiesService["FacilitiesService"]:::app
        HazardService["HazardService"]:::app
        AppraisalService["AppraisalService"]:::app
        LandPriceService["LandPriceService"]:::app
        TransactionService["TransactionService"]:::app
        UrbanPlanningService["UrbanPlanningService"]:::app
        ServicesAggregate["services.dart"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Entities["Entities"]:::domain
        ValueObjects["Value Objects"]:::domain
        RepoInterfaces["Repository Interfaces"]:::domain
        Failures["Failure Types"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        RepoImpl["Repository Implementations"]:::infra
        subgraph "Datasources"
            direction TB
            RemoteDS["RemoteDataSource"]:::infra
            LocalDS["LocalDataSource"]:::infra
        end
        DTOs["DTOs"]:::infra
        Mappers["Mappers"]:::infra
        APIClient["API Client (Dio)"]:::infra
    end

    %% External
    MLITAPI["MLIT REST API"]:::external

    %% Connections
    Consumer -->|"invokes"| MLITSdkFactory
    MLITSdkFactory -->|"configures"| ApiClientConfig
    MLITSdkFactory -->|"configures"| DioConfig
    MLITSdkFactory -->|"loads endpoints"| ApiEndpoints
    MLITSdkFactory -->|"provides services"| ServicesAggregate
    ServicesAggregate -->|includes| BaseService
    ServicesAggregate -->|includes| FacilitiesService
    ServicesAggregate -->|includes| HazardService
    ServicesAggregate -->|includes| AppraisalService
    ServicesAggregate -->|includes| LandPriceService
    ServicesAggregate -->|includes| TransactionService
    ServicesAggregate -->|includes| UrbanPlanningService

    FacilitiesService -->|"depends on"| RepoInterfaces
    HazardService -->|"depends on"| RepoInterfaces
    AppraisalService -->|"depends on"| RepoInterfaces
    LandPriceService -->|"depends on"| RepoInterfaces
    TransactionService -->|"depends on"| RepoInterfaces
    UrbanPlanningService -->|"depends on"| RepoInterfaces

    RepoInterfaces -->|"implemented by"| RepoImpl
    RepoImpl -->|"uses cache"| LocalDS
    RepoImpl -->|"uses remote"| RemoteDS

    RemoteDS -->|"HTTP calls via"| APIClient
    APIClient -->|"requests"| MLITAPI
    MLITAPI -->|"returns JSON"| DTOs
    DTOs -->|"mapped by"| Mappers
    Mappers -->|"produces"| Entities
    LocalDS -->|"returns cached JSON"| DTOs

    Entities -->|"returned in Either<Failure, T>"| ServicesAggregate
    Failures -->|"error types for"| ServicesAggregate
    ValueObjects -->|"used by"| Entities

    %% Click Events
    click MLITSdkFactory "https://github.com/erknvl/mlit_sdk/blob/main/lib/mlit_sdk.dart"
    click ApiClientConfig "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/infrastructure/config/api_client_config.dart"
    click DioConfig "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/infrastructure/config/dio_config.dart"
    click ApiEndpoints "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/infrastructure/config/api_endpoints.dart"

    click BaseService "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/base_service.dart"
    click FacilitiesService "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/facilities/facilities_service.dart"
    click HazardService "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/hazard/hazard_service.dart"
    click AppraisalService "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/real_estate/appraisal_service.dart"
    click LandPriceService "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/real_estate/land_price_service.dart"
    click TransactionService "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/real_estate/transaction_service.dart"
    click UrbanPlanningService "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/urban_planning/urban_planning_service.dart"
    click ServicesAggregate "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/application/services/services.dart"

    click Entities "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/domain/entities"
    click ValueObjects "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/domain/value_objects"
    click RepoInterfaces "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/domain/repositories"
    click Failures "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/domain/failures"

    click RemoteDS "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/infrastructure/datasources/remote"
    click LocalDS "https://github.com/erknvl/mlit_sdk/blob/main/lib/src/infrastructure/datasources/local/local_data_source.dart"
    click DTOs "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/infrastructure/dtos"
    click Mappers "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/infrastructure/mappers"
    click RepoImpl "https://github.com/erknvl/mlit_sdk/tree/main/lib/src/infrastructure/repositories"

    %% Styles
    classDef sdkCore fill:#BBDEFB,stroke:#000,stroke-width:1px
    classDef app fill:#FFE0B2,stroke:#000,stroke-width:1px
    classDef domain fill:#C8E6C9,stroke:#000,stroke-width:1px
    classDef infra fill:#E1BEE7,stroke:#000,stroke-width:1px
    classDef external fill:#CFD8DC,stroke:#000,stroke-width:1px
```
