How jpcuencat/ucacue-analitica works
Purpose and Runtime Entry Points
This repository delivers UCACUE’s academic-analytics conversational assistant: an embeddable Next.js widget that answers enrollment/matriculation questions using an OpenAI tool-calling agent and UCACUE data. Backend graph serving is configured by langgraph.json and composed in langgraph_server.py; local/container startup uses entrypoint-langgraph.sh and scripts/dev-up.sh. The production UI starts at frontend/app/page.tsx; the iframe demonstration is frontend/public/widget-demo.html.
Agent Graph and Composition Root
langgraph_server.py is the sole composition root: it builds the LangGraph LLM↔tool loop, injects concrete data adapters, system guidance, and checkpoint persistence. The graph uses LangChain ChatOpenAI and OpenAI via OPENAI_API_KEY; src/agent/playbook.md supplies per-turn analyst guidance. This is the production reasoning boundary: the frontend does not directly invoke academic-data services.
Paths: langgraph_server.py, langgraph.json, src/agent/playbook.md.
Domain Contracts and Anti-Corruption Boundary
The domain layer defines typed contracts and normalization independently of LangGraph, HTTP, or database concerns. Tools depend on data ports rather than adapter implementations, preserving swapability between live UCACUE API access and memory-backed behavior.
Paths: src/domain/puertos.py, src/domain/normalizacion.py, src/infrastructure/memoria.py.
Academic Data Access and Tool Use Cases
Seven LangChain tools implement the application-facing academic queries. They consume the domain port and return Result-style outcomes rather than propagating exceptions. The real adapter translates calls to the external UCACUE academic API hosted in Azure, authenticated/configured through UCACUE_API_KEY and UCACUE_API_URL; its expected service contract is documented in docs/openapi.yaml.
Paths: src/tools/ucacue_tools.py, src/infrastructure/ucacue_api.py, docs/openapi.yaml.
Widget, Frontend API, and Conversation Flow
The Next.js 15 App Router frontend renders chat messages, tool results, and charts, and is designed for cross-site iframe embedding. The primary path is user → widget → Next.js LangGraph proxy → graph/tools → UCACUE API. The frontend also owns thread endpoints and client-side thread integration, separating UI/session concerns from agent execution.
Paths: frontend/components/Chat.tsx, frontend/components/ChartBlock.tsx, frontend/app/api/threads/route.ts, frontend/lib/threads-client.ts.
Identity, Persistence, and Security Boundaries
Frontend authentication is JWT-based, with login and required password-change flows. PostgreSQL persists users and thread metadata; LangGraph checkpoint data is persisted separately. Request security and rate limiting sit at the Next.js boundary, while middleware protects routed frontend access.
Paths: frontend/lib/auth.ts, frontend/lib/db.ts, frontend/lib/request-security.ts, frontend/middleware.ts.
Deployment and Evaluation
Docker Compose deploys PostgreSQL, LangGraph, frontend, and Cloudflare tunnel infrastructure; service definitions and persistent volumes are centralized in docker-compose.yml. A separate evaluation-only agent/harness runs LangSmith datasets and evaluators; it is not the production UI path.
Paths: docker-compose.yml, Dockerfile.langgraph, evaluate.py, src/evaluation/evaluators.py.
Main entry points: langgraph_server.py LangGraph server · puertos.py Academic data ports · Chat.tsx Chat widget · docker-compose.yml Compose deployment
Components 21
Embeddable frontend
Next.js widget, sessions, and request boundary.
- Chat widget · Embeddable chat interface with messages and tool output.
frontend/components/Chat.tsx - Chart rendering
frontend/components/ChartBlock.tsx - Thread endpoints · Owns frontend thread metadata endpoints.
frontend/app/api/threads/route.ts - Thread client
frontend/lib/threads-client.ts - JWT authentication · Includes login and required password-change flows.
frontend/lib/auth.ts - Request security · Applies request protection and rate limiting.
frontend/lib/request-security.ts - Route middleware · Protects routed frontend access.
frontend/middleware.ts - Users and threads DB · Persists users and thread metadata.
frontend/lib/db.ts
Production agent
LangGraph reasoning and academic tool loop.
- LangGraph server · Builds the LLM-to-tool loop and injects production dependencies.
langgraph_server.py - Analyst playbook · Per-turn guidance for the agent.
src/agent/playbook.md - Academic query tools · Seven Result-style use cases for academic questions.
src/tools/ucacue_tools.py - Agent checkpoints · Separately persists graph checkpoint state.
Academic data
Domain ports and live UCACUE integration.
- Academic data ports · Typed adapter-independent contracts for tools.
src/domain/puertos.py - Domain normalization
src/domain/normalizacion.py - UCACUE API adapter · Uses UCACUE API credentials to translate port calls.
src/infrastructure/ucacue_api.py - UCACUE academic API · Azure-hosted academic data service.
docs/openapi.yaml - Memory adapter · Swappable memory-backed port implementation.
src/infrastructure/memoria.py
Deployment and evaluation
Runtime packaging and offline quality checks.
- Compose deployment · Runs PostgreSQL, LangGraph, frontend, and Cloudflare tunnel.
docker-compose.yml - LangGraph image
Dockerfile.langgraph - Evaluation harness · Runs LangSmith datasets and evaluators outside the production path.
evaluate.py - Evaluators
src/evaluation/evaluators.py
Connections 20
- Chat widget → Chart rendering: renders
- Chat widget → Thread client: uses
- Thread client → Thread endpoints: manages threads
- Thread endpoints → Users and threads DB: persists metadata
- Route middleware → JWT authentication: enforces access
- Request security → Chat widget: protects requests
- Chat widget → LangGraph server: proxies conversations
- LangGraph server → Analyst playbook: loads guidance
- LangGraph server → Academic query tools: invokes
- LangGraph server → Agent checkpoints: persists state
- Academic query tools → Academic data ports: depends on
- Academic data ports → Domain normalization: normalizes data
- Academic data ports → UCACUE API adapter: implemented by
- Academic data ports → Memory adapter: implemented by
- UCACUE API adapter → UCACUE academic API: calls
- Compose deployment → Users and threads DB: runs PostgreSQL
- Compose deployment → LangGraph server: runs service
- Compose deployment → LangGraph image: builds
- Evaluation harness → Evaluators: uses
- Evaluation harness → LangGraph server: evaluates separately