# natantavares-plank/chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/natantavares-plank/chatbot
- Repository: https://github.com/natantavares-plank/chatbot

## Overview

##### Project Type and Purpose
- This is a full-stack monorepo application: a web-based AI Character Chatbot.
- Frontend: Next.js 15 (App Router), React 19, TypeScript, Tailwind CSS, Framer Motion.
- AI Engine: LangGraph (LangChain + LangSmith) implementing a multi-agent system.
- Backend/Persistence: Supabase (PostgreSQL + Auth + RLS).
- External Services: OpenAI GPT, OpenWeather API, NewsAPI.

##### File Structure Analysis
- Top Level:
- pnpm-workspace.yaml, turbo.json, package.json – monorepo orchestration.
- apps/web – Next.js application.
- apps/web/src:
- /app – App Router directories (api/chat, auth, chat, layout, pages).
- /components – Reusable UI (animation, ui/*).
- /hooks – Custom React hooks (useChat).
- /lib/langgraph – AI graph configuration, agent factory, agents, tools, memory manager.
- /lib/supabase – Supabase middleware, server client, service functions.
- apps/web/supabase – database migrations and config.
- Config: next.config.ts, tailwind.config.ts, tsconfig.json, .env_example.
- Deployment/build: Turbo, pnpm, Supabase CLI.

##### README Insights
- Detailed sections on multi-agent router, weather/news/chat agents, memory management with summarization.
- Database schema: chats, messages, summaries with RLS.
- API endpoints: /api/chat, auth endpoints.
- External API integrations and performance optimizations (Edge Runtime, lazy loading, streaming support).

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Frontend Layer
  subgraph "Frontend (Next.js App)" 
    UIcomp["UI Components"]:::frontend
    Anim["Animations"]:::frontend
    Hook["useChat Hook"]:::frontend
  end

  %% API Layer
  subgraph "API Layer (Edge Runtime)" 
    ChatRoute["/api/chat/route.ts"]:::api
    ChatActions["/api/chat/actions.ts"]:::api
    ChatDebug["/api/chat/debug/route.ts"]:::api
    AuthAction["/auth/action.ts"]:::api
    AuthConfirm["/auth/confirm/route.ts"]:::api
    SupMiddleware["Supabase Middleware"]:::api
    SupServer["Supabase Server Client"]:::api
    SupService["Supabase Service"]:::api
  end

  %% AI Engine Layer
  subgraph "LangGraph AI Engine" 
    GraphConfig["Graph Configuration"]:::ai
    AgentFactory["Agent Factory"]:::ai
    ChatAgent["Chat Agent"]:::ai
    WeatherAgent["Weather Agent"]:::ai
    NewsAgent["News Agent"]:::ai
    MemoryMgr["Memory Manager"]:::ai
    LangSmith["LangSmith Integration"]:::ai
    WeatherTool["weather.tool.ts"]:::ai
    NewsTool["news.tool.ts"]:::ai
  end

  %% Database Layer
  subgraph "Database (Supabase/PostgreSQL)" 
    DB["PostgreSQL"]:::db
    Config["config.toml"]:::db
    Mig1["20250805131738_create_chat_tables.sql"]:::db
    Mig2["20250806175503_fix_summaries_unique_constraint.sql"]:::db
    Mig3["20250811183543_adds_agent_at_messages_table.sql"]:::db
    Mig4["20250814210805_adds_turn_column_at_chat_table.sql"]:::db
  end

  %% External Services
  subgraph "External Services" 
    OpenAI["OpenAI GPT-4/3.5"]:::ext
    WeatherAPI["OpenWeather API"]:::ext
    NewsAPI["NewsAPI"]:::ext
  end

  %% Monorepo Config
  subgraph "Monorepo & Config" 
    Pnpm["pnpm-workspace.yaml"]:::config
    Turbo["turbo.json"]:::config
    WebPkg["apps/web/package.json"]:::config
    NextConfig["next.config.ts"]:::config
    Tailwind["tailwind.config.ts"]:::config
    TsConfig["tsconfig.json"]:::config
  end

  %% Relationships
  UIcomp -->|"interact"| ChatRoute
  Hook -->|"useChat calls"| ChatRoute
  ChatRoute -->|"calls ChatActions"| ChatActions
  ChatActions -->|"debug via"| ChatDebug
  ChatRoute -->|"auth lookup"| SupMiddleware
  SupMiddleware --> SupServer
  SupServer --> SupService
  SupService -->|"INSERT/SELECT"| DB
  ChatRoute -->|"invoke LangGraph"| AgentFactory
  AgentFactory --> ChatAgent
  AgentFactory --> WeatherAgent
  AgentFactory --> NewsAgent
  WeatherAgent -->|"Invoke weatherTool.invoke()"| WeatherTool
  NewsAgent -->|"Invoke newsTool.invoke()"| NewsTool
  WeatherTool -->|"API call"| WeatherAPI
  NewsTool -->|"API call"| NewsAPI
  ChatAgent -->|"uses LangSmith"| LangSmith
  ChatAgent --> MemoryMgr
  WeatherAgent --> MemoryMgr
  NewsAgent --> MemoryMgr
  MemoryMgr --> SupService
  SupService --> DB
  AgentFactory --> GraphConfig
  ChatRoute --> UIcomp
  UIcomp -->|"login/signup"| AuthAction
  AuthAction --> AuthConfirm
  AuthConfirm --> SupService
  SupService --> DB

  %% Click Events Frontend
  click UIcomp "https://github.com/natantavares-plank/chatbot/tree/main/apps/web/src/app"
  click Anim "https://github.com/natantavares-plank/chatbot/tree/main/apps/web/src/components/animation"
  click Hook "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/hooks/useChat.tsx"

  %% Click Events API
  click ChatRoute "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/app/api/chat/route.ts"
  click ChatActions "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/app/api/chat/actions.ts"
  click ChatDebug "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/app/api/chat/debug/route.ts"
  click AuthAction "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/app/auth/action.ts"
  click AuthConfirm "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/app/auth/confirm/route.ts"
  click SupMiddleware "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/supabase/middleware.ts"
  click SupServer "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/supabase/server.ts"
  click SupService "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/supabase/service.ts"

  %% Click Events AI Engine
  click GraphConfig "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/graph.ts"
  click AgentFactory "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/agent-factory.ts"
  click ChatAgent "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/agents/chat.agent.ts"
  click WeatherAgent "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/agents/weather.agent.ts"
  click NewsAgent "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/agents/news.agent.ts"
  click LangSmith "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/langsmith.ts"
  click MemoryMgr "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/memory-manager.ts"
  click WeatherTool "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/tools/weather.tool.ts"
  click NewsTool "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/src/lib/langgraph/tools/news.tool.ts"

  %% Click Events Database
  click Config "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/supabase/config.toml"
  click Mig1 "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/supabase/migrations/20250805131738_create_chat_tables.sql"
  click Mig2 "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/supabase/migrations/20250806175503_fix_summaries_unique_constraint.sql"
  click Mig3 "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/supabase/migrations/20250811183543_adds_agent_at_messages_table.sql"
  click Mig4 "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/supabase/migrations/20250814210805_adds_turn_column_at_chat_table.sql"

  %% Click Events Monorepo
  click Pnpm "https://github.com/natantavares-plank/chatbot/blob/main/pnpm-workspace.yaml"
  click Turbo "https://github.com/natantavares-plank/chatbot/blob/main/turbo.json"
  click WebPkg "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/package.json"
  click NextConfig "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/next.config.ts"
  click Tailwind "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/tailwind.config.ts"
  click TsConfig "https://github.com/natantavares-plank/chatbot/blob/main/apps/web/tsconfig.json"

  %% Styles
  classDef frontend fill:#cce4f7,stroke:#0366d6,stroke-width:1px
  classDef api fill:#e0f7e9,stroke:#028f60,stroke-width:1px
  classDef ai fill:#d1e8c4,stroke:#2f855a,stroke-width:1px
  classDef db fill:#ffe4b2,stroke:#dd6b20,stroke-width:1px
  classDef ext fill:#e2e8f0,stroke:#718096,stroke-width:1px
  classDef config fill:#f0f4c3,stroke:#c0ca33,stroke-width:1px
```
