# meituan-dianping/logan architecture

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

- Interactive diagram: https://gitdiagram.com/meituan-dianping/logan
- Repository: https://github.com/meituan-dianping/logan

## Overview

##### Project Type and Purpose
- Logan is a full-stack logging system that spans multiple platforms (iOS, Android, Web, Flutter, etc.). Its purpose is to collect, store, upload, and analyze logs generated across different client applications.
- The project is split into several distinct SDKs (for mobile and web), a server component (backend log processing and storage), and a visual front-end (LoganSite) for analysis and search.

##### File Structure
- Notice that there are multiple top-level directories for each client platform:
– Example/Logan-Android (Android SDK sample and integration)
– Logan/Logan (includes the core C logging library “Clogan” and encryption utilities)
– Logan/iOS (iOS SDK)
– Logan/WebSDK (JavaScript SDK for web environments)
– Flutter (Flutter plugin supporting Android/iOS)
- In addition, there is a backend server directory (Logan/Server) and a frontend web UI in Logan/LoganSite.
- Also, supporting libraries like mbedtls and cJSON reside under Logan/mbedtls and Logan/Clogan, indicating that the low-level logging libraries and encryption components are built in C.
- The presence of NodeServer examples, Dockerfiles, and package files indicates that the project is designed to be deployed in varied environments with typical configurations (build and deployment scripts).

##### README for Insights
- The README explains the architecture with multiple images, describing four core modules: Input, Storage, BackEnd, and FrontEnd.
- It outlines a logging “pipeline” where logs are generated by the clients (via SDKs), sent to the server, stored/processed, and then visualized via LoganSite.
- There are also step-by-step setup instructions and environment requirements for each component, reaffirming the separation of concerns by platform.

- Main Components:
- Mobile and Client SDKs:
· iOS SDK (Logan/iOS) and macOS components.
· Android SDK (Example/Logan-Android and Logan/Logan through C components).
· Flutter Plugin (Flutter) that wraps the logging functionality.
· Web SDK (Logan/WebSDK) for browser-based logging.
- Server Side:
· Backend log processing service (Logan/Server) written in Java.
· Supporting log file management, protocol handling, and batch insertion.
· Configuration via Dockerfiles, pom.xml, and migration scripts (in Logan/scripts).
- Frontend:
· LoganSite (Logan/LoganSite) which provides a visual interface for log search & analysis.
· This is a Node/React-based web application that communicates with the Backend via an API.
- Core Logging Library:
· The low-level C library (Clogan in Logan/Clogan) that handles log formatting/processing.
· The integration with mbedtls and cJSON for security and structured log messaging.
- Relationships/Interactions:
- Client SDKs generate logs and use a common protocol (as detailed in the README’s “Log protocol” documentation) to send logs to the backend.
- The server receives logs, processes them (using modules like protocol handlers, task dispatchers, and mappers), and stores them (possibly in a database, as hinted by SQL scripts and migration files).
- LoganSite acts as a monitoring and analysis layer that communicates with the backend to retrieve log details (through defined APIs).
- The use of native libraries (C language libraries and mobile platform project files) indicates integration via JNI (for Android) or direct SDK bindings (for iOS and Flutter).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client SDKs"
        A("Android SDK (Java+JNI+C)"):::client
        B("iOS SDK (Sample)"):::client
        C("iOS SDK (Logan)"):::client
        D("Flutter Plugin (Dart with native bindings)"):::client
        E("Web SDK (JavaScript)"):::client
        F("Native Log Library (C)"):::core
        G("Encryption Module (mbedtls & cJSON)"):::encryption
    end

    subgraph "Backend Processing"
        H("Backend Log Processing Service (Java, Spring)"):::backend
    end

    subgraph "Frontend"
        I("LoganSite (Node/React)"):::frontend
    end

    %% Library integration within Client SDKs
    A -->|"uses"| F
    B -->|"uses"| F
    C -->|"uses"| F
    D -->|"uses"| F
    F -->|"integrates"| G

    %% Clients sending logs to Backend
    A -->|"sendsLogs"| H
    B -->|"sendsLogs"| H
    C -->|"sendsLogs"| H
    D -->|"sendsLogs"| H
    E -->|"sendsLogs"| H

    %% Backend providing API to Frontend
    H -->|"providesAPI"| I

    %% Click Events
    click A "https://github.com/meituan-dianping/logan/tree/master/Example/Logan-Android"
    click B "https://github.com/meituan-dianping/logan/tree/master/Example/Logan-iOS"
    click C "https://github.com/meituan-dianping/logan/tree/master/Logan/iOS"
    click D "https://github.com/meituan-dianping/logan/tree/master/Flutter"
    click E "https://github.com/meituan-dianping/logan/tree/master/Logan/WebSDK"
    click H "https://github.com/meituan-dianping/logan/tree/master/Logan/Server"
    click I "https://github.com/meituan-dianping/logan/tree/master/Logan/LoganSite"
    click F "https://github.com/meituan-dianping/logan/tree/master/Logan/Clogan"
    click G "https://github.com/meituan-dianping/logan/tree/master/Logan/mbedtls"

    %% Styles
    classDef client fill:#f7d794,stroke:#333,stroke-width:2px;
    classDef backend fill:#f6b3ba,stroke:#333,stroke-width:2px;
    classDef frontend fill:#c5f9e8,stroke:#333,stroke-width:2px;
    classDef core fill:#d2e6f5,stroke:#333,stroke-width:2px;
    classDef encryption fill:#f5d2d2,stroke:#333,stroke-width:2px;
```
