# dheiver2/mangaba_ai architecture

> Architecture diagram of the GitHub repository dheiver2/mangaba_ai, 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/dheiver2/mangaba_ai
- Repository: https://github.com/dheiver2/mangaba_ai

## Overview

##### Project type and purpose
- Mangaba.AI is a Python framework (an open-source tool) for creating and orchestrating teams of autonomous AI agents.
- It provides core services (agent management, inter-agent communication, context persistence), model adapters (OpenAI, Anthropic, Gemini), and integration plugins (Slack, GitHub, Jira, Discord).

##### File structure
- Top-level “mangaba_ai/” – core library
- config (assistant setup, environment loading)
- core (Agent base classes, MCP context manager, model interfaces, communication protocols)
- schemas (JSON/schema definitions for configs, messages, analysis results)
- cases (prebuilt workflows like Slack analysis)
- utils (logging, validation, exceptions)
- main.py (CLI entry-point)
- “src/integrations/” – plugin directory for platform connectors (slack, github, jira, discord)
- “examples/” – usage demos showing how to wire agents, integrations, and run tasks
- “docs/” – Markdown and Sphinx docs including architecture.md, workflow.md, agents.md
- Tests, CI scripts, and environment setup files

##### Extract insights from the README
- Core features: Autonomous agents, A2A communication, MCP (shared context), multi-model support, integration plugins
- Usage flow: configure API keys → define agents & tasks → execute examples (basic_usage.py) → view collaborative output
- Extensions: drop-in new agent roles, add new integration under src/integrations

a. Main Components
- Client / CLI (main.py or user code)
- Configuration Loader (environment & API keys)
- Agent Manager & MCP Context Controller
- Agent Instances (Researcher, Analyst, Writer, custom roles)
- Communication Bus / Protocol Layer (core.protocols)
- Model Adapters (OpenAI, Anthropic, Gemini)
- Memory / Context Store (in-memory or external DB)
- Integration Plugins (Slack, GitHub, Jira, Discord)
- Utilities (Logging, Validation)
- External Services (AI API endpoints, Slack/GitHub APIs)

b. Relationships & Data Flow
- User invokes main → config loader populates settings
- Agent Manager creates agent objects → places them on MCP context bus
- Agents send/receive messages via protocols → MCP orchestrates sequence
- Agents call Model Adapters → external AI APIs return responses → fed back into MCP
- Integration plugin handlers subscribe to MCP events and push/pull data from external platforms
- Logs and errors flow to utility modules

c. Architectural Patterns & Principles
- Modular, plugin-based architecture (separate core vs. integrations)
- Actor-style agents communicating via message protocols
- Pipeline/workflow pattern controlled by MCP (shared context manager)
- Dependency Injection for model adapters and configs
- Schema-driven validation

d. Key Technologies & Frameworks
- Python 3.8+ with dependency injection via config
- Third-party AI SDKs (google-generativeai, openai, anthropic)
- Sphinx for docs (docs/*.md, conf.py)
- pytest for tests (tests/, src/integrations/*/tests)

