# georgeprichici/metadefender-menlo-integration architecture

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

- Interactive diagram: https://gitdiagram.com/georgeprichici/metadefender-menlo-integration
- Repository: https://github.com/georgeprichici/metadefender-menlo-integration

## Overview

##### Project Type and Purpose
- This project is a middleware integration tool designed to bridge Menlo Security’s file sanitization requests to MetaDefender Core or Cloud. It exposes REST API endpoints for file submissions, analysis, health checks, and file retrieval.
- The middleware supports asynchronous processing (leveraging Python’s async features introduced in Python 3.5) and can be deployed directly, containerized via Docker, or run in a Kubernetes cluster.

##### Analyzing the File Structure
- Top-level files and directories indicate several key components:
– The Dockerfile, Kubernetes folder, and deploy scripts show that containerization and orchestration are supported.
– The “api” directory contains API definitions (Postman collection and OpenAPI spec) for interfacing with Menlo Security.
– The “metadefender_menlo” package houses the core application code, structured into subcomponents:
- The “api” subfolder is split into:
◦ “adaptors” (e.g., base_adaptor.py, file_submit.py) that implement integrations with various MetaDefender APIs.
◦ “handlers” (e.g., health_check.py, file_submit.py, retrieve_sanitized.py) that define REST endpoints handling requests.
◦ “models” and “responses” that encapsulate data structures and HTTP responses.
- The presence of config.yml indicates a centralized configuration for API endpoints, HTTPS settings, logging, and MetaDefender parameters.
- Documentation (docs folder) and examples (README content describing integration with Menlo) help understand the external and internal behaviors.

##### Key Architectural Components
a. Main Components:
– Menlo Security (External Client): Represents the external entity invoking the Sanitization API, requiring HTTPS communication.
– Middleware (This Project):
- API Gateway / Endpoint Layer — the REST endpoints (handlers) receiving calls from Menlo.
- Business Logic Layer — incorporates adaptors that translate incoming requests to MetaDefender API calls and handle responses.
- Data Models & Response Objects — to validate and construct payloads.
- Configuration & Logging Modules — ensure proper settings for HTTPS, logging, and runtime parameters.
– MetaDefender Services:
- MetaDefender Core API.
- MetaDefender Cloud API (optional based on the configuration in config.yml).
– Deployment & Orchestration Components:
- Docker Container — built using the Dockerfile.
- Kubernetes Deployment — described in the kubernetes folder (deployment.yaml, service.yaml, ingress configurations).

b. Relationships and Data Flows:
– Menlo Security initiates a HTTPS request (e.g., file submission, health check) to the Middleware’s exposed endpoint.
– The Middleware’s API handlers receive the request and, based on the action, delegate processing to specific adaptors (e.g., file_submit adaptor).
– The adaptor calls out to the appropriate MetaDefender API (Core or Cloud) using defined endpoints and configuration parameters.
– Responses from MetaDefender are processed and transformed into a standardized format before being sent back as responses to Menlo.
– Logging and configuration components monitor and adjust these flows.
– The system’s containerization layers (Docker and Kubernetes) are responsible for packaging and deploying the middleware.

c. Architectural Patterns and Design Principles:
– Modular Design: Separation of concerns is evident in the segregation between API handlers, adaptors, models, and utility functions.
– API Gateway Pattern: The middleware centrally manages calls from Menlo and routes them to relevant processing modules.
– Asynchronous Processing: Leveraging Python’s async features to handle network calls to external APIs effectively.
– Containerization and Orchestration: Support for Docker and Kubernetes for streamlined deployment and scaling.

d. Relevant Technologies, Frameworks, and Libraries:
– Python (as the chosen programming language with async support).
– REST APIs (typically using frameworks like Flask, FastAPI, or similar – inferred from the structure).
– Docker for containerization.
– Kubernetes for orchestration.
– HTTPS configuration using locally stored certificates (with custom CA support as described in the README).

