# disney/mocking-jukebox architecture

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

- Interactive diagram: https://gitdiagram.com/disney/mocking-jukebox
- Repository: https://github.com/disney/mocking-jukebox

## Overview

##### Main Components

a. Client-Side Components:
- MockingJukebox Client Library
- Service Worker (for network interception)
- Client Application (that uses the library)

b. Server-Side Components:
- Express Server
- Mock Storage System
- Proxy Handler
- Mock Service Routes

##### Use a three-layer architecture representation
- Top Layer: Client Browser
- Middle Layer: Mocking Jukebox Components
- Bottom Layer: Server & Storage

##### Component Placement

Client Side (Top):

- Client Browser     |

- Client App      |  |

- Service Worker  |  |

- MJ Client Lib   |  |

Server Side (Bottom):

- Express Server      |

- Mock Endpoint   |  |
- Proxy Handler   |  |

- Mock Storage    |  |

##### Important Flows to Illustrate

Recording Flow:
**Client App -> Service Worker -> Real API**
- > Mock Storage

Playback Flow:
**Client App -> Service Worker -> Mock Storage**
- > Client App

##### Technical Details to Note

- Mock Service Worker integration
- `/mock` endpoint
- Album-based storage structure
- Request/response transformation points

##### Implementation Notes

- The service worker's central role in request interception
- The separation between recording and playback modes
- The configuration flexibility
- The storage mechanism

Remember to include these key files/components from the structure:
- src/client/interception.ts
- src/server/proxy/recording.ts
- src/server/proxy/playback.ts
- mock-recordings directory

**Request -> transformRequest -> Match/Record/Playback -> transformResponse -> Response**

This system design should clearly show how Mocking Jukebox acts as a middleware layer between the client application and its backend services, with the ability to switch between recording real responses and playing back recorded ones.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Browser
        ClientApp["Client Application"]:::client
        ServiceWorker["Service Worker"]:::core
        MJClient["Mocking Jukebox Client"]:::core
    end

    subgraph "Mocking Jukebox Core"
        NetworkInt["Network Interception"]:::core
        ClientHandlers["Client Request Handlers"]:::core
        ProxySystem["Proxy Handler System"]:::core
        RecordingComp["Recording Component"]:::core
        PlaybackComp["Playback Component"]:::core
        ResponseHandler["Response Handler"]:::core
    end

    subgraph "Server Layer"
        MainServer["Express Server"]:::server
        MockStorage[("Mock Storage")]:::storage
        SharedTypes["Type Definitions"]:::types
        SharedEnums["Enumerations"]:::types
    end

    %% Connections
    ClientApp --> ServiceWorker
    ServiceWorker --> MJClient
    MJClient --> NetworkInt
    NetworkInt --> ClientHandlers
    ClientHandlers --> ProxySystem
    ProxySystem --> RecordingComp
    ProxySystem --> PlaybackComp
    RecordingComp --> ResponseHandler
    PlaybackComp --> ResponseHandler
    ResponseHandler --> MockStorage
    ProxySystem --> SharedTypes
    ProxySystem --> SharedEnums
    MainServer --> ProxySystem

    %% Click Events
    click MJClient "https://github.com/disney/mocking-jukebox/blob/main/src/client/index.ts"
    click ServiceWorker "https://github.com/disney/mocking-jukebox/blob/main/src/server/service-worker.ts"
    click NetworkInt "https://github.com/disney/mocking-jukebox/blob/main/src/client/interception.ts"
    click ClientHandlers "https://github.com/disney/mocking-jukebox/blob/main/src/client/handlers.ts"
    click ProxySystem "https://github.com/disney/mocking-jukebox/blob/main/src/server/proxy/index.ts"
    click RecordingComp "https://github.com/disney/mocking-jukebox/blob/main/src/server/proxy/recording.ts"
    click PlaybackComp "https://github.com/disney/mocking-jukebox/blob/main/src/server/proxy/playback.ts"
    click ResponseHandler "https://github.com/disney/mocking-jukebox/blob/main/src/server/proxy/get-response.ts"
    click MockStorage "https://github.com/disney/mocking-jukebox/tree/main/mock-recordings/recordings/"
    click SharedTypes "https://github.com/disney/mocking-jukebox/blob/main/src/shared/types.ts"
    click SharedEnums "https://github.com/disney/mocking-jukebox/blob/main/src/shared/enums.ts"
    click MainServer "https://github.com/disney/mocking-jukebox/blob/main/src/server/index.ts"
    click ClientApp "https://github.com/disney/mocking-jukebox/blob/main/test/fixtures/client.js"

    %% Styles
    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef client fill:#4caf50,stroke:#4caf50,color:#fff
    classDef server fill:#ff9800,stroke:#ff9800,color:#fff
    classDef storage fill:#607d8b,stroke:#607d8b,color:#fff
    classDef types fill:#9c27b0,stroke:#9c27b0,color:#fff

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        ClientComp["Client Component"]:::client
        ServerComp["Server Component"]:::server
        StorageComp["Storage"]:::storage
        TypeComp["Type Definitions"]:::types
    end
```
