Skip to main content

Architecture Overview

Synapse UI is an Nx monorepo that publishes tree-shakable Angular packages under the @synapse-ui npm scope. The library targets enterprise applications that embed generative AI experiences — streaming responses, prompt input, and AI-specific feedback — without coupling to a specific LLM provider.

Design Goals

  1. Provider-agnostic — Components consume generic SSE streams; no Azure/OpenAI SDK in the UI layer.
  2. Performance at stream speed — OnPush change detection and incremental DOM updates for high-frequency SSE chunks.
  3. Themeable by default — All visual values flow through CSS custom properties managed by ThemeService.
  4. Publishable granularity — Secondary entry points (@synapse-ui/ai-prompt, etc.) so consumers import only what they need.
  5. Documented decisions — ADRs capture why, not just what.

High-Level Architecture

flowchart TB
subgraph Consumer App
App[Angular Application]
end

subgraph Synapse UI Packages
Theme["@synapse-ui/theme"]
Prompt["@synapse-ui/ai-prompt"]
Stream["@synapse-ui/stream-container"]
Core["@synapse-ui/core"]
end

subgraph External
SSE[SSE Backend]
Marked[marked]
Shiki[Shiki]
end

App --> Theme
App --> Prompt
App --> Stream
Prompt --> Theme
Stream --> Theme
Stream --> Core
Core --> Marked
Core --> Shiki
App -->|EventSource / fetch| SSE
SSE -->|text/event-stream| Core

Layer Responsibilities

LayerPackageResponsibility
Theme@synapse-ui/themeDesign tokens, CSS variable maps, ThemeService
Core@synapse-ui/coreSSE parsing, stream buffers, shared types and utilities
UI@synapse-ui/*Standalone Angular components with Storybook stories
Appsapps/docs, apps/sandboxDocumentation site and integration reference

Data Flow: Prompt to Streamed Response

sequenceDiagram
participant User
participant PromptBar as AiPromptBar
participant App as Consumer App
participant Backend as SSE Backend
participant Container as AiStreamContainer

User->>PromptBar: Type prompt, press Enter
PromptBar->>App: submit event (prompt text)
App->>Backend: POST /chat (opens SSE)
Backend-->>App: SSE chunks
App->>Container: append chunks (signal/Observable)
Container->>Container: Parse markdown (marked)
Container->>Container: Highlight code (Shiki)
Container->>User: Rendered streaming output
User->>PromptBar: Click stop
PromptBar->>App: stopGeneration event
App->>Backend: Abort stream

Key Technical Choices

ConcernChoiceRationale
MonorepoNxAffected builds, generators, consistent tooling
ComponentsStandalone + OnPushModern Angular, performance for streaming
ThemingCSS custom propertiesRuntime switching without rebuild
MarkdownmarkedLightweight, extensible
HighlightingShikiAccurate, theme-aware syntax highlighting
StreamingGeneric SSEBackend-agnostic; works with any compliant server
DocsDocusaurus + StorybookNarrative docs + interactive component catalog

See ADRs for full decision records.

MVP Boundary

The minimum viable release includes:

  • @synapse-ui/themeThemeService and token maps
  • @synapse-ui/ai-promptAiPromptBar
  • @synapse-ui/stream-containerAiStreamContainer

Everything else (skeleton, feedback, button, additional primitives) ships post-MVP.