# organizacao-dukamp/ia-dukamp architecture

> Architecture diagram of the GitHub repository organizacao-dukamp/ia-dukamp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/organizacao-dukamp/ia-dukamp
- Repository: https://github.com/organizacao-dukamp/ia-dukamp

## Overview

TPEC-IA is a Brazilian livestock-focused AI assistant with an institutional landing page and WhatsApp as its user-facing channel. The documented message workflow runs from the WhatsApp webhook through the private backend and conversation handling into the chat core, which combines internal data and RAG with optional current-web research before producing one reply. The product also includes weather-aware answers, media analysis, market quotes, a read-only DuKamp catalog integration, and authenticated administration for knowledge, products, AI health, and quotes. Some subsystem links are documented only at a high level; unverified connections are dashed.

Main entry points: [`src/lib/chat/core.server.ts`](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/core.server.ts) (Chat core), [`src/integrations/supabase/client.server.ts`](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/integrations/supabase/client.server.ts) (TPEC Supabase client), [`src/lib/whatsapp/backend.server.ts`](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/backend.server.ts) (WhatsApp backend), [`src/lib/chat/query-router.server.ts`](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/query-router.server.ts) (Query and intent routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User channels"]
  node_landing["Institutional landing<br/>[index.tsx]"]
  node_whatsapp_route["WhatsApp webhook<br/>[whatsapp.ts]"]
  node_whatsapp_http["WhatsApp HTTP handler"]
  node_whatsapp_backend["WhatsApp backend<br/>[backend.server.ts]"]
  node_conversation["Conversation handling"]
  node_media["Media processing<br/>[media.server.ts]"]
end

subgraph group_assistant["Assistant runtime"]
  node_chat_core["Chat core<br/>[core.server.ts]"]
  node_query_router["Query and intent routing"]
  node_ai_orchestrator["AI orchestration"]
  node_ai_providers["Model providers"]
  node_weather["Weather intelligence"]
end

subgraph group_knowledge["Knowledge and data"]
  node_rag["Knowledge retrieval<br/>[search.server.ts]"]
  node_rag_ingest["Knowledge ingestion<br/>[ingest.server.ts]"]
  node_dukamp_knowledge["DuKamp knowledge tools<br/>[dukamp-package.ts]"]
  node_market_quotes["Livestock quotes"]
  node_market_data["Market data<br/>[market.server.ts]"]
  node_market_ingestion["Market ingestion<br/>[ingest.server.ts]"]
  node_site_lookup["DuKamp catalog lookup"]
  node_supabase_admin[("TPEC Supabase client<br/>[client.server.ts]")]
  node_supabase_site[("DuKamp Supabase client")]
end

subgraph group_operations["Operations and admin"]
  node_admin_auth["Admin access<br/>[auth-middleware.ts]"]
  node_knowledge_admin["Knowledge admin"]
  node_product_admin["Product admin<br/>[admin.produtos.tsx]"]
  node_ai_admin["AI health admin<br/>[admin.ia.tsx]"]
  node_quote_admin["Quote admin<br/>[admin.cotacoes.tsx]"]
  node_market_endpoint["Market ingest endpoint<br/>[market-ingest.ts]"]
end

node_producer(("Producer"))
node_meta{{"Meta WhatsApp"}}

node_producer -->|"views"| node_landing
node_landing -->|"opens conversation"| node_meta
node_meta -->|"posts message"| node_whatsapp_route
node_whatsapp_route -->|"dispatches"| node_whatsapp_http
node_whatsapp_http -->|"dispatches"| node_whatsapp_backend
node_whatsapp_backend -->|"handles conversation"| node_conversation
node_whatsapp_backend -->|"calls core"| node_chat_core
node_whatsapp_backend -.->|"processes media"| node_media
node_chat_core -.->|"routes queries"| node_query_router
node_chat_core -->|"retrieves evidence"| node_rag
node_chat_core -.->|"generates answer"| node_ai_orchestrator
node_ai_orchestrator -.->|"uses models"| node_ai_providers
node_chat_core -.->|"handles weather"| node_weather
node_rag_ingest -.->|"stores embeddings"| node_supabase_admin
node_rag -.->|"reads knowledge"| node_supabase_admin
node_market_ingestion -->|"writes quotes"| node_market_data
node_market_ingestion -->|"persists data"| node_supabase_admin
node_market_endpoint -->|"dispatches sync"| node_market_ingestion
node_market_endpoint -->|"dispatches quotes"| node_market_quotes
node_market_quotes -.->|"reads quotes"| node_supabase_admin
node_query_router -->|"checks market intent"| node_market_data
node_query_router -->|"checks market intent"| node_market_quotes
node_query_router -->|"looks up catalog"| node_site_lookup
node_site_lookup -.->|"reads public data"| node_supabase_site
node_knowledge_admin -.->|"manages ingestion"| node_rag_ingest
node_knowledge_admin -->|"manages packages"| node_dukamp_knowledge
node_admin_auth -.->|"authenticates users"| node_supabase_admin
node_product_admin -.->|"manages catalog"| node_site_lookup
node_ai_admin -.->|"checks AI health"| node_ai_orchestrator
node_quote_admin -->|"views quotes"| node_market_quotes

click node_landing "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/index.tsx"
click node_whatsapp_route "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/api/public/whatsapp.ts"
click node_whatsapp_http "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/enhanced-http.server.ts"
click node_whatsapp_backend "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/backend.server.ts"
click node_conversation "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/conversation.server.ts"
click node_media "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/media.server.ts"
click node_chat_core "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/core.server.ts"
click node_query_router "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/query-router.server.ts"
click node_ai_orchestrator "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/ai/orchestrator.server.ts"
click node_ai_providers "https://github.com/organizacao-dukamp/ia-dukamp/tree/main/src/lib/ai/providers"
click node_weather "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/weather-intelligence.server.ts"
click node_rag "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/rag/search.server.ts"
click node_rag_ingest "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/rag/ingest.server.ts"
click node_dukamp_knowledge "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/rag/dukamp-package.ts"
click node_market_quotes "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/market/livestock.server.ts"
click node_market_data "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/market/market.server.ts"
click node_market_ingestion "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/market/ingest.server.ts"
click node_site_lookup "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/site/site-lookup.server.ts"
click node_supabase_admin "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/integrations/supabase/client.server.ts"
click node_supabase_site "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/site/site-client.server.ts"
click node_admin_auth "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/integrations/supabase/auth-middleware.ts"
click node_knowledge_admin "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.base-conhecimento.tsx"
click node_product_admin "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.produtos.tsx"
click node_ai_admin "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.ia.tsx"
click node_quote_admin "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.cotacoes.tsx"
click node_market_endpoint "https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/api/public/market-ingest.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_landing,node_whatsapp_route,node_whatsapp_http,node_whatsapp_backend,node_conversation,node_media toneBlue
class node_chat_core,node_query_router,node_ai_orchestrator,node_ai_providers,node_weather toneAmber
class node_rag,node_rag_ingest,node_dukamp_knowledge,node_market_quotes,node_market_data,node_market_ingestion,node_site_lookup,node_supabase_admin,node_supabase_site toneMint
class node_admin_auth,node_knowledge_admin,node_product_admin,node_ai_admin,node_quote_admin,node_market_endpoint toneRose
class node_producer,node_meta toneIndigo
```

## Components

### User channels

- [Institutional landing](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/index.tsx): `src/routes/index.tsx`
- [WhatsApp webhook](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/api/public/whatsapp.ts): `src/routes/api/public/whatsapp.ts`
- [WhatsApp HTTP handler](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/enhanced-http.server.ts): `src/lib/whatsapp/enhanced-http.server.ts`
- [WhatsApp backend](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/backend.server.ts): `src/lib/whatsapp/backend.server.ts`
- [Conversation handling](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/conversation.server.ts): `src/lib/whatsapp/conversation.server.ts`
- [Media processing](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/whatsapp/media.server.ts): `src/lib/whatsapp/media.server.ts`

### Assistant runtime

- [Chat core](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/core.server.ts): `src/lib/chat/core.server.ts`
- [Query and intent routing](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/query-router.server.ts): `src/lib/chat/query-router.server.ts`
- [AI orchestration](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/ai/orchestrator.server.ts): `src/lib/ai/orchestrator.server.ts`
- [Model providers](https://github.com/organizacao-dukamp/ia-dukamp/tree/main/src/lib/ai/providers): `src/lib/ai/providers`
- [Weather intelligence](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/chat/weather-intelligence.server.ts): `src/lib/chat/weather-intelligence.server.ts`

### Knowledge and data

- [Knowledge retrieval](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/rag/search.server.ts): `src/lib/rag/search.server.ts`
- [Knowledge ingestion](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/rag/ingest.server.ts): `src/lib/rag/ingest.server.ts`
- [DuKamp knowledge tools](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/rag/dukamp-package.ts): `src/lib/rag/dukamp-package.ts`
- [Livestock quotes](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/market/livestock.server.ts): `src/lib/market/livestock.server.ts`
- [Market data](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/market/market.server.ts): `src/lib/market/market.server.ts`
- [Market ingestion](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/market/ingest.server.ts): `src/lib/market/ingest.server.ts`
- [DuKamp catalog lookup](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/site/site-lookup.server.ts): `src/lib/site/site-lookup.server.ts`
- [TPEC Supabase client](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/integrations/supabase/client.server.ts): `src/integrations/supabase/client.server.ts`
- [DuKamp Supabase client](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/lib/site/site-client.server.ts): `src/lib/site/site-client.server.ts`

### Operations and admin

- [Admin access](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/integrations/supabase/auth-middleware.ts): `src/integrations/supabase/auth-middleware.ts`
- [Knowledge admin](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.base-conhecimento.tsx): `src/routes/_authenticated/admin.base-conhecimento.tsx`
- [Product admin](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.produtos.tsx): `src/routes/_authenticated/admin.produtos.tsx`
- [AI health admin](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.ia.tsx): `src/routes/_authenticated/admin.ia.tsx`
- [Quote admin](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/_authenticated/admin.cotacoes.tsx): `src/routes/_authenticated/admin.cotacoes.tsx`
- [Market ingest endpoint](https://github.com/organizacao-dukamp/ia-dukamp/blob/main/src/routes/api/public/market-ingest.ts): `src/routes/api/public/market-ingest.ts`

### Other components

- **Producer**
- **Meta WhatsApp**

## Connections

- Producer → Institutional landing: views (evidence: `README.md`)
- Institutional landing → Meta WhatsApp: opens conversation (evidence: `README.md`)
- Meta WhatsApp → WhatsApp webhook: posts message (evidence: `README.md`)
- WhatsApp webhook → WhatsApp HTTP handler: dispatches (evidence: `README.md`)
- WhatsApp HTTP handler → WhatsApp backend: dispatches (evidence: `README.md`)
- WhatsApp backend → Conversation handling: handles conversation (evidence: `README.md`)
- WhatsApp backend → Chat core: calls core (evidence: `README.md`)
- WhatsApp backend → Media processing: processes media
- Chat core → Query and intent routing: routes queries
- Chat core → Knowledge retrieval: retrieves evidence (evidence: `README.md`)
- Chat core → AI orchestration: generates answer
- AI orchestration → Model providers: uses models
- Chat core → Weather intelligence: handles weather
- Knowledge ingestion → TPEC Supabase client: stores embeddings (evidence: `src/lib/rag/ingest.server.ts`)
- Knowledge retrieval → TPEC Supabase client: reads knowledge
- Market ingestion → Market data: writes quotes (evidence: `src/lib/market/ingest.server.ts`)
- Market ingestion → TPEC Supabase client: persists data (evidence: `src/lib/market/ingest.server.ts`)
- Market ingest endpoint → Market ingestion: dispatches sync (evidence: `src/routes/api/public/market-ingest.ts`)
- Market ingest endpoint → Livestock quotes: dispatches quotes (evidence: `src/routes/api/public/market-ingest.ts`)
- Livestock quotes → TPEC Supabase client: reads quotes
- Query and intent routing → Market data: checks market intent (evidence: `src/lib/chat/query-router.server.ts`)
- Query and intent routing → Livestock quotes: checks market intent (evidence: `src/lib/chat/query-router.server.ts`)
- Query and intent routing → DuKamp catalog lookup: looks up catalog (evidence: `src/lib/chat/query-router.server.ts`)
- DuKamp catalog lookup → DuKamp Supabase client: reads public data
- Knowledge admin → Knowledge ingestion: manages ingestion
- Knowledge admin → DuKamp knowledge tools: manages packages
- Admin access → TPEC Supabase client: authenticates users
- Product admin → DuKamp catalog lookup: manages catalog
- AI health admin → AI orchestration: checks AI health
- Quote admin → Livestock quotes: views quotes
