# mayamatakeshi/sip-mrcp architecture

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

- Interactive diagram: https://gitdiagram.com/mayamatakeshi/sip-mrcp
- Repository: https://github.com/mayamatakeshi/sip-mrcp

## Overview

#### Purpose and public entry point
`sip-mrcp` is a Node.js library for building MRCPv2 clients and servers over SIP, with RTP media transport. The package entry point is `index.js`, which exposes the SIP/MRCP stack API used by applications such as the paired examples in `samples/client.js` and `samples/server.js`.

#### Stack orchestration
`lib/sip_mrcp_stack.js` defines `SipMrcpStack`, the primary integration boundary. It is configured with:
- SIP signaling options and listening address/port
- RTP local address and allocatable media ports
- MRCP control-channel port
- an optional inbound-session callback

Applications instantiate one stack per client/server endpoint and use it to create outgoing sessions or receive incoming ones.

Paths: `lib/sip_mrcp_stack.js`, `index.js`

#### SIP signaling and session negotiation
The stack manages SIP-based session establishment and resource negotiation for MRCP resources such as speech synthesis. Client flow begins with `create_session(sip_uri, resource_type, offer_payloads, callback)`. Server flow enters through `new_session_callback`, where the application accepts a negotiated media payload or refuses the invitation.

Codec payload definitions—including payload ID, codec name, and clock rate—cross the SIP/SDP negotiation boundary and determine the RTP media format.

Paths: `lib/sip_mrcp_stack.js`, `samples/client.js`, `samples/server.js`

#### Session abstraction
`lib/session.js` represents an established or pending client/server interaction. It provides the application-facing control and event boundary:
- accept or refuse inbound sessions
- send MRCP messages with `send_mrcp_msg`
- receive `mrcp_msg` events
- receive `rtp_data` events

This keeps protocol transport details below a session-oriented EventEmitter-style API.

Paths: `lib/session.js`, `samples/client.js`, `samples/server.js`

#### MRCP control flow
After SIP negotiation creates the session, MRCPv2 control messages are sent and received through the session abstraction. Client applications issue MRCP requests; server applications consume those messages and implement the chosen resource behavior. The library’s MRCP integration is external to this repository and is supplied through the Node dependency ecosystem.

Paths: `lib/session.js`, `lib/sip_mrcp_stack.js`

#### RTP media flow
RTP media is negotiated alongside the MRCP session, using configured local IPs and a supplied pool/list of local RTP ports. Received media is emitted as `rtp_data` on the session. Payload selection made during session acceptance determines the codec expected on this path.

Paths: `lib/sip_mrcp_stack.js`, `lib/session.js`

#### Runtime and external boundaries
The repository is a Node.js package, executed directly by consumers or sample programs. Its material external protocol/runtime dependencies are SIP signaling, MRCPv2 control transport, RTP media transport, and the external SIP.js and MRCP libraries referenced by the package and README. Utility logic is centralized separately from stack/session ownership.

Paths: `package.json`, `lib/utils.js`, `samples/client.js`

