# copilotkit/open-research-ana architecture

> Architecture diagram of the GitHub repository copilotkit/open-research-ana, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/copilotkit/open-research-ana
- Repository: https://github.com/copilotkit/open-research-ana

## Overview

##### Main Components
- Agent (Backend):
- Core agent logic: files like config.py, graph.py, and state.py.
- Tools: Located in agent/tools (e.g., outline_writer, section_writer, tavily_extract, tavily_search).
- Environment Configuration: .env.example for API keys and settings.
- Dependencies: Integrates language graph functionality and connects with external APIs (OpenAI, Tavily, LangSmith, CopilotKit).

- Frontend (Next.js Application):
- API Routes: Found in frontend/src/app/api; for instance, the copilotkit route.
- UI Components: Multiple React components for chat, document management, progress views, etc.
- Utility Libraries and Hooks: In frontend/src/lib and frontend/src/lib/hooks.
- Styling and configuration: Tailwind configuration, ESLint, and TypeScript configurations.

- External Services:
- External APIs/Services: OpenAI for language models, Tavily for real-time search, LangSmith, and CopilotKit for agent interfacing.
- LangGraph CLI and dependencies for orchestrating the backend.

##### Out Relationships and Interactions
- The frontend communicates with the agent via the API endpoint provided after starting the agent (e.g., langgraph up results in a local HTTP endpoint).
- The agent serves as the back-end core which processes research data, manages state, and leverages integrated tools to perform actions like outlining or extracting information.
- The frontend makes API calls (using endpoints defined under the app/api folder) to interface with the agent.
- Both layers require secret/API keys through environment configuration, ensuring secure interactions with third-party services.

##### Important Architectural Patterns and Design Principles
- Separation of Concerns: Clearly separated front-facing UI (React/Next.js) from the underlying agent logic.
- Modular Design: The agent’s utilities are modularized into separate tools, and the frontend’s UI components are well-organized into individual files and subdirectories.
- Human-in-the-loop Interaction: Emphasizes interactive research and iterative user engagement.
- Integration with Third-Party Services: Demonstrates external dependency management and use of various real-time search and agentic tools.

##### Detail Technologies and Frameworks
- Backend: Python (with LangGraph integration, API key management, and environment configuration).
- Frontend: Next.js (React with TypeScript) with various UI components and custom hooks.
- Tools: Docker (for containerizing components), PNPM (for package management), and additional build and linting tools.
- External Services: OpenAI, Tavily, CopilotKit, LangSmith.

- Frontend → Agent API endpoints (user actions initiating backend processing)
- Agent → External APIs/Services (communications for search, language generation, etc.)
- Business logic (backend, tools)
- UI components (frontend)
- External services
- Additional Elements: Include configuration and environment settings, especially noting the integration of environment variables (from .env files) that enable secure API interactions.
- Interaction Flow: Optionally annotate the sequence of actions from starting the agent (using LangGraph CLI) to opening a tunnel with CopilotKit, then initiating the frontend – to visually capture the complete startup and runtime workflow.

