# jmartin82/mmock architecture

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

- Interactive diagram: https://gitdiagram.com/jmartin82/mmock
- Repository: https://github.com/jmartin82/mmock

## Overview

##### Main Components

a) Core Server Components:
- Mock Server (Port 8083)
- Console Server (Port 8082)
- TLS Server (Port 8084)

b) Key Functional Modules:
- Config Management System
- Request Matcher
- Response Generator
- Proxy Handler
- Scenario Manager
- Statistics Collector
- WebSocket Real-time Updates

c) Storage Components:
- Mock Definitions Store
- Request History Store
- Scenario State Store

##### Component Relationships

**Client Requests -> Mock Server**

- > Request Matcher

- > Mock Definitions Store
- > Scenario Manager

- > Proxy Handler (if proxy mode)

- > Response Generator

- > Variable Processor

- > Request History Store

- > WebSocket Updates -> Console UI

##### Important Details

a) API Endpoints:
- /api/request/* (verification endpoints)
- /api/scenarios/* (scenario management)
- /api/mapping/* (mock definition management)
- /echo (WebSocket endpoint)

b) File Structure Integration:
- Config folder for mock definitions
- TLS configuration location
- UI component location

##### Architectural Patterns to Highlight

- REST API architecture for management
- Event-driven architecture for real-time updates
- Plugin-based architecture for variable processors
- State machine pattern for scenarios

##### Implementation Details

Following aspects:
- Mock definition formats (JSON/YAML)
- Variable interpolation system
- Request matching logic
- Scenario state transitions
- Proxy mode operation

##### External Integrations

Connections to:
- External services (for proxy mode)
- File system (for configuration)
- Callback endpoints
- WebHook destinations

##### Notes

Annotations for:
- Default ports (8082, 8083, 8084)
- Supported protocols (HTTP/HTTPS)
- Configuration hot-reload capability
- Real-time monitoring features

- Mock definition management
- Request matching and response generation
- Scenario management
- Verification capabilities
- Real-time monitoring
- Proxy functionality

## Diagram (Mermaid)

```mermaid
%%{init: {'theme': 'base', 'themeVariables': { 'fontSize': '16px'}}}%%
flowchart TB
    subgraph Clients
        C1[Client Requests]:::client
        C2[Console UI]:::client
    end

    subgraph "Core Servers"
        MS[Mock Server :8083]:::server
        CS[Console Server :8082]:::server
        TLS[TLS Server :8084]:::server
    end

    subgraph "Request Processing"
        RM[Request Matcher]:::processor
        PH[Proxy Handler]:::processor
        RG[Response Generator]:::processor
        VP[Variable Processor]:::processor
        VG[Variable Generators]:::processor
    end

    subgraph "Management"
        CM[Config Management]:::manager
        SM[Scenario Manager]:::manager
        SC[Statistics Collector]:::manager
    end

    subgraph "Storage"
        MDS[(Mock Definitions)]:::storage
        RHS[(Request History)]:::storage
        SS[(Scenario State)]:::storage
    end

    subgraph "API Layer"
        R[Router]:::api
        WD[WebSocket Dispatcher]:::realtime
        AS[API Services]:::api
        PM[Payload Matcher]:::processor
    end

    C1 --> MS
    C2 --> CS
    
    MS --> R
    R --> RM
    R --> PH
    R --> RG
    
    RM --> PM
    RM --> MDS
    RM --> SM
    
    RG --> VP
    VP --> VG
    
    SM --> SS
    
    PH --> RHS
    RHS --> WD
    WD --> C2
    
    CM --> MDS
    SC --> RHS
    
    AS --> CS
    
    classDef client fill:#FFA500,stroke:#333,stroke-width:2px
    classDef server fill:#4169E1,stroke:#333,stroke-width:2px
    classDef processor fill:#98FB98,stroke:#333,stroke-width:2px
    classDef manager fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px
    classDef api fill:#20B2AA,stroke:#333,stroke-width:2px
    classDef realtime fill:#FF69B4,stroke:#333,stroke-width:2px

    click MS "https://github.com/jmartin82/mmock/blob/master/cmd/mmock/main.go"
    click TLS "https://github.com/jmartin82/mmock/tree/master//tls"
    click CS "https://github.com/jmartin82/mmock/blob/master/internal/console/dispatcher.go"
    click CM "https://github.com/jmartin82/mmock/tree/master/internal/config/"
    click RM "https://github.com/jmartin82/mmock/blob/master/pkg/match/request.go"
    click MDS "https://github.com/jmartin82/mmock/blob/master/pkg/mock/definition.go"
    click PH "https://github.com/jmartin82/mmock/blob/master/internal/proxy/proxy.go"
    click SM "https://github.com/jmartin82/mmock/blob/master/pkg/match/scenario_store.go"
    click SC "https://github.com/jmartin82/mmock/blob/master/internal/statistics/statistics.go"
    click C2 "https://github.com/jmartin82/mmock/tree/master/UI/src/"
    click AS "https://github.com/jmartin82/mmock/blob/master/UI/src/services/api.js"
    click RHS "https://github.com/jmartin82/mmock/blob/master/pkg/match/transaction_store.go"
    click VP "https://github.com/jmartin82/mmock/blob/master/pkg/vars/evaluator.go"
    click R "https://github.com/jmartin82/mmock/blob/master/internal/server/router.go"
    click WD "https://github.com/jmartin82/mmock/blob/master/internal/console/dispatcher.go"
    click PM "https://github.com/jmartin82/mmock/tree/master/pkg/match/payload/"
    click VG "https://github.com/jmartin82/mmock/tree/master/pkg/vars/fake/"
```
