# vivo/moonbox architecture

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

- Interactive diagram: https://gitdiagram.com/vivo/moonbox
- Repository: https://github.com/vivo/moonbox

## Overview

##### Main Components
- Frontend Client: Represent the “client” directory and its Vue components, which include the main App, routes, store (Vuex), and other UI elements. This provides the user interface for both flow recording and replay monitoring.
- Backend Services: Clearly show the layered backend architecture:
– The core server (in the moonbox-server module), which is responsible for receiving traffic requests (entry calls) from agents.
– Service modules such as moonbox-service-agent, moonbox-service-console, moonbox-service-data, etc., that implement business logic for recording, replay, configuration management, and analysis.
– The data access layer (DAL) in the moonbox-dal module that uses MyBatis to interact with a MySQL database.
– The integration with Redis, Elasticsearch, or other storage systems (as indicated in folders like “db/mysql” and “docker/redis”, and modules such as moonbox-service-data-es and moonbox-service-data-redis).
- Agent and Plugin Engine:
– The moonbox-agent and its local deployment assets (e.g., local-agent, moonbox-agent, and corresponding Docker images) that capture the traffic from entry points by leveraging Java instrumentation.
– The plugins directory that contains many submodules (dubbo, motan, okhttp, etc.) following an SPI design that intercepts sub-calls during both recording and replay.
- Infrastructure and Deployment:
– The Docker directory with compose files and Dockerfiles shows that each major component (e.g., MySQL, Redis, web server) is containerized.
– The “db” directory that includes the DDL files for the MySQL database.

##### Architectural Patterns & Design Principles
- Separation of concerns by differentiating between the presentation layer (Vue client), the business/service layer (Java REST/Controller modules, service implementations), and the data layer (DAL and database connectors).
- Use of SPI for extensibility (a plug-in based design) and the micro-modular approach that splits responsibilities among different Maven modules.
- Containerization of the platform using Docker, which separates the runtime environments and supports scalable deployment in production.

##### Technologies and Frameworks
- Frontend: Vue.js, Vue Router, Vuex, Babel, Gulp.
- Backend: Java (Spring Framework, MyBatis), Maven-based multi-module project, with heavy use of SPI plugins for RPC mocking.
- Database: MySQL (schema in db/mysql and mapping files in moonbox-dal), Redis (docker/redis), ElasticSearch (in moonbox-service-data-es).
- Deployment: Docker and docker-compose for orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Layer
    subgraph "External Layer"
        ET("External Traffic"):::external
    end

    %% Agent & Plugin Layer
    subgraph "Agent & Plugin Layer"
        A("Agent (moonbox-agent)"):::agent
        PE("Plugin Engine"):::agent
    end

    %% Backend Services
    subgraph "Backend Services"
        CS("Core Server (moonbox-server)"):::backend
        DAL("Data Access Layer (moonbox-dal)"):::dal
        CS -->|"persistence"| DAL
    end

    %% Data Storage
    subgraph "Data Storage"
        DB("MySQL Database"):::database
        DAL -->|"MyBatis"| DB
        DB -->|"replay_flow"| CS
    end

    %% Cache & Search
    subgraph "Cache & Search"
        RC("Redis Cache"):::database
        ES("ElasticSearch"):::database
        CS -->|"caching"| RC
        CS -->|"indexing"| ES
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        UI("UI Client – Vue.js App"):::frontend
        UI -->|"user_interactions"| CS
        CS -->|"API_response"| UI
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        DI("Docker Infrastructure"):::docker
        DS("Database Schema"):::docker
    end

    %% Connections for Request Flow
    ET -->|"entry_calls"| A
    A -->|"recording"| CS
    PE -->|"mock_responses"| CS

    %% Click Events
    click UI "https://github.com/vivo/moonbox/blob/main/client/src/App.vue"
    click CS "https://github.com/vivo/moonbox/tree/main/moonbox-server"
    click DAL "https://github.com/vivo/moonbox/tree/main/moonbox-server/moonbox-dal"
    click A "https://github.com/vivo/moonbox/tree/main/moonbox-agent"
    click PE "https://github.com/vivo/moonbox/tree/main/moonbox-agent/moonbox-plugins"
    click DI "https://github.com/vivo/moonbox/tree/main/docker"
    click DS "https://github.com/vivo/moonbox/tree/main/db/mysql"

    %% Styles
    classDef external fill:#f0f0f0,stroke:#000,stroke-width:2px,color:#000;
    classDef frontend fill:#cce5ff,stroke:#0056b3,stroke-width:2px,color:#0056b3;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px,color:#155724;
    classDef agent fill:#fff3cd,stroke:#856404,stroke-width:2px,color:#856404;
    classDef dal fill:#f8d7da,stroke:#721c24,stroke-width:2px,color:#721c24;
    classDef docker fill:#e2e3e5,stroke:#6c757d,stroke-width:2px,color:#6c757d;
    classDef database fill:#f1f8e9,stroke:#33691e,stroke-width:2px,color:#33691e;
```
