# unispeech/unimrcp architecture

> Architecture diagram of the GitHub repository unispeech/unimrcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/unispeech/unimrcp
- Repository: https://github.com/unispeech/unimrcp

## Overview

##### Project Type and Purpose
- UniMRCP is an open‑source, C‑based protocol stack and toolkit implementing MRCPv1/v2 (Media Resource Control Protocol).
- It provides a layered, extensible framework for building MRCP clients, servers, media engines (ASR/TTS), and transport/signaling modules (SIP, RTSP).

##### File‑Structure Analysis
- Top‑level build system (Autotools/CMake): `configure.ac`, `CMakeLists.txt`, `Makefile.am`, `build/`, `acinclude.m4`, etc.
- Core libraries under `libs/`:
- `apr-toolkit`: abstraction and utility layer (based on Apache Portable Runtime).
- `mpf`: media processing framework (codecs, RTP, mixer, resampler).
- `mrcp*`: protocol stack split into control, message, resources, signaling, transport.
- `mrcp-client`, `mrcp-server`: client and server API layers.
- `mrcp-engine`: engine management, state machines, plugin loader.
- `mrcpv2-transport`, `uni-rtsp`: transport modules for MRCPv2 over SIP or RTSP.
- Extension points:
- `modules/`: protocol adapters (Sofia-SIP, Uni-RTSP).
- `plugins/`: sample engines (demo‑recog, demo‑synth, demo‑verifier, mrcp‑recorder).
- Platforms/binaries:
- `platforms/umc`: a unified media client console (C++).
- `platforms/unimrcp-client`, `unimrcp-server`, `asr-client`, libraries (`libunimrcp-client`, `libunimrcp-server`, `libasr-client`).
- Configuration and scenarios: `conf/` holds XML profiles, scenarios, XSDs.
- Data and tests: `data/` (sample audio/grammar), `tests/` (unit/integration suites, SIPp scenarios).
- Documentation: Doxygen (`docs/dox`), UML/design (`docs/ea`).

##### README Insights
- Confirms MRCPv1/v2 compliance, links to Doxygen and UML docs, and build/install instructions in `INSTALL`.
- Emphasizes extensibility and community resources.

a. Main Components (layered view):
- Foundation Layer: **APR Toolkit** (memory, threading, logging).
- Media Layer: **MPF** (audio codecs, RTP handling, mixing).
- Protocol Layer: **MRCP Core** split into:
- **Control** (resource/factory/stream API)
- **Message** (header/line parsing)
- **Resources** (recog/synth/recorder/verifier headers)
- Engine Layer: **MRCP‑Engine** (engine factory, state machines, plugin loader)
- Signaling/Transport Layer:
- **MRCP-Signaling** (session descriptor, agent)
- **MRCPv2-Transport** (SIP/RTSP channels)
- API Layer: **mrcp-client** and **mrcp-server** libraries
- Application Layer: Binaries (`unimrcp-client`, `unimrcp-server`, `umc`, `asr-client`)
- Extension Modules/Plugins: `modules/mrcp-sofiasip`, `modules/mrcp-unirtsp`, `plugins/*`

b. Relationships & Interactions:
- **Binaries** link against **API Layer** → which calls into **Protocol**, **Engine**, **Media**, **Foundation**.
- **MRCP commands** flow: Application → Client API → Protocol Control → Engine → MPF (media) → Transport → Network.
- **Transport** passes MRCP messages to remote servers or engines via SIP/RTSP; responses traverse back up.
- **Engine plugins** (`plugins/*`) are loaded by MRCP‑Engine at runtime.
- **Configuration** (`conf/*.xml`) drives session setup, resource profiles, and scenario behavior.

c. Architectural Patterns & Principles:
- Layered architecture with clear separation of concerns (Foundation → Media → Protocol → Signaling/Transport → Application).
- Plugin architecture for media engines and protocol adapters, enabling runtime extensibility.
- Use of factory and state‑machine patterns in the MRCP‑Engine layer.
- Build portability via APR and Autotools/CMake abstraction.

