# How DotMock works

> DotMock surrounds a real backend with controlled dependencies. It does not replace the backend.

## 01. Create or import the contract
Start from OpenAPI, GraphQL, WSDL, Protobuf, or a focused workspace. DotMock keeps protocol-specific structure instead of flattening everything into generic HTTP.

## 02. Model behavior, not only responses
Add conditions, persistent state, latency, failures, streams, tool calls, and outbound events so the dependency behaves like the system your code must survive.

## 03. Point the development environment at DotMock
Swap the third-party base URL or client target in development and test configuration. Keep the application flow and client code intact.

## 04. Exercise, inspect, and reset
Run the real flow, inspect matched traffic and state changes, verify deliveries, then reset the environment for a reproducible next run.

## Governed agent execution
Coding agents can connect through CLI or MCP. DotMock keeps material changes evidence-based and approval-gated.

1. **Inspect:** Read the active contract, state, traffic, and capability boundaries before changing anything.
2. **Draft:** Prepare the smallest workspace change without publishing it immediately.
3. **Validate:** Run validation, simulation, or a dry run and show the expected response and state diff.
4. **Approve:** Require explicit approval for publication, rollback, deletion, reset, or other sensitive actions.
5. **Verify:** Report the resulting route, revision, traffic, delivery, or state evidence.

## Common controlled runs
### Recover from an upstream outage
Stage latency, timeouts, retries, and a controlled recovery without waiting for the real provider to fail.

### Complete a stateful checkout
Move a cart through payment and fulfillment state while emitting the same webhooks the backend consumes.

### Test an LLM tool loop
Return a deterministic tool call, accept the tool result, then stream the final provider-shaped response.

### Prove authentication failures
Exercise expired credentials, missing scopes, rate limits, and recovery paths against a stable contract.

## Related resources
- [Protocols and interfaces](https://dotmock.com/protocols.md)
- [Concept guide](https://dotmock.com/docs/concepts/how-it-works.md)
- [CLI guide](https://dotmock.com/docs/guides/cli.md)
- [MCP integration](https://dotmock.com/docs/features/mcp-integration.md)

Canonical HTML: https://dotmock.com/how-it-works
