# ljdongz/mocka architecture

> Architecture diagram of the GitHub repository ljdongz/mocka, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ljdongz/mocka
- Repository: https://github.com/ljdongz/mocka

## Overview

Mocka is a local API mock server managed either through a browser UI or an MCP-connected AI agent. Users configure HTTP endpoints, response variants and sequences, then send requests to the mock server; they can also configure STOMP-over-WebSocket behavior and inspect live history. Supporting capabilities include collections, environments, datasets, media, import/export, and real-time updates. The README documents the service boundaries; source-index references and excerpts support several internal links. Some unsampled routes and runtime wiring are represented only where documented, or left unconnected.

Main entry points: [`server/src/services`](https://github.com/ljdongz/mocka/tree/main/server/src/services) (Configuration services), [`server/src/mock-server.ts`](https://github.com/ljdongz/mocka/blob/main/server/src/mock-server.ts) (Mock server), [`client/src/App.tsx`](https://github.com/ljdongz/mocka/blob/main/client/src/App.tsx) (Web UI), [`server/src/admin-server.ts`](https://github.com/ljdongz/mocka/blob/main/server/src/admin-server.ts) (Admin API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Management clients"]
  node_browser["Web UI<br/>[App.tsx]"]
  node_ui_features["Editors and tools"]
  node_client_state["Client stores"]
  node_client_api["API clients"]
  node_mcp["MCP server<br/>[server.ts]"]
  node_mcp_tools["MCP tools"]
end

subgraph group_admin["Admin and configuration"]
  node_admin_api["Admin API<br/>[admin-server.ts]"]
  node_admin_routes["Admin routes"]
  node_config_services["Configuration services"]
  node_domain_models["HTTP domain models<br/>[endpoint.ts]"]
  node_import_export["Import and export"]
  node_environments["Environments and data"]
  node_media["Media responses<br/>[media.service.ts]"]
end

subgraph group_httpmock["HTTP mock runtime"]
  node_mock_server["Mock server<br/>[mock-server.ts]"]
  node_route_registry["HTTP route registry<br/>[route-registry.ts]"]
  node_mock_handler["Request handler"]
end

subgraph group_stomp["STOMP mock runtime"]
  node_stomp_admin["STOMP configuration<br/>[stomp.service.ts]"]
  node_stomp_models["STOMP models<br/>[stomp.ts]"]
  node_stomp_handler["STOMP protocol handler<br/>[handler.ts]"]
  node_stomp_broker["STOMP broker<br/>[broker.ts]"]
end

subgraph group_state["Persistence and events"]
  node_database[("SQLite database<br/>[connection.ts]")]
  node_events["Domain events<br/>[domain-events.ts]"]
  node_history["Request history<br/>[history.service.ts]"]
end

node_human(("User"))
node_ai(("AI agent"))
node_external_app(("Client application"))
node_socket_client(("WebSocket client"))

node_human -->|"configures"| node_browser
node_browser -->|"renders"| node_ui_features
node_ui_features -.->|"manages"| node_client_state
node_client_state -->|"calls"| node_client_api
node_client_api -->|"sends REST"| node_admin_api
node_ai -->|"connects via MCP"| node_mcp
node_mcp -->|"registers"| node_mcp_tools
node_mcp_tools -.->|"manages"| node_config_services
node_admin_api -.->|"routes requests"| node_admin_routes
node_admin_routes -->|"delegates to"| node_config_services
node_config_services -.->|"persists via"| node_database
node_config_services -->|"uses"| node_domain_models
node_config_services -->|"updates routes"| node_route_registry
node_admin_api -->|"runs alongside"| node_mock_server
node_external_app -->|"sends HTTP"| node_mock_server
node_mock_server -->|"routes requests"| node_route_registry
node_mock_server -.->|"handles requests"| node_mock_handler
node_mock_handler -.->|"records requests"| node_history
node_config_services -.->|"supports configuration transfer"| node_import_export
node_browser -->|"receives live updates"| node_events
node_events -->|"broadcasts updates"| node_browser
node_admin_routes -->|"delegates STOMP"| node_stomp_admin
node_stomp_admin -->|"uses"| node_stomp_models
node_stomp_admin -.->|"persists via"| node_database
node_socket_client -->|"opens WebSocket"| node_mock_server
node_mock_server -->|"dispatches STOMP"| node_stomp_handler
node_stomp_handler -->|"uses broker"| node_stomp_broker
node_stomp_handler -->|"emits session updates"| node_events
node_config_services -.->|"manages variables"| node_environments
node_mock_handler -.->|"serves media"| node_media

click node_browser "https://github.com/ljdongz/mocka/blob/main/client/src/App.tsx"
click node_ui_features "https://github.com/ljdongz/mocka/tree/main/client/src/components"
click node_client_state "https://github.com/ljdongz/mocka/tree/main/client/src/stores"
click node_client_api "https://github.com/ljdongz/mocka/tree/main/client/src/api"
click node_mcp "https://github.com/ljdongz/mocka/blob/main/server/src/mcp/server.ts"
click node_mcp_tools "https://github.com/ljdongz/mocka/tree/main/server/src/mcp/tools"
click node_admin_api "https://github.com/ljdongz/mocka/blob/main/server/src/admin-server.ts"
click node_admin_routes "https://github.com/ljdongz/mocka/tree/main/server/src/routes"
click node_config_services "https://github.com/ljdongz/mocka/tree/main/server/src/services"
click node_domain_models "https://github.com/ljdongz/mocka/blob/main/server/src/models/endpoint.ts"
click node_import_export "https://github.com/ljdongz/mocka/blob/main/server/src/services/import-export.service.ts"
click node_mock_server "https://github.com/ljdongz/mocka/blob/main/server/src/mock-server.ts"
click node_route_registry "https://github.com/ljdongz/mocka/blob/main/server/src/services/route-registry.ts"
click node_mock_handler "https://github.com/ljdongz/mocka/blob/main/server/src/services/mock-handler.service.ts"
click node_stomp_admin "https://github.com/ljdongz/mocka/blob/main/server/src/services/stomp.service.ts"
click node_stomp_models "https://github.com/ljdongz/mocka/blob/main/server/src/models/stomp.ts"
click node_stomp_handler "https://github.com/ljdongz/mocka/blob/main/server/src/stomp/handler.ts"
click node_stomp_broker "https://github.com/ljdongz/mocka/blob/main/server/src/stomp/broker.ts"
click node_database "https://github.com/ljdongz/mocka/blob/main/server/src/db/connection.ts"
click node_events "https://github.com/ljdongz/mocka/blob/main/server/src/services/domain-events.ts"
click node_history "https://github.com/ljdongz/mocka/blob/main/server/src/services/history.service.ts"
click node_environments "https://github.com/ljdongz/mocka/blob/main/server/src/services/environment.service.ts"
click node_media "https://github.com/ljdongz/mocka/blob/main/server/src/services/media.service.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_ui_features,node_client_state,node_client_api,node_mcp,node_mcp_tools,node_human,node_external_app,node_socket_client toneBlue
class node_admin_api,node_admin_routes,node_config_services,node_domain_models,node_import_export,node_environments,node_media toneAmber
class node_mock_server,node_route_registry,node_mock_handler toneMint
class node_stomp_admin,node_stomp_models,node_stomp_handler,node_stomp_broker toneRose
class node_database,node_events,node_history,node_ai toneIndigo
```

## Components

### Management clients

- [Web UI](https://github.com/ljdongz/mocka/blob/main/client/src/App.tsx): `client/src/App.tsx`
- [Editors and tools](https://github.com/ljdongz/mocka/tree/main/client/src/components): `client/src/components`
- [Client stores](https://github.com/ljdongz/mocka/tree/main/client/src/stores): `client/src/stores`
- [API clients](https://github.com/ljdongz/mocka/tree/main/client/src/api): `client/src/api`
- [MCP server](https://github.com/ljdongz/mocka/blob/main/server/src/mcp/server.ts): `server/src/mcp/server.ts`
- [MCP tools](https://github.com/ljdongz/mocka/tree/main/server/src/mcp/tools): `server/src/mcp/tools`

### Admin and configuration

- [Admin API](https://github.com/ljdongz/mocka/blob/main/server/src/admin-server.ts): `server/src/admin-server.ts`
- [Admin routes](https://github.com/ljdongz/mocka/tree/main/server/src/routes): `server/src/routes`
- [Configuration services](https://github.com/ljdongz/mocka/tree/main/server/src/services): `server/src/services`
- [HTTP domain models](https://github.com/ljdongz/mocka/blob/main/server/src/models/endpoint.ts): `server/src/models/endpoint.ts`
- [Import and export](https://github.com/ljdongz/mocka/blob/main/server/src/services/import-export.service.ts): `server/src/services/import-export.service.ts`
- [Environments and data](https://github.com/ljdongz/mocka/blob/main/server/src/services/environment.service.ts): `server/src/services/environment.service.ts`
- [Media responses](https://github.com/ljdongz/mocka/blob/main/server/src/services/media.service.ts): `server/src/services/media.service.ts`

### HTTP mock runtime

- [Mock server](https://github.com/ljdongz/mocka/blob/main/server/src/mock-server.ts): `server/src/mock-server.ts`
- [HTTP route registry](https://github.com/ljdongz/mocka/blob/main/server/src/services/route-registry.ts): `server/src/services/route-registry.ts`
- [Request handler](https://github.com/ljdongz/mocka/blob/main/server/src/services/mock-handler.service.ts): `server/src/services/mock-handler.service.ts`

### STOMP mock runtime

- [STOMP configuration](https://github.com/ljdongz/mocka/blob/main/server/src/services/stomp.service.ts): `server/src/services/stomp.service.ts`
- [STOMP models](https://github.com/ljdongz/mocka/blob/main/server/src/models/stomp.ts): `server/src/models/stomp.ts`
- [STOMP protocol handler](https://github.com/ljdongz/mocka/blob/main/server/src/stomp/handler.ts): `server/src/stomp/handler.ts`
- [STOMP broker](https://github.com/ljdongz/mocka/blob/main/server/src/stomp/broker.ts): `server/src/stomp/broker.ts`

### Persistence and events

- [SQLite database](https://github.com/ljdongz/mocka/blob/main/server/src/db/connection.ts): `server/src/db/connection.ts`
- [Domain events](https://github.com/ljdongz/mocka/blob/main/server/src/services/domain-events.ts): `server/src/services/domain-events.ts`
- [Request history](https://github.com/ljdongz/mocka/blob/main/server/src/services/history.service.ts): `server/src/services/history.service.ts`

### Other components

- **User**
- **AI agent**
- **Client application**
- **WebSocket client**

## Connections

- User → Web UI: configures
- Web UI → Editors and tools: renders (evidence: `client/src/App.tsx`)
- Editors and tools → Client stores: manages (evidence: `client/src/components/stomp/StompTestClient.tsx`)
- Client stores → API clients: calls (evidence: `client/src/stores/endpoint.store.ts`)
- API clients → Admin API: sends REST
- AI agent → MCP server: connects via MCP
- MCP server → MCP tools: registers (evidence: `server/src/mcp/server.ts`)
- MCP tools → Configuration services: manages
- Admin API → Admin routes: routes requests
- Admin routes → Configuration services: delegates to (evidence: `server/src/routes/endpoint.routes.ts`)
- Configuration services → SQLite database: persists via (evidence: `server/src/services/import-export.service.ts`)
- Configuration services → HTTP domain models: uses (evidence: `server/src/services/endpoint.service.ts`)
- Configuration services → HTTP route registry: updates routes (evidence: `server/src/services/endpoint.service.ts`)
- Admin API → Mock server: runs alongside
- Client application → Mock server: sends HTTP
- Mock server → HTTP route registry: routes requests (evidence: `server/src/index.ts`)
- Mock server → Request handler: handles requests
- Request handler → Request history: records requests
- Configuration services → Import and export: supports configuration transfer (evidence: `server/src/services/import-export.service.ts`)
- Web UI → Domain events: receives live updates
- Domain events → Web UI: broadcasts updates (evidence: `server/src/services/domain-events.ts`)
- Admin routes → STOMP configuration: delegates STOMP (evidence: `server/src/routes/stomp.routes.ts`)
- STOMP configuration → STOMP models: uses (evidence: `server/src/services/stomp.service.ts`)
- STOMP configuration → SQLite database: persists via
- WebSocket client → Mock server: opens WebSocket
- Mock server → STOMP protocol handler: dispatches STOMP
- STOMP protocol handler → STOMP broker: uses broker (evidence: `server/src/stomp/handler.ts`)
- STOMP protocol handler → Domain events: emits session updates (evidence: `server/src/stomp/handler.ts`)
- Configuration services → Environments and data: manages variables
- Request handler → Media responses: serves media
