# brainydaps/barbara architecture

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

- Interactive diagram: https://gitdiagram.com/brainydaps/barbara
- Repository: https://github.com/brainydaps/barbara

## Overview

##### Project Type & Purpose
- Barbara is a multi-platform mobile/desktop client built with .NET MAUI (Shell + TabBar) using the MVVM pattern.
- It provides three chat “agents” (Analyst, JournalHistorian, Psychologist) backed by Azure AI Agent Services via a semantic kernel.
- Purpose: present a unified XAML UI, route user messages to the appropriate AI agent, display replies in chat bubbles.

##### File Structure
- Top-level:
- Barbara.sln / Barbara.csproj – MAUI app entry point
- MauiProgram.cs – DI container & platform setup
- Presentation Layer:
- AppShell.xaml / AppShell.xaml.cs – defines Shell + TabBar with three tabs
- Views/ (AnalystPage, JournalHistorianPage, PsychologistPage) – XAML UI pages
- Controls/MessageView.xaml(.cs) – reusable chat bubble control
- Resources/Styles, Fonts, Images – UI assets
- ViewModel Layer (MVVM):
- ViewModels/BaseViewModel.cs – common ObservableCollection<MessageItem>, InputText
- ViewModels/*ViewModel.cs – one per tab; call BotService
- Domain Model & Converters:
- Models/MessageItem.cs – chat message data structure
- Service Layer:
- Services/KernelSetup.cs – initializes AIProjectClient & AgentsClient from connection string
- Services/BotService.cs – routes message to the correct agent, polls for reply
- Platform Projects:
- Platforms/{Android, iOS, MacCatalyst, Tizen, Windows} – platform-specific bootstrap and manifests

##### README for Architecture Insights
- Technologies: .NET MAUI, MVVM, Azure AI Foundry, DI container.

a. Main Components
- Presentation (Shell + TabBar, Views, Controls)
- ViewModel Layer (BaseViewModel + per-tab ViewModels)
- Service Layer (BotService, KernelSetup)
- AI Layer (AIProjectClient, AgentsClient, individual Agent instances)
- External Systems (Azure AI Agent Services in AI Foundry)
b. Relationships & Data Flow
1. User taps a tab → AppShell navigates to View
2. User enters text → Bound InputText in ViewModel
3. ViewModel calls BotService.SendToAgentAsync
4. BotService uses AgentsClient (provided by KernelSetup) to invoke correct Agent
5. Agent runs in Azure, returns reply over HTTP/JSON
6. BotService aggregates reply → returns to ViewModel → updates ObservableCollection
7. View updates via data binding → MessageView renders bubble
c. Architectural Patterns
- MVVM: clear separation of View / ViewModel / Model
- Shell TabBar: high-level navigation container
- Dependency Injection: all services & view-models registered in MauiProgram
- Semantic Kernel Agents: pluggable AI backends
d. Key Technologies
- .NET MAUI + XAML for UI
- Microsoft.Extensions.DependencyInjection
- Azure.AI.AgentServices (AIProjectClient / AgentsClient)
- Semantic Kernel
- CollectionView & DataTemplates for message list

##### Detail, Not Complexity
- Every major folder/component from the file tree.
- Both in-process components (XAML UI, ViewModels, Services) and out-of-process services (Azure AI).
- Avoid clustering too much into “Misc”: show individual agents (AnalystAgent, JournalHistorianAgent, PsychologistAgent) as distinct nodes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        AppShell["AppShell (Shell + TabBar)"]:::presentation
        AnalystPage["AnalystPage"]:::presentation
        JournalHistorianPage["JournalHistorianPage"]:::presentation
        PsychologistPage["PsychologistPage"]:::presentation
        MessageView["MessageView (Chat Bubble Control)"]:::presentation
        AppShell -->|"1. navigate to tab"| AnalystPage
        AppShell -->|"1. navigate to tab"| JournalHistorianPage
        AppShell -->|"1. navigate to tab"| PsychologistPage
        AnalystPage -->|"binds InputText / messages"| AnalystViewModel
        JournalHistorianPage -->|"binds InputText / messages"| JournalHistorianViewModel
        PsychologistPage -->|"binds InputText / messages"| PsychologistViewModel
        AnalystPage --> MessageView
        JournalHistorianPage --> MessageView
        PsychologistPage --> MessageView
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        direction TB
        BaseViewModel["BaseViewModel"]:::vm
        AnalystViewModel["AnalystViewModel"]:::vm
        JournalHistorianViewModel["JournalHistorianViewModel"]:::vm
        PsychologistViewModel["PsychologistViewModel"]:::vm
        AnalystViewModel -->|inherits| BaseViewModel
        JournalHistorianViewModel -->|inherits| BaseViewModel
        PsychologistViewModel -->|inherits| BaseViewModel
        AnalystViewModel -->|"2. SendToAgentAsync"| BotService
        JournalHistorianViewModel -->|"2. SendToAgentAsync"| BotService
        PsychologistViewModel -->|"2. SendToAgentAsync"| BotService
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        BotService["BotService"]:::service
        KernelSetup["KernelSetup"]:::service
        BotService -->|"uses"| KernelSetup
        KernelSetup --> AgentsClient
    end

    %% AI Engine
    subgraph "AI Engine"
        direction TB
        AIProjectClient["AIProjectClient"]:::ai
        AgentsClient["AgentsClient"]:::ai
        AnalystAgent["AnalystAgent"]:::ai
        JournalHistorianAgent["JournalHistorianAgent"]:::ai
        PsychologistAgent["PsychologistAgent"]:::ai
        AgentsClient --> AnalystAgent
        AgentsClient --> JournalHistorianAgent
        AgentsClient --> PsychologistAgent
        BotService -->|"3. invoke agent"| AgentsClient
        AnalystAgent -->|"4. HTTP/JSON"| AzureAI
        JournalHistorianAgent -->|"4. HTTP/JSON"| AzureAI
        PsychologistAgent -->|"4. HTTP/JSON"| AzureAI
    end

    %% External Services
    subgraph "External Services"
        AzureAI["Azure AI Agent Services"]:::external
    end

    %% Response Flow
    AzureAI -->|"5. reply"| AgentsClient
    AgentsClient -->|"6. reply"| BotService
    BotService -->|"7. update ObservableCollection"| AnalystViewModel
    BotService -->|"7. update ObservableCollection"| JournalHistorianViewModel
    BotService -->|"7. update ObservableCollection"| PsychologistViewModel

    %% DI & Startup
    subgraph "App Startup & DI"
        direction TB
        MauiProgram["MauiProgram.cs"]:::config
        App["App.xaml / App.xaml.cs"]:::config
        Project["Barbara.sln / Barbara.csproj"]:::config
        PlatformsAndroid["Platforms/Android"]:::config
        PlatformsiOS["Platforms/iOS"]:::config
        PlatformsMac["Platforms/MacCatalyst"]:::config
        PlatformsTizen["Platforms/Tizen"]:::config
        PlatformsWindows["Platforms/Windows"]:::config

        MauiProgram -.->|registers| BotService
        MauiProgram -.->|registers| KernelSetup
        MauiProgram -.->|registers| AIProjectClient
        MauiProgram -.->|registers| AgentsClient
        MauiProgram -.->|registers| BaseViewModel
        MauiProgram -.->|registers| AnalystViewModel
        MauiProgram -.->|registers| JournalHistorianViewModel
        MauiProgram -.->|registers| PsychologistViewModel
        App --> AppShell
        Project --> MauiProgram
        Project --> App
        Project --> PlatformsAndroid
        Project --> PlatformsiOS
        Project --> PlatformsMac
        Project --> PlatformsTizen
        Project --> PlatformsWindows
    end

    %% Click Events
    click AppShell "https://github.com/brainydaps/barbara/blob/master/AppShell.xaml"
    click AnalystPage "https://github.com/brainydaps/barbara/blob/master/Views/AnalystPage.xaml"
    click JournalHistorianPage "https://github.com/brainydaps/barbara/blob/master/Views/JournalHistorianPage.xaml"
    click PsychologistPage "https://github.com/brainydaps/barbara/blob/master/Views/PsychologistPage.xaml"
    click MessageView "https://github.com/brainydaps/barbara/blob/master/Controls/MessageView.xaml"
    click BaseViewModel "https://github.com/brainydaps/barbara/blob/master/ViewModels/BaseViewModel.cs"
    click AnalystViewModel "https://github.com/brainydaps/barbara/blob/master/ViewModels/AnalystViewModel.cs"
    click JournalHistorianViewModel "https://github.com/brainydaps/barbara/blob/master/ViewModels/JournalHistorianViewModel.cs"
    click PsychologistViewModel "https://github.com/brainydaps/barbara/blob/master/ViewModels/PsychologistViewModel.cs"
    click MessageItem "https://github.com/brainydaps/barbara/blob/master/Models/MessageItem.cs"
    click AuthorToColorConverter "https://github.com/brainydaps/barbara/blob/master/Converters/AuthorToColorConverter.cs"
    click KernelSetup "https://github.com/brainydaps/barbara/blob/master/Services/KernelSetup.cs"
    click BotService "https://github.com/brainydaps/barbara/blob/master/Services/BotService.cs"
    click MauiProgram "https://github.com/brainydaps/barbara/blob/master/MauiProgram.cs"
    click App "https://github.com/brainydaps/barbara/blob/master/App.xaml"
    click Project "https://github.com/brainydaps/barbara/blob/master/Barbara.csproj"
    click PlatformsAndroid "https://github.com/brainydaps/barbara/tree/master/Platforms/Android"
    click PlatformsiOS "https://github.com/brainydaps/barbara/tree/master/Platforms/iOS"
    click PlatformsMac "https://github.com/brainydaps/barbara/tree/master/Platforms/MacCatalyst"
    click PlatformsTizen "https://github.com/brainydaps/barbara/tree/master/Platforms/Tizen"
    click PlatformsWindows "https://github.com/brainydaps/barbara/tree/master/Platforms/Windows"

    %% Styles
    classDef presentation fill:#BBDEFB,stroke:#90CAF9,stroke-width:1px
    classDef vm fill:#C8E6C9,stroke:#A5D6A7,stroke-width:1px
    classDef service fill:#FFE0B2,stroke:#FFCC80,stroke-width:1px
    classDef ai fill:#E1BEE7,stroke:#CE93D8,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#BDBDBD,stroke-width:1px
    classDef config fill:#CFD8DC,stroke:#B0BEC5,stroke-width:1px dashed
```
