# alufers/mitmproxy2swagger architecture

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

- Interactive diagram: https://gitdiagram.com/alufers/mitmproxy2swagger
- Repository: https://github.com/alufers/mitmproxy2swagger

## Overview

Key Components to Include:

##### Input Sources Layer
- Mitmproxy Flow Files (.flow)
- HAR Files (Browser DevTools export)

##### Core Processing Layer
- HarCaptureReader (from har_capture_reader.py)
- MitmproxyCaptureReader (from mitmproxy_capture_reader.py)
- SwaggerUtil (from swagger_util.py)

##### Processing Pipeline
Two-pass system:
- First Pass: Path Template Generation
- A component for x-path-templates generation
- User interaction point for template editing
- Second Pass: OpenAPI Specification Generation
- Components for:
- Request/Response parsing
- Schema generation
- Example data incorporation (optional)
- Headers processing (optional)

##### Output Layer
Two main outputs:
- OpenAPI 3.0 Specification (YAML/JSON)
- Optional HTML Documentation (via redoc-cli)

Design Guidelines:

##### Technical Details
- Python version requirement
- Integration with external tools (mitmproxy, redoc-cli)
- Configuration components (.flake8, .mypy.ini, etc.)

##### Testing Layer
A separate section showing:
- Test components (test_mitmproxy2swagger.py, test_openapi_compliance.py)
- Test data flows (from testdata directory)
- Testing utilities (testing_util.py)

Specific Implementation Details:

##### Configuration Management
- How pyproject.toml influences the system
- CI/CD components from .github/workflows

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "输入"
        HAR[HAR文件]:::input
        FLOW[Mitmproxy流文件]:::input
    end

    subgraph "核心处理"
        HCR["HAR捕获读取器"]:::processor
        MCR["Mitmproxy捕获读取器"]:::processor
        SU["Swagger工具"]:::processor
        ML["主要逻辑"]:::processor
        CI["控制台界面"]:::processor
    end

    subgraph "处理流程"
        direction TB
        FP["第一步:<br/>路径模板生成"]:::process
        UI["用户模板<br/>编辑"]:::user
        SP["第二步:<br/>OpenAPI生成"]:::process
        subgraph "模式处理"
            direction TB
            RP["请求/响应<br/>解析"]:::process
            SG["模式<br/>生成"]:::process
            ED["示例数据<br/>处理"]:::process
            HP["请求头<br/>处理"]:::process
        end
    end

    subgraph "测试框架"
        TU["测试工具"]:::test
        OCT["OpenAPI合规性<br/>测试"]:::test
        CFT["核心功能<br/>测试"]:::test
        TD["测试数据"]:::test
    end

    subgraph "配置"
        PC["项目配置"]:::config
        LC["代码风格配置"]:::config
        TC["类型检查配置"]:::config
        CI_CD["CI/CD流水线"]:::config
    end

    subgraph "输出"
        OAS["OpenAPI 3.0<br/>规范"]:::output
        HD["HTML文档<br/>(通过redoc-cli)"]:::output
    end

    %% 关系
    HAR --> HCR
    FLOW --> MCR
    HCR --> ML
    MCR --> ML
    ML --> SU
    SU --> FP
    FP --> UI
    UI --> SP
    SP --> RP
    RP --> SG
    SG --> ED
    ED --> HP
    HP --> OAS
    OAS --> HD

    %% 测试关系
    ML --> TU
    TU --> OCT
    TU --> CFT
    TD --> CFT
    TD --> OCT

    %% 点击事件
    click HCR "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/har_capture_reader.py"
    click MCR "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/mitmproxy_capture_reader.py"
    click SU "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/swagger_util.py"
    click ML "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/mitmproxy2swagger.py"
    click CI "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/console_util.py"
    click TU "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/testing_util.py"
    click OCT "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/test_openapi_compliance.py"
    click CFT "https://github.com/alufers/mitmproxy2swagger/blob/master/mitmproxy2swagger/test_mitmproxy2swagger.py"
    click TD "https://github.com/alufers/mitmproxy2swagger/tree/master/testdata/"
    click OAS "https://github.com/alufers/mitmproxy2swagger/blob/master/example_outputs/lisek-out.swagger.yml"
    click HD "https://github.com/alufers/mitmproxy2swagger/blob/master/example_outputs/lisek-static.html"
    click PC "https://github.com/alufers/mitmproxy2swagger/blob/master/pyproject.toml"
    click LC "https://github.com/alufers/mitmproxy2swagger/blob/master/.flake8"
    click TC "https://github.com/alufers/mitmproxy2swagger/blob/master/.mypy.ini"
    click CI_CD "https://github.com/alufers/mitmproxy2swagger/tree/master/.github/workflows/"

    %% 样式
    classDef input fill:#a2d2ff,stroke:#333,stroke-width:2px
    classDef processor fill:#90be6d,stroke:#333,stroke-width:2px
    classDef process fill:#f9c74f,stroke:#333,stroke-width:2px
    classDef user fill:#f8961e,stroke:#333,stroke-width:2px
    classDef output fill:#f94144,stroke:#333,stroke-width:2px
    classDef test fill:#577590,stroke:#333,stroke-width:2px
    classDef config fill:#9f86c0,stroke:#333,stroke-width:2px

    %% 图例
    subgraph "图例"
        L1["输入源"]:::input
        L2["处理器"]:::processor
        L3["处理步骤"]:::process
        L4["用户交互"]:::user
        L5["输出"]:::output
        L6["测试"]:::test
        L7["配置"]:::config
    end
```
