# codingwithanish/parlant architecture

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

- Interactive diagram: https://gitdiagram.com/codingwithanish/parlant
- Repository: https://github.com/codingwithanish/parlant

## Overview

##### Project Type and Purpose
- Parlant is a full-stack, open-source conversation modeling engine with two main surfaces:
- A Python‐based backend (Parlant REST API + core engine) that orchestrates guideline matching, tool calling, and message composition.
- A TypeScript/React “sandbox” UI (chat SPA) served by the backend for interactive testing.
- It also provides CLI binaries (`parlant-server`, `parlant-client`) and SDKs for Python and TypeScript.

##### Top-Level Architecture Layers
- Presentation Layer
- Browser / Developer CLI → React SPA + WebSocket console for real‐time logs.
- API Layer
- `src/parlant/api/app.py` uses FastAPI (or similar) to expose REST endpoints and WebSocket streams.
- Controllers under `src/parlant/api/*.py` (sessions, agents, guidelines, logs, etc.).
- Core Engine Layer
- `src/parlant/core/application.py` and sub-packages implement:
– Guideline matching (`guideline_matcher`)
– Tool invocation (`tool_caller`)
– Message composition / self-critique
– Event emission (buffer + publisher)
- Uses hexagonal (ports & adapters) pattern—core logic depends on abstract interfaces.
- Adapter Layer
- Database adapters (`adapters/db/*`): MongoDB, JSON file, in-memory.
- Vector DB adapters (`adapters/vector_db/*`): Chroma, in-memory.
- NLP service adapters (`adapters/nlp/*`): OpenAI, Azure, Anthropic, Gemini, HuggingFace, etc.
- Logger adapter (`adapters/loggers/*`): WebSocket, file.
- Persistence Layer
- Document store (Mongo or JSON) for sessions, guidelines, glossary, etc.
- Vector store (Chroma) for embeddings.
- External Services
- LLM providers via REST
- OpenAPI‐driven tools (plugin framework)
- Third‐party services invoked through tool adapters.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["React SPA"]:::frontend
        CLI["CLI Clients"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIServer["FastAPI Server"]:::api
        Controllers["Controllers"]:::api
    end

    %% Core Engine Layer
    subgraph "Core Engine"
        direction TB
        Application["Core Application"]:::core
        GuidelineMatcher["Guideline Matcher"]:::core
        ToolCaller["Tool Caller"]:::core
        MessageComposer["Message Composer & Generator"]:::core
        EventPublisher["Event Publisher"]:::core
    end

    %% Adapter Layer
    subgraph "Adapter Layer"
        direction TB
        subgraph DB_Adapters["Database Adapters"]
            JSONAdapter["JSON DB Adapter"]:::adapter
            MongoAdapter["MongoDB Adapter"]:::adapter
            TransientDB["In-Memory DB Adapter"]:::adapter
        end
        subgraph Vector_Adapters["Vector DB Adapters"]
            ChromaAdapter["Chroma Adapter"]:::adapter
            TransientVector["In-Memory Vector Adapter"]:::adapter
        end
        subgraph NLP_Adapters["NLP Service Adapters"]
            OpenAI["OpenAI Adapter"]:::adapter
            Azure["Azure Adapter"]:::adapter
            Anthropic["Anthropic Adapter"]:::adapter
            Gemini["Gemini Adapter"]:::adapter
        end
        LoggerAdapter["WebSocket Logger Adapter"]:::adapter
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        DocumentStore["Document Store (Mongo/JSON)"]:::datastore
        VectorStore["Vector Store (Chroma)"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        LLMProviders["LLM Providers"]:::external
        ToolServices["External Tools"]:::external
    end

    %% Connections
    Browser -->|HTTP/WebSocket| APIServer
    CLI -->|gRPC/REST| APIServer

    APIServer -->|calls| Controllers
    Controllers -->|invokes| Application

    Application -->|uses| GuidelineMatcher
    Application -->|uses| ToolCaller
    Application -->|uses| MessageComposer
    Application -->|publishes events| EventPublisher

    GuidelineMatcher -->|queries| JSONAdapter
    GuidelineMatcher -->|queries| MongoAdapter

    ToolCaller -->|via| NLP_Adapters
    ToolCaller -->|via| Vector_Adapters
    ToolCaller -->|via| ToolServices

    MessageComposer -->|reads| DocumentStore
    MessageComposer -->|reads| VectorStore

    EventPublisher -->|streams logs| LoggerAdapter
    LoggerAdapter -->|WebSocket| Browser

    JSONAdapter -->|stores| DocumentStore
    MongoAdapter -->|stores| DocumentStore
    TransientDB -->|stores| DocumentStore

    ChromaAdapter -->|stores| VectorStore
    TransientVector -->|stores| VectorStore

    NLP_Adapters -->|REST| LLMProviders

    Controllers -->|returns| Browser

    %% Click Events
    click Browser "https://github.com/codingwithanish/parlant/tree/develop/src/parlant/api/chat"
    click CLI "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/bin/client.py"
    click CLI "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/bin/server.py"
    click APIServer "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/api/app.py"
    click Controllers "https://github.com/codingwithanish/parlant/tree/develop/src/parlant/api/"
    click Application "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/application.py"
    click GuidelineMatcher "https://github.com/codingwithanish/parlant/tree/develop/src/parlant/core/engines/alpha/guideline_matching"
    click ToolCaller "https://github.com/codingwithanish/parlant/tree/develop/src/parlant/core/engines/alpha/tool_calling"
    click MessageComposer "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/engines/alpha/message_event_composer.py"
    click MessageComposer "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/engines/alpha/message_generator.py"
    click EventPublisher "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/emission/event_buffer.py"
    click EventPublisher "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/emission/event_publisher.py"
    click JSONAdapter "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/db/json_file.py"
    click MongoAdapter "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/db/mongo_db.py"
    click TransientDB "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/db/transient.py"
    click ChromaAdapter "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/vector_db/chroma.py"
    click TransientVector "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/vector_db/transient.py"
    click OpenAI "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/nlp/openai_service.py"
    click Azure "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/nlp/azure_service.py"
    click Anthropic "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/nlp/anthropic_service.py"
    click Gemini "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/nlp/gemini_service.py"
    click LoggerAdapter "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/adapters/loggers/websocket.py"
    click DocumentStore "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/persistence/document_database.py"
    click VectorStore "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/persistence/vector_database.py"
    click SDK "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/sdk.py"
    click ToolRegistry "https://github.com/codingwithanish/parlant/blob/develop/src/parlant/core/services/tools/service_registry.py"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef api fill:#DFFFE0,stroke:#28a745,color:#28a745
    classDef core fill:#E0F7FA,stroke:#00796B,color:#00796B
    classDef adapter fill:#FFF3E0,stroke:#FB8C00,color:#FB8C00
    classDef datastore fill:#F0F0F0,stroke:#AAAAAA,color:#333333
    classDef external fill:#FFEBEE,stroke:#D32F2F,color:#D32F2F
```