##### Detail without over-fragmenting
- Layer: Entry → Configuration → Core orchestration → Agents → Adapters → External services
- Don’t omit utility/support modules (logging, validation) but group them logically
- Schema definitions as the contract between components

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Entry
    User["User / CLI"]:::frontend
    click User "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/main.py"

    %% Configuration Layer
    subgraph "Configuration Layer"
        ConfigLoader["Configuration Loader"]:::core
    end
    click ConfigLoader "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/config/setup.py"
    click ConfigLoader "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/config/assistant.py"

    %% Core Orchestration
    subgraph "Core Engine"
        AgentManager["Agent Manager"]:::core
        AgentBase["Agent Base Classes"]:::core
        MCP["MCP Context Controller"]:::core
        Protocols["Communication Bus / Protocol Layer"]:::core
        Models["Model Adapter Interfaces"]:::core
        MemoryStore["Message Schema"]:::datastore
        AnalysisStore["Analysis Schema"]:::datastore
        ConfigSchema["Config Schema"]:::datastore
    end
    click AgentBase "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/core/agent.py"
    click MCP "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/core/mcp.py"
    click Protocols "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/core/protocols.py"
    click Models "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/core/models.py"
    click MemoryStore "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/schemas/message.py"
    click AnalysisStore "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/schemas/analysis.py"
    click ConfigSchema "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/schemas/config_schema.json"

    %% Utility Modules
    subgraph "Utilities"
        Logging["Logging"]:::util
        Validation["Validation"]:::util
        Exceptions["Exceptions"]:::util
    end
    click Logging "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/utils/logging.py"
    click Validation "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/utils/config_validator.py"
    click Exceptions "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/utils/exceptions.py"

    %% Integration Plugins
    subgraph "Integration Plugins"
        SlackHandler["Slack Handler"]:::plugin
        SlackAnalyzer["Slack Channel Analyzer"]:::plugin
        GitHubPlugin["GitHub Integration"]:::plugin
        JiraPlugin["Jira Integration"]:::plugin
        DiscordPlugin["Discord Integration"]:::plugin
    end
    click SlackHandler "https://github.com/dheiver2/mangaba_ai/blob/main/src/integrations/slack/slack_agent_handler.py"
    click SlackAnalyzer "https://github.com/dheiver2/mangaba_ai/blob/main/src/integrations/slack/slack_channel_analyzer.py"
    click GitHubPlugin "https://github.com/dheiver2/mangaba_ai/blob/main/src/integrations/github/github_integration.py"
    click JiraPlugin "https://github.com/dheiver2/mangaba_ai/blob/main/src/integrations/jira/jira_integration.py"
    click DiscordPlugin "https://github.com/dheiver2/mangaba_ai/blob/main/src/integrations/discord/discord_integration.py"

    %% Prebuilt Workflows
    subgraph "Prebuilt Workflows (Cases)"
        SlackCase["Slack Analysis Case"]:::plugin
        CasesRegistry["Generic Cases Registry"]:::core
    end
    click SlackCase "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/cases/slack_analyzer.py"
    click CasesRegistry "https://github.com/dheiver2/mangaba_ai/blob/main/mangaba_ai/cases/cases.py"

    %% Examples
    subgraph "Examples"
        BasicUsage["Basic Usage Demo"]:::example
        PlatformSamples["Platform Integrations Samples"]:::example
    end
    click BasicUsage "https://github.com/dheiver2/mangaba_ai/blob/main/examples/basic_usage.py"
    click PlatformSamples "https://github.com/dheiver2/mangaba_ai/tree/main/examples/platform_integrations/"

    %% Documentation
    subgraph "Documentation"
        ArchDoc["Architecture Overview"]:::docs
        ProtDoc["Protocols Description"]:::docs
        AgentsDoc["Agents Reference"]:::docs
        WorkflowDoc["Workflow Guide"]:::docs
    end
    click ArchDoc "https://github.com/dheiver2/mangaba_ai/blob/main/docs/architecture.md"
    click ProtDoc "https://github.com/dheiver2/mangaba_ai/blob/main/docs/protocols.md"
    click AgentsDoc "https://github.com/dheiver2/mangaba_ai/blob/main/docs/agents.md"
    click WorkflowDoc "https://github.com/dheiver2/mangaba_ai/blob/main/docs/workflow.md"

    %% Tests
    subgraph "Tests"
        CoreTests["Core Tests"]:::test
        IntegrationTests["Integration Tests"]:::test
        SlackTests["Slack Plugin Tests"]:::test
        APITests["API & Performance Tests"]:::test
    end
    click CoreTests "https://github.com/dheiver2/mangaba_ai/blob/main/tests/test_core.py"
    click IntegrationTests "https://github.com/dheiver2/mangaba_ai/blob/main/tests/test_integrations.py"
    click SlackTests "https://github.com/dheiver2/mangaba_ai/blob/main/src/integrations/slack/tests/test_slack_integration.py"
    click APITests "https://github.com/dheiver2/mangaba_ai/blob/main/tests/test_mangaba_api.py"
    click APITests "https://github.com/dheiver2/mangaba_ai/blob/main/tests/test_performance.py"

    %% External Services
    subgraph "External Services"
        ExternalAI["External AI APIs"]:::external
        SlackAPI["Slack API"]:::external
        GitHubAPI["GitHub API"]:::external
        JiraAPI["Jira API"]:::external
        DiscordAPI["Discord API"]:::external
    end

    %% Data Flows
    User -->|"invoke"| ConfigLoader
    ConfigLoader -->|"loads settings"| AgentManager

    %% Core interactions
    AgentManager -->|creates| AgentBase
    AgentManager -->|controls| MCP
    AgentBase -->|communicates via| Protocols
    MCP -->|orchestrates messages| AgentBase
    AgentBase -->|calls| Models
    Models -->|sends requests to| ExternalAI
    ExternalAI -->|responses| Models
    Models -->|returns responses| MCP
    MCP -->|provides context| AgentBase

    %% Plugins integration
    AgentManager -->|loads| SlackHandler
    AgentManager -->|loads| GitHubPlugin
    AgentManager -->|loads| JiraPlugin
    AgentManager -->|loads| DiscordPlugin

    SlackHandler -->|interacts with| SlackAPI
    SlackAnalyzer -->|analyzes via| SlackAPI
    GitHubPlugin -->|interacts with| GitHubAPI
    JiraPlugin -->|interacts with| JiraAPI
    DiscordPlugin -->|interacts with| DiscordAPI

    %% Workflows
    CasesRegistry -->|includes| SlackCase
    SlackCase -->|uses| SlackHandler
    SlackCase -->|feeds| MCP

    %% Utilities usage
    AgentManager -->|logs/errors| Logging
    AgentManager -->|validates| Validation
    AgentManager -->|raises| Exceptions
    Protocols -->|validates| Validation

    %% Examples & Docs reference
    BasicUsage -->|demonstrates| AgentManager
    PlatformSamples -->|demonstrates plugins| SlackHandler

    %% Styles
    classDef core fill:#D0E8FF,stroke:#0366D6,color:#000
    classDef plugin fill:#DFFFE0,stroke:#2E8B57,color:#000
    classDef external fill:#FFE5B4,stroke:#D2691E,color:#000
    classDef datastore fill:#F0E6FF,stroke:#8A2BE2,color:#000
    classDef util fill:#F5F5F5,stroke:#A9A9A9,color:#000
    classDef example fill:#FFF5BA,stroke:#FFD700,color:#000
    classDef docs fill:#FFD1DC,stroke:#FF69B4,color:#000
    classDef test fill:#ECECEC,stroke:#708090,color:#000
    classDef frontend fill:#E8F0FE,stroke:#4285F4,color:#000
```