- External Clients: Menlo Security
- Middleware API Endpoints: Include handlers (e.g., file_submit, retrieve_sanitized, health_check)
- Business Logic/Adaptors: The adaptor layer interfacing with MetaDefender (show separate paths for “metadefender_core_api.py” and “metadefender_cloud_api.py”)
- Data Models & Response Objects (indicate their flow within middleware)
- External MetaDefender Services: Illustrate MetaDefender Core and MetaDefender Cloud as external systems.
- From Menlo Security to Middleware’s HTTPS endpoint.
- Bidirectional communication where applicable.
- Use another for internal components (API Gateway, Adaptors, Models).
– Make sure every component is clearly labeled with its role and, if possible, reference the file structure (e.g., “metadefender_menlo/api/handlers/health_check.py” for clarity).

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client
    A["Menlo Security"]:::external

    %% Middleware Components
    subgraph "Middleware"
        %% API Endpoints / Handlers
        subgraph "API Endpoints/Handlers"
            B1["Health Check Handler"]:::internal
            B2["File Submit Handler"]:::internal
            B3["Retrieve Sanitized Handler"]:::internal
        end
        %% Business Logic / Adaptors
        C["Business Logic/Adaptors"]:::internal
        %% MetaDefender Integrations
        subgraph "MetaDefender Integrations"
            D1["MetaDefender Core API"]:::external
            D2["MetaDefender Cloud API"]:::external
        end
        %% Data Models & Response Objects
        subgraph "Data Models & Responses"
            E1["Models"]:::internal
            E2["Responses"]:::internal
        end
        %% Configuration & Logging
        F["Configuration & Logging"]:::internal
    end

    %% Deployment and API Definition Artifacts
    subgraph "Deployment"
        G["Docker Container"]:::deploy
        H["Kubernetes Deployment"]:::deploy
        ApiDef["API Definitions"]:::deploy
        J["Documentation"]:::deploy
    end

    %% Data Flow Connections
    A -->|"HTTPS"| B1
    A -->|"HTTPS"| B2
    A -->|"HTTPS"| B3

    B1 -->|"Delegate"| C
    B2 -->|"Delegate"| C
    B3 -->|"Delegate"| C

    %% Calls from Business Logic to external MetaDefender APIs
    C -->|"Invoke(Core)"| D1
    C -->|"Invoke(Cloud)"| D2
    D1 -->|"Response"| C
    D2 -->|"Response"| C

    %% Processing with Data Models and Responses
    C -->|"Process"| E1
    E1 -->|"Format"| E2
    E2 -->|"Return"| B1

    %% Configuration and Logging influence
    F -->|"Config"| B1
    F -->|"Config"| C

    %% Deployment Flow
    B1 -->|"Packaged"| G
    G -->|"Deploy"| H
    ApiDef -->|"Defines"| B1
    J -->|"Guide"| F

    %% Click Events
    click B1 "https://github.com/georgeprichici/metadefender-menlo-integration/blob/master/metadefender_menlo/api/handlers/health_check.py"
    click B2 "https://github.com/georgeprichici/metadefender-menlo-integration/blob/master/metadefender_menlo/api/handlers/file_submit.py"
    click B3 "https://github.com/georgeprichici/metadefender-menlo-integration/blob/master/metadefender_menlo/api/handlers/retrieve_sanitized.py"
    click C "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/metadefender_menlo/api/adaptors"
    click D1 "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/metadefender_menlo/api/metadefender"
    click D2 "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/metadefender_menlo/api/metadefender"
    click E1 "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/metadefender_menlo/api/models"
    click E2 "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/metadefender_menlo/api/responses"
    click ApiDef "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/api"
    click F "https://github.com/georgeprichici/metadefender-menlo-integration/blob/master/config.yml"
    click J "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/docs"
    click G "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/Dockerfile"
    click H "https://github.com/georgeprichici/metadefender-menlo-integration/tree/master/kubernetes"

    %% Styles
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef internal fill:#bbf,stroke:#333,stroke-width:2px;
    classDef deploy fill:#cfc,stroke:#333,stroke-width:2px;
```