##### Attention to Detail

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Agent Backend Section
    subgraph "Agent Backend"
        direction TB
        subgraph "Core Logic"
            direction TB
            A1["Config (config.py)"]:::backendCore
            A2["Graph (graph.py)"]:::backendCore
            A3["State (state.py)"]:::backendCore
        end
        subgraph "Tool Modules"
            direction TB
            T1["Outline Writer (outline_writer.py)"]:::backendTool
            T2["Section Writer (section_writer.py)"]:::backendTool
            T3["Tavily Extract (tavily_extract.py)"]:::backendTool
            T4["Tavily Search (tavily_search.py)"]:::backendTool
        end
        AEnv["Environment Config (.env.example)"]:::backendEnv
    end

    %% Frontend Section
    subgraph "Frontend UI"
        direction TB
        F1["API Routes (copilotkit)"]:::frontendAPI
        F2["UI Components"]:::frontendUI
        F3["Utility Libraries & Hooks"]:::frontendUtil
        subgraph "Styling & Configuration"
            direction TB
            F4a["Tailwind Config (tailwind.config.ts)"]:::frontendConfig
            F4b["ESLint (.eslintrc.json)"]:::frontendConfig
            F4c["TypeScript (tsconfig.json)"]:::frontendConfig
            F4d["Globals CSS (globals.css)"]:::frontendConfig
        end
    end

    %% External Services Section
    subgraph "External Services"
        direction TB
        ES1["OpenAI"]:::external
        ES2["Tavily"]:::external
        ES3["LangSmith"]:::external
        ES4["CopilotKit"]:::external
    end

    %% Relationships between Frontend and Agent Backend
    F1 -->|"API_call"| A1
    F1 -->|"API_call"| A2
    F1 -->|"API_call"| A3
    F2 -->|"triggers"| F1
    F3 -->|"supports"| F2
    F4a -->|"configures"| F2
    F4b -->|"configures"| F2
    F4c -->|"configures"| F2
    F4d -->|"configures"| F2

    %% Relationships from Agent Core to Tool Modules
    A1 -->|"utilizes"| T1
    A1 -->|"utilizes"| T2
    A1 -->|"utilizes"| T3
    A1 -->|"utilizes"| T4

    %% Relationships from Agent Backend to External Services
    A1 -->|"integrates"| ES1
    A1 -->|"integrates"| ES2
    A1 -->|"integrates"| ES3
    A1 -->|"integrates"| ES4

    %% Click Events for Agent Backend - Core Logic
    click A1 "https://github.com/copilotkit/open-research-ana/blob/main/agent/config.py"
    click A2 "https://github.com/copilotkit/open-research-ana/blob/main/agent/graph.py"
    click A3 "https://github.com/copilotkit/open-research-ana/blob/main/agent/state.py"

    %% Click Events for Agent Backend - Tool Modules
    click T1 "https://github.com/copilotkit/open-research-ana/blob/main/agent/tools/outline_writer.py"
    click T2 "https://github.com/copilotkit/open-research-ana/blob/main/agent/tools/section_writer.py"
    click T3 "https://github.com/copilotkit/open-research-ana/blob/main/agent/tools/tavily_extract.py"
    click T4 "https://github.com/copilotkit/open-research-ana/blob/main/agent/tools/tavily_search.py"

    %% Click Event for Agent Backend - Environment Configuration
    click AEnv "https://github.com/copilotkit/open-research-ana/blob/main/agent/.env.example"

    %% Click Event for Frontend - API Routes
    click F1 "https://github.com/copilotkit/open-research-ana/blob/main/frontend/src/app/api/copilotkit/route.ts"

    %% Click Event for Frontend - UI Components
    click F2 "https://github.com/copilotkit/open-research-ana/tree/main/frontend/src/components"

    %% Click Events for Frontend - Utility Libraries and Hooks
    click F3 "https://github.com/copilotkit/open-research-ana/tree/main/frontend/src/lib"
    click F3 "https://github.com/copilotkit/open-research-ana/tree/main/frontend/src/lib/hooks"

    %% Click Events for Frontend - Styling & Configuration
    click F4a "https://github.com/copilotkit/open-research-ana/blob/main/frontend/tailwind.config.ts"
    click F4b "https://github.com/copilotkit/open-research-ana/blob/main/frontend/.eslintrc.json"
    click F4c "https://github.com/copilotkit/open-research-ana/blob/main/frontend/tsconfig.json"
    click F4d "https://github.com/copilotkit/open-research-ana/blob/main/frontend/src/app/globals.css"

    %% Styles
    classDef backendCore fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backendTool fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef backendEnv fill:#D5F5E3,stroke:#117864,stroke-width:2px;
    classDef frontendAPI fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef frontendUI fill:#F5CBA7,stroke:#CD6155,stroke-width:2px;
    classDef frontendUtil fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef frontendConfig fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
