# cienciadosdados/morphic architecture

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

- Interactive diagram: https://gitdiagram.com/cienciadosdados/morphic
- Repository: https://github.com/cienciadosdados/morphic

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js Application (app directory structure)
- UI Components (components directory)
- Theme and Styling (Tailwind CSS)

b) Backend Layer:
- API Routes (app/api directory)
- Agent System (lib/agents)
- Redis Storage (lib/redis)

c) External Services:
- AI Providers (OpenAI, Google, Anthropic, Ollama, Groq)
- Search APIs (Tavily, Serper, SearXNG)
- Extract APIs (Tavily, Jina AI)
- Database (Upstash/Local Redis)

##### Component Relationships

a) Client-Side Flow:
- User Interface → API Routes
- Components → Agents
- Chat Interface → Search System

b) Server-Side Flow:
- Agents → External AI Providers
- Search System → Search APIs
- Storage Layer → Redis

##### Specific Implementation Details

a) Core Features:
- Search and Answer System
- History Management
- Share Functionality
- Video Search
- URL-based Answers

b) Agent Architecture:
- Task Manager
- Researcher
- Query Suggestor
- Inquiry Handler

##### Detailed Component Breakdown

a) Frontend Components:
**Components/**
- Chat Interface
- Search Interface
- History Management
- Share System
- UI Elements

b) Backend Services:
**Lib/**
- Agents
- Task Manager
- Researcher
- Tools
- Redis Interface
- Schema Definitions

##### Integration Points

Following integration points:

- AI Provider Integration
- Search API Integration
- Redis Storage Integration
- SearXNG Integration (when configured)

##### Data Flow Patterns

Following flows:

a) Search Flow:
User Input → Query Processing → Search API → Result Processing → UI Rendering

b) Chat Flow:
User Message → Agent System → AI Provider → Response Generation → UI Update

##### Configuration Layer

A section showing:
- Environment Configuration
- Search Engine Settings
- Model Selection
- Redis Configuration

Remember to include:
- Version information
- Configuration options
- Deployment options (Vercel/Cloudflare)
- Optional features (video search, share functionality)

This system design should effectively communicate how Morphic combines AI capabilities with search functionality while maintaining a modular and extensible architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    User((User)) --> UI[User Interface]
    UI --> API[API Routes]
    API --> TaskMgr[Task Manager]
    
    TaskMgr --> Researcher[Researcher]
    TaskMgr --> QuerySug[Query Suggestor]
    TaskMgr --> Inquiry[Inquiry Handler]
    
    Researcher --> Search[Search System]
    Researcher --> VideoSearch[Video Search]
    
    Search --> SearchAPI[Search APIs]
    VideoSearch --> SearchAPI
    
    TaskMgr --> AI[AI Providers]
    
    API --> Redis[(Redis DB)]
    Redis --> Schema[Schema Definitions]
    
    %% Click Events
    click UI "https://github.com/cienciadosdados/morphic/tree/main/app"
    click API "https://github.com/cienciadosdados/morphic/tree/main/app/api"
    click TaskMgr "https://github.com/cienciadosdados/morphic/blob/main/lib/agents/task-manager.tsx"
    click Researcher "https://github.com/cienciadosdados/morphic/blob/main/lib/agents/researcher.tsx"
    click QuerySug "https://github.com/cienciadosdados/morphic/blob/main/lib/agents/query-suggestor.tsx"
    click Inquiry "https://github.com/cienciadosdados/morphic/blob/main/lib/agents/inquire.tsx"
    click Search "https://github.com/cienciadosdados/morphic/blob/main/lib/agents/tools/search.tsx"
    click VideoSearch "https://github.com/cienciadosdados/morphic/blob/main/lib/agents/tools/video-search.tsx"
    click Redis "https://github.com/cienciadosdados/morphic/tree/main/lib/redis"
    click Schema "https://github.com/cienciadosdados/morphic/tree/main/lib/schema"
    
    %% Styles
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef user fill:#85C1E9,stroke:#333,stroke-width:2px
    classDef api fill:#82E0AA,stroke:#333,stroke-width:2px
    classDef agent fill:#F8C471,stroke:#333,stroke-width:2px
    classDef tool fill:#F1948A,stroke:#333,stroke-width:2px
    classDef database fill:#BB8FCE,stroke:#333,stroke-width:2px
    classDef external fill:#85929E,stroke:#333,stroke-width:2px
    
    class User user
    class UI,API api
    class TaskMgr,Researcher,QuerySug,Inquiry agent
    class Search,VideoSearch tool
    class Redis database
    class SearchAPI,AI external
```