Main entry points: [`lib/sip_mrcp_stack.js`](https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/sip_mrcp_stack.js) (SipMrcpStack), [`lib/session.js`](https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/session.js) (Session), [`index.js`](https://github.com/mayamatakeshi/sip-mrcp/blob/main/index.js) (Package entry), [`samples/client.js`](https://github.com/mayamatakeshi/sip-mrcp/blob/main/samples/client.js) (Client sample)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Consumers"]
  node_client_sample["Client sample<br/>example app<br/>[client.js]"]
  node_server_sample["Server sample<br/>example app<br/>[server.js]"]
end

subgraph group_package["sip-mrcp package"]
  node_entry["Package entry<br/>Node.js API<br/>[index.js]"]
  node_stack["SipMrcpStack<br/>stack orchestrator<br/>[sip_mrcp_stack.js]"]
  node_session["Session<br/>EventEmitter API<br/>[session.js]"]
  node_utils["Utilities<br/>shared helpers<br/>[utils.js]"]
  node_package_manifest["Package manifest<br/>dependency manifest<br/>[package.json]"]
end

subgraph group_external["Protocol dependencies"]
  node_sipjs{{"SIP.js<br/>external library"}}
  node_mrcp_lib{{"MRCP library<br/>external library"}}
  node_sip_peer(("SIP peer<br/>SIP signaling"))
  node_mrcp_peer(("MRCP resource<br/>MRCPv2 control"))
  node_rtp_peer(("RTP media peer<br/>RTP transport"))
end

node_client_sample -->|"uses"| node_entry
node_server_sample -->|"uses"| node_entry
node_entry -->|"exports"| node_stack
node_stack -->|"creates negotiated sessions"| node_session
node_stack -->|"uses"| node_utils
node_package_manifest -.->|"declares"| node_sipjs
node_package_manifest -.->|"declares"| node_mrcp_lib
node_stack -->|"uses"| node_sipjs
node_stack -->|"SIP/SDP negotiation"| node_sip_peer
node_stack -->|"opens control channel"| node_mrcp_lib
node_session -->|"sends and receives MRCP"| node_mrcp_lib
node_mrcp_lib -->|"MRCPv2 messages"| node_mrcp_peer
node_session -->|"emits and sends RTP"| node_rtp_peer
node_server_sample -->|"accepts or refuses; handles events"| node_session
node_client_sample -->|"sends requests; handles events"| node_session

click node_client_sample "https://github.com/mayamatakeshi/sip-mrcp/blob/main/samples/client.js"
click node_server_sample "https://github.com/mayamatakeshi/sip-mrcp/blob/main/samples/server.js"
click node_entry "https://github.com/mayamatakeshi/sip-mrcp/blob/main/index.js"
click node_stack "https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/sip_mrcp_stack.js"
click node_session "https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/session.js"
click node_utils "https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/utils.js"
click node_package_manifest "https://github.com/mayamatakeshi/sip-mrcp/blob/main/package.json"

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_client_sample,node_server_sample toneBlue
class node_entry,node_stack,node_session,node_utils,node_package_manifest toneAmber
class node_sipjs,node_mrcp_lib,node_sip_peer,node_mrcp_peer,node_rtp_peer toneMint
```

## Components

### Consumers

- [Client sample](https://github.com/mayamatakeshi/sip-mrcp/blob/main/samples/client.js): example app · Creates outgoing MRCP sessions and sends requests. · `samples/client.js`
- [Server sample](https://github.com/mayamatakeshi/sip-mrcp/blob/main/samples/server.js): example app · Accepts inbound sessions and handles MRCP requests. · `samples/server.js`

### sip-mrcp package

- [Package entry](https://github.com/mayamatakeshi/sip-mrcp/blob/main/index.js): Node.js API · `index.js`
- [SipMrcpStack](https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/sip_mrcp_stack.js): stack orchestrator · Owns SIP setup, negotiation, and media/control configuration. · `lib/sip_mrcp_stack.js`
- [Session](https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/session.js): EventEmitter API · Application boundary for acceptance, MRCP messages, and RTP events. · `lib/session.js`
- [Utilities](https://github.com/mayamatakeshi/sip-mrcp/blob/main/lib/utils.js): shared helpers · `lib/utils.js`
- [Package manifest](https://github.com/mayamatakeshi/sip-mrcp/blob/main/package.json): dependency manifest · `package.json`

### Protocol dependencies

- **SIP.js**: external library · Provides SIP signaling integration.
- **MRCP library**: external library · Provides MRCPv2 control transport integration.
- **SIP peer**: SIP signaling
- **MRCP resource**: MRCPv2 control
- **RTP media peer**: RTP transport · Codec payload selection determines the media format.

## Connections

- Client sample → Package entry: uses
- Server sample → Package entry: uses
- Package entry → SipMrcpStack: exports
- SipMrcpStack → Session: creates negotiated sessions
- SipMrcpStack → Utilities: uses
- Package manifest → SIP.js: declares
- Package manifest → MRCP library: declares
- SipMrcpStack → SIP.js: uses
- SipMrcpStack → SIP peer: SIP/SDP negotiation
- SipMrcpStack → MRCP library: opens control channel
- Session → MRCP library: sends and receives MRCP
- MRCP library → MRCP resource: MRCPv2 messages
- Session → RTP media peer: emits and sends RTP
- Server sample → Session: accepts or refuses; handles events
- Client sample → Session: sends requests; handles events
