> Documentation index for m4trix: https://m4trix.dev/llms.txt. Every page is available as Markdown by appending `.md` to its URL.

# What's Happening (Mental Model)

Source: https://m4trix.dev/docs/getting-started/whats-happening

Here's the mental model for how a request flows through m4trix:

## Flow Overview

1. **HTTP Request** — A client sends a POST (or GET) to your exposed endpoint.
2. **expose()** — Extracts the JSON payload, runs auth (if configured), and publishes a **start event** to the main channel.
3. **Main Channel** — Events enter here. Agents subscribed to this channel receive the event.
4. **Agent(s)** — Logic runs. The agent reads `triggerEvent.payload`, does work (e.g. calls an LLM), and **emits** new events.
5. **Client Channel** — Emitted events are published to channels the agent is bound to. The client channel has an `sse()` proxy, so events are streamed as SSE to the browser.
6. **Browser** — Receives SSE events and can render them in real time.

## Key Ideas

- **Events** are typed messages. Schemas are validated at runtime via Effect.
- **Channels** route events. Agents subscribe to channels (input) and publish to channels (output).
- **Proxies** determine how events leave the system — e.g. `proxy.sse()` for SSE, or a custom proxy kind of your own.
- **AgentNetwork** wires everything: channels, agents, and the event plane.

## Diagram

![One request through the hello-world network: the browser POSTs to expose(), which publishes user-request on main; myAgent runs and emits agent-response events on client; they stream through proxy.sse() to the browser, followed by m4trix:run.completed.](https://m4trix.dev/docs/visuals/request-flow.gif)

## Next

- [Next Steps](https://m4trix.dev/docs/getting-started/next-steps.md) — Where to go from here