d. Key Technologies & Frameworks:
- C89/C99 codebase, Apache Portable Runtime (APR)
- Autotools and CMake build scripts, Visual Studio project files for Windows.

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Application Layer
  subgraph "Application Layer"
    UMC["UniMRCP Console"]:::app
    CLIENT_APP["UniMRCP Client App"]:::app
    SERVER_APP["UniMRCP Server App"]:::app
    ASR_APP["ASR Client App"]:::app
  end

  %% API Layer
  subgraph "API Layer"
    CLIENT_LIB["MRCP Client API Lib"]:::lib
    SERVER_LIB["MRCP Server API Lib"]:::lib
  end

  %% Signaling & Transport Layer
  subgraph "Signaling & Transport Layer"
    SIGNALING["MRCP Signaling"]:::lib
    V2_TRANSPORT["MRCPv2 Transport"]:::lib
    RTSP_LIB["Uni-RTSP Transport"]:::lib
  end

  %% Engine Layer
  subgraph "Engine Layer"
    ENGINE["MRCP Engine"]:::lib
  end

  %% Protocol Layer
  subgraph "Protocol Layer"
    CTRL["MRCP Control Module"]:::lib
    MSG["MRCP Message Module"]:::lib
    RES["MRCP Resources Module"]:::lib
    INC["MRCP Common Headers"]:::lib
  end

  %% Media Layer
  subgraph "Media Layer"
    MPF["MPF (Media Processing Framework)"]:::lib
  end

  %% Foundation Layer
  subgraph "Foundation Layer"
    APR["APR Toolkit"]:::lib
  end

  %% Extension Modules & Plugins
  subgraph "Extension Modules"
    SOFIA["Sofia-SIP Module"]:::ext
    UNIRTSP_MODULE["Uni-RTSP Module"]:::ext
  end
  subgraph "Engine Plugins"
    REC_PLUGIN["Demo Recognizer Plugin"]:::plugin
    SYN_PLUGIN["Demo Synthesizer Plugin"]:::plugin
    VER_PLUGIN["Demo Verifier Plugin"]:::plugin
    RECORDER_PLUGIN["MRCP Recorder Plugin"]:::plugin
  end

  %% Config, Data, Tests, Docs
  CONFIG["Configuration Files"]:::config
  DATA["Sample Data"]:::data
  TESTS["Test Suites"]:::test
  DOCS["Documentation"]:::doc

  %% Runtime/Data Flows
  UMC -->|uses| CLIENT_LIB
  CLIENT_APP -->|uses| CLIENT_LIB
  SERVER_APP -->|uses| SERVER_LIB
  ASR_APP -->|uses| CLIENT_LIB

  CLIENT_LIB -->|calls| CTRL
  SERVER_LIB -->|calls| CTRL

  CTRL -->|parses| MSG
  CTRL -->|loads| RES
  CTRL -->|includes| INC

  CTRL -->|manages sessions| SIGNALING
  SIGNALING -->|opens channels| V2_TRANSPORT
  SIGNALING -->|opens channels| RTSP_LIB

  SOFIA -->|plugs into| SIGNALING
  UNIRTSP_MODULE -->|plugs into| SIGNALING

  REC_PLUGIN -->|loaded by| ENGINE
  SYN_PLUGIN -->|loaded by| ENGINE
  VER_PLUGIN -->|loaded by| ENGINE
  RECORDER_PLUGIN -->|loaded by| ENGINE

  CTRL -->|delegates to| ENGINE
  ENGINE -->|processes media via| MPF
  MPF -->|relies on| APR

  CONFIG -->|drives| UMC
  CONFIG -->|drives| CLIENT_APP

  %% Miscellaneous
  DATA -->|used in| TESTS
  DOCS -->|documents| CTRL

  %% Click Events
  click APR "https://github.com/unispeech/unimrcp/tree/master/libs/apr-toolkit"
  click MPF "https://github.com/unispeech/unimrcp/tree/master/libs/mpf"
  click CTRL "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp/control"
  click MSG "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp/message"
  click RES "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp/resources"
  click INC "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp/include"
  click ENGINE "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp-engine"
  click SIGNALING "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp-signaling"
  click V2_TRANSPORT "https://github.com/unispeech/unimrcp/tree/master/libs/mrcpv2-transport"
  click RTSP_LIB "https://github.com/unispeech/unimrcp/tree/master/libs/uni-rtsp"
  click CLIENT_LIB "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp-client"
  click SERVER_LIB "https://github.com/unispeech/unimrcp/tree/master/libs/mrcp-server"
  click UMC "https://github.com/unispeech/unimrcp/tree/master/platforms/umc"
  click CLIENT_APP "https://github.com/unispeech/unimrcp/tree/master/platforms/unimrcp-client"
  click SERVER_APP "https://github.com/unispeech/unimrcp/tree/master/platforms/unimrcp-server"
  click ASR_APP "https://github.com/unispeech/unimrcp/tree/master/platforms/asr-client"
  click SOFIA "https://github.com/unispeech/unimrcp/tree/master/modules/mrcp-sofiasip"
  click UNIRTSP_MODULE "https://github.com/unispeech/unimrcp/tree/master/modules/mrcp-unirtsp"
  click REC_PLUGIN "https://github.com/unispeech/unimrcp/tree/master/plugins/demo-recog"
  click SYN_PLUGIN "https://github.com/unispeech/unimrcp/tree/master/plugins/demo-synth"
  click VER_PLUGIN "https://github.com/unispeech/unimrcp/tree/master/plugins/demo-verifier"
  click RECORDER_PLUGIN "https://github.com/unispeech/unimrcp/tree/master/plugins/mrcp-recorder"
  click CONFIG "https://github.com/unispeech/unimrcp/tree/master/conf"
  click DATA "https://github.com/unispeech/unimrcp/tree/master/data"
  click TESTS "https://github.com/unispeech/unimrcp/tree/master/tests"
  click DOCS "https://github.com/unispeech/unimrcp/tree/master/docs"

  %% Styles
  classDef app fill:#ffcc00,stroke:#333,stroke-width:1px
  classDef lib fill:#00ccff,stroke:#333,stroke-width:1px
  classDef ext fill:#ccff99,stroke:#333,stroke-width:1px
  classDef plugin fill:#99ccff,stroke:#333,stroke-width:1px
  classDef config fill:#cccccc,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
  classDef data fill:#ff99cc,stroke:#333,stroke-width:1px
  classDef test fill:#ff9999,stroke:#333,stroke-width:1px
  classDef doc fill:#dddddd,stroke:#333,stroke-width:1px
```
