Skip to content

Architecture Overview

Juca follows a hub architecture — a thin frontend with a lightweight orchestrator that delegates backend intelligence to external agents. The UI is composed entirely of typed Blocks rendered in a WorkCanvas.

Juca is built on five key patterns:

PatternImplementationPurpose
Server Components + Server ActionsNext.js 16 App RouterData fetching and mutations without client-side state management
Block System11 typed blocks, factory functionsUniform UI composition — every piece of content is a Block
Tool Registrysrc/lib/unified/tools/Routes user intents to specialized handler functions
Adapter Patternsrc/lib/adapters/ (planned)Unified interface for calling any backend agent (Valter, Leci, future)
Feature Flagssrc/lib/featureFlags.tsProgressive rollout of features via URL params or localStorage

The pre-pivot architecture was a fullstack monolith where Juca contained its own search engine, LLM pipeline, knowledge graph, and validation logic. That backend is being migrated to the Valter API, leaving Juca as a lean frontend hub.

graph TB
subgraph "Frontend — React 19"
AppShell["AppShell"]
Sidebar["SessionSidebar"]
PhaseRail["PhaseRail"]
Canvas["WorkCanvas"]
Composer["Composer"]
Blocks["Block Components<br/>(11 types)"]
SlideOver["SlideOver<br/>(Integra viewer)"]
end
subgraph "Server Layer — Next.js 16"
Actions["Server Actions<br/>briefing · session · message"]
Routes["API Routes<br/>(~55 endpoints)"]
SSE["SSE Stream<br/>/api/v2/stream"]
Auth["NextAuth v5<br/>Google OAuth + Email"]
end
subgraph "Orchestration"
Intent["Intent Detector"]
Tools["Tool Registry<br/>juris · ratio · analyzer<br/>compare · insights"]
Clarify["Clarification Policy"]
end
subgraph "External Agents"
Valter["Valter API<br/>STJ Jurisprudence<br/>Search · KG · LLM · Verify"]
Leci["Leci API<br/>Federal Legislation<br/>(future)"]
end
subgraph "Data Layer"
SQLite["SQLite<br/>Sessions · Blocks"]
end
AppShell --> Sidebar
AppShell --> PhaseRail
AppShell --> Canvas
Canvas --> Blocks
Canvas --> Composer
Canvas --> SlideOver
Composer --> Actions
Actions --> Intent
Intent --> Clarify
Intent --> Tools
Tools -->|"REST API"| Valter
Tools -.->|"REST API (future)"| Leci
Tools --> SSE
Actions --> SQLite
SSE --> Canvas
Auth --> Actions
Auth --> Routes

Juca has six entry points into the application:

Entry PointLocationPurpose
Web Appsrc/app/page.tsxServer Component that loads sessions and renders AppClient
API Routessrc/app/api/*/route.ts~55 REST endpoints (many transitional, moving to Valter)
SSE Streamsrc/app/api/v2/stream/route.tsReal-time progress streaming via Server-Sent Events
Server Actionssrc/actions/Briefing, session, message, and recalculate mutations
Instrumentationsrc/instrumentation.tsPre-warms caches (KG, Corpus, BM25) + OTel setup on startup
Dockerscripts/entrypoint.shContainer bootstrap for Railway deployment

A typical user interaction follows this path:

User types query in Composer
→ Server Action receives input
→ Intent Detector classifies the query
→ Tool Registry selects handler (e.g., JurisTool, AnalyzerTool)
→ Tool calls Valter REST API (/v1/retrieve, /v1/verify, etc.)
→ Response transformed by Block Factory
→ createDiagnosisData(), createPrecedentData(), etc.
→ Blocks persisted to SQLite via getBlocksDB().addBlock()
→ SSE streams block events to client
→ WorkCanvas renders new blocks in real-time

With the hub pivot, responsibilities are clearly split:

ConcernOwnerNotes
UI renderingJuca (React 19)Block System, WorkCanvas, Composer
Session persistenceJuca (SQLite)Sessions, blocks, user preferences. Will migrate to Postgres.
OrchestrationJuca (lightweight)Intent Detection, Tool Registry, Clarification Policy
SSE streamingJucaReal-time progress via /api/v2/stream
AuthenticationJucaNextAuth v5 (Google OAuth + magic links)
Legal searchValter/v1/retrieve, /v1/similar_cases
LLM processingValterMulti-model Generate → Criticize → Revise pipeline
Knowledge GraphValter/v1/graph/* (Neo4j Aura, 28.5K nodes, 207K edges)
Citation verificationValter/v1/verify
Federal legislationLeci (future)Not yet available — DB schema only

The architecture reflects several deliberate decisions. See Architecture Decision Records for full context:

DecisionChoiceRationale
Frontend hub over monolithHub + external agentsAvoid duplicating Valter’s capabilities in Juca
Block System over panels11 typed blocksUniform composition, easier to test, works with SSE
SQLite over PostgresSQLite for nowZero-config for single-dev; migrate at v0.6+
Server Actions over API callsNext.js Server ActionsFewer network hops, built-in auth, TypeScript end-to-end
Tailwind v4 CSS-firstDesign tokens in globals.cssAligns with Tailwind v4 best practices