Skip to content

Architecture

How the studio is built: Next.js frontend, Django API, agent orchestration, and sandboxed execution — with a SELECT-only, RBAC- and PII-aware data path.

System Overview

canTrust is built on a modern, containerized architecture designed for security, scalability, and low-latency AI interactions.

Frontend

The user-facing application is built with Next.js and React, delivering a fast, responsive single-page experience. Real-time streaming of AI responses uses Server-Sent Events (SSE) for instant feedback during analysis.

Backend API

The core API is powered by Django REST Framework, handling authentication, data source management, conversation orchestration, billing enforcement, and the transformation engine. All endpoints are authenticated and rate-limited.

AI Orchestration

AI workflows are managed through LangGraph, which coordinates multi-step agent execution. The Deep Agent plans analysis steps, routes to appropriate tools (SQL generation, Python execution, document retrieval), and synthesizes results — all with full traceability.

Sandboxed Execution

All code execution (Python, SQL) happens in isolated OpenSandboxcontainers. Each execution gets its own ephemeral environment with no access to the host system, other users' data, or the network. Containers are destroyed after execution completes.

Data Flow

  1. User sends a message — the frontend streams the request to the backend via SSE.
  2. Billing enforcement — quota checks (daily queries, monthly tokens, model access) are validated before processing.
  3. Agent orchestration — LangGraph breaks the request into steps: schema lookup, query generation, code execution, and synthesis.
  4. Sandboxed execution — SQL runs against the connected data source; Python runs in an isolated container.
  5. Response streaming — results, charts, and reasoning steps stream back to the frontend in real time.
  6. Persistence — the conversation, trace events, and token usage are stored for history, billing, and audit.

Security Model

  • Authentication — JWT-based with optional SSO (Google, SAML). All API endpoints require authentication.
  • Encryption — TLS in transit, AES-256 at rest for database credentials and sensitive fields.
  • Isolation — Code execution happens in disposable containers with no persistent state or network access.
  • Access control — Role-based permissions (owner, editor, viewer) on conversations and data sources.
  • Audit trail — Every query, transformation, and agent run is logged with full input/output traces.
  • SQL validation — All data transformations pass through AST-based SQL parsing that enforces a strict statement-type allowlist.

Infrastructure

canTrust deploys as a set of Docker containers orchestrated with Docker Compose. The stack includes the Next.js frontend, Django API, LiteLLM proxy for model routing, OpenSandbox for code execution, and an observability stack (OpenTelemetry + Aspire Dashboard) for monitoring.