# ndsev/mapget architecture

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

- Interactive diagram: https://gitdiagram.com/ndsev/mapget
- Repository: https://github.com/ndsev/mapget

## Overview

##### Main Components

a. Core Components:
- Service (Central Coordinator)
- Data Sources (Multiple Types)
- Cache System (RocksDB/Memory)
- HTTP Service Layer
- Client Interface Layer
- Model Layer (Feature Data Model)

b. External Components:
- Client Applications
- Data Source Implementations
- Storage Systems

##### Architecture Pattern

**[Client Layer]**
- ↕ HTTP/REST
**[Service Layer]**
- ↕ Internal APIs
**[Core Layer]**
- ↕ Storage/Cache
**[Data Layer]**

##### Component Relationships

**Clients → HTTP Service → Map Service → Cache**
- ↘ Data Sources

##### Detailed Component Breakdown

a. Model Layer (libs/model):
- Feature Models
- Geometry Types
- Attribute Layers
- String Pools

b. Service Layer (libs/service):
- Cache Interface
- Data Source Interface
- Service Configuration
- Location Services

c. HTTP Layer (libs/http-service):
- REST API Endpoints
- HTTP Client
- Service CLI

d. Data Source Layer (libs/http-datasource):
- Data Source Client
- Data Source Server
- HTTP Server Implementation

##### Key Flows to Highlight

a. Data Retrieval Flow:
**Client Request → HTTP Service → Map Service → Cache Check**
- ↘ Data Source (if cache miss)

b. Data Source Registration:
**Data Source → Service Registration → Source Info Storage**

##### Implementation Details

- mapget-model (core data structures)
- mapget-service (main service logic)
- mapget-http-service (REST interface)
- mapget-http-datasource (remote data source support)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        ClientApps[Client Applications]:::client
        PythonBindings["Python Bindings"]:::client
        click PythonBindings "https://github.com/ndsev/mapget/tree/main/libs/pymapget/"
        PyClient["Client Binding"]:::client
        PyService["Service Binding"]:::client
        PyModel["Model Binding"]:::client
        click PyClient "https://github.com/ndsev/mapget/blob/main/libs/pymapget/binding/py-client.h"
        click PyService "https://github.com/ndsev/mapget/blob/main/libs/pymapget/binding/py-service.h"
        click PyModel "https://github.com/ndsev/mapget/blob/main/libs/pymapget/binding/py-model.h"
    end

    subgraph Service["Service Layer"]
        HTTPService["HTTP Service"]:::service
        HTTPClient["HTTP Client"]:::service
        ServiceCLI["Service CLI"]:::service
        click HTTPService "https://github.com/ndsev/mapget/blob/main/libs/http-service/include/mapget/http-service/http-service.h"
        click HTTPClient "https://github.com/ndsev/mapget/blob/main/libs/http-service/include/mapget/http-service/http-client.h"
        click ServiceCLI "https://github.com/ndsev/mapget/blob/main/libs/http-service/include/mapget/http-service/cli.h"
    end

    subgraph Core["Core Layer"]
        MapService["Map Service"]:::core
        CacheInterface["Cache Interface"]:::core
        DSInterface["Data Source Interface"]:::core
        ServiceConfig["Service Configuration"]:::core
        LocationServices["Location Services"]:::core
        LoggingSystem["Logging System"]:::core
        click CacheInterface "https://github.com/ndsev/mapget/blob/main/libs/service/include/mapget/service/cache.h"
        click ServiceConfig "https://github.com/ndsev/mapget/blob/main/libs/service/include/mapget/service/config.h"
        click DSInterface "https://github.com/ndsev/mapget/blob/main/libs/service/include/mapget/service/datasource.h"
        click LocationServices "https://github.com/ndsev/mapget/blob/main/libs/service/include/mapget/service/locate.h"
        click LoggingSystem "https://github.com/ndsev/mapget/blob/main/libs/logging/include/mapget/log.h"
    end

    subgraph Model["Model Layer"]
        FeatureModels["Feature Models"]:::model
        GeometryTypes["Geometry Types"]:::model
        StringPools["String Pools"]:::model
        click FeatureModels "https://github.com/ndsev/mapget/blob/main/libs/model/include/mapget/model/feature.h"
        click GeometryTypes "https://github.com/ndsev/mapget/blob/main/libs/model/include/mapget/model/geometry.h"
        click StringPools "https://github.com/ndsev/mapget/blob/main/libs/model/include/mapget/model/stringpool.h"
    end

    subgraph Storage["Storage Layer"]
        MemCache["Memory Cache"]:::storage
        RocksDBCache["RocksDB Cache"]:::storage
        click MemCache "https://github.com/ndsev/mapget/blob/main/libs/service/include/mapget/service/memcache.h"
        click RocksDBCache "https://github.com/ndsev/mapget/blob/main/libs/service/include/mapget/service/rocksdbcache.h"
    end

    subgraph DataSource["Data Source Layer"]
        DSClient["Data Source Client"]:::datasource
        DSServer["Data Source Server"]:::datasource
        click DSClient "https://github.com/ndsev/mapget/blob/main/libs/http-datasource/include/mapget/http-datasource/datasource-client.h"
        click DSServer "https://github.com/ndsev/mapget/blob/main/libs/http-datasource/include/mapget/http-datasource/datasource-server.h"
    end

    %% Relationships
    ClientApps --> HTTPService
    PythonBindings --> HTTPService
    HTTPService --> MapService
    MapService --> CacheInterface
    CacheInterface --> MemCache
    CacheInterface --> RocksDBCache
    MapService --> DSInterface
    DSInterface --> DSClient
    DSClient --> DSServer
    MapService --> ServiceConfig
    MapService --> LocationServices
    MapService --> LoggingSystem
    MapService --> Model

    %% Styling
    classDef client fill:#gray,stroke:#333,stroke-width:2px;
    classDef service fill:#yellow,stroke:#333,stroke-width:2px;
    classDef core fill:#blue,stroke:#333,stroke-width:2px;
    classDef model fill:#purple,stroke:#333,stroke-width:2px;
    classDef storage fill:#green,stroke:#333,stroke-width:2px;
    classDef datasource fill:#orange,stroke:#333,stroke-width:2px;

    %% Legend
    subgraph Legend
        Client1[Client Component]:::client
        Service1[Service Component]:::service
        Core1[Core Component]:::core
        Model1[Model Component]:::model
        Storage1[Storage Component]:::storage
        DS1[Data Source Component]:::datasource
    end
```
