How ultramaroon-decency/larp works
Purpose and Entry Points
Larp is a full-stack AI research system: it accepts research questions, runs a multi-agent web-research pipeline, persists reports, and streams job progress. Backend startup is Larp-Backend/backend/app/main.py; its versioned HTTP/WebSocket API is assembled in Larp-Backend/backend/app/api/v1/router.py. The React client starts at Larp-Frontend/research-lab/src/main.tsx and composes the application in Larp-Frontend/research-lab/src/App.tsx.
API, Request Boundaries, and Access Control
REST endpoints expose research lifecycle, reports, authentication, users, payments, exports, agents, and health; live research updates use a dedicated WebSocket endpoint. Route handlers are in Larp-Backend/backend/app/api/v1/endpoints/research.py, Larp-Backend/backend/app/api/v1/endpoints/reports.py, and Larp-Backend/backend/app/api/v1/endpoints/websockets.py. Cross-cutting boundaries include JWT authentication/refresh handling, rate limiting, payment interception, CORS, correlation IDs, and centralized errors under Larp-Backend/backend/app/middleware/authentication.py, Larp-Backend/backend/app/middleware/payment.py, and Larp-Backend/backend/app/core/security.py.
Research Orchestration Pipeline
AgentManager is the control-plane coordinator for asynchronous research jobs, while research and report services own lifecycle/business operations. Core paths are Larp-Backend/backend/app/services/agent_manager.py, Larp-Backend/backend/app/services/research_service.py, and Larp-Backend/backend/app/services/report_service.py. The intended stage sequence is Planner → Search → Fact Checker → Citation → Report; job cancellation is a first-class lifecycle concern, reflected in Larp-Backend/backend/app/models/research_job.py.
AI Agent and Provider Layer
Agent interfaces and concrete implementations isolate orchestration from LLM/search vendors. The agent layer is rooted in Larp-Backend/backend/app/agents/base.py, with pipeline roles in Larp-Backend/backend/app/agents/planner.py, Larp-Backend/backend/app/agents/search.py, and Larp-Backend/backend/app/agents/real_agents.py. Groq supports planning/fact checking; Tavily supplies web search; report generation cascades across NVIDIA GPT-OSS, Groq, Gemini, OpenAI, and OpenRouter before a local fallback. This is the principal external-service boundary and should retain resilience/fallback behavior.
State, Persistence, and Eventing
PostgreSQL is accessed asynchronously through SQLAlchemy setup in Larp-Backend/backend/app/database.py. ORM entities distinguish research requests/jobs, reports, sources, history, users, payments, configured agents, and agent execution logs; key models are Larp-Backend/backend/app/models/research.py, Larp-Backend/backend/app/models/research_report.py, and Larp-Backend/backend/app/models/research_source.py. Repositories provide the data-access boundary, e.g. Larp-Backend/backend/app/repositories/research_job_repository.py. Alembic migrations define durable schema evolution in Larp-Backend/backend/alembic/versions/.
Redis supports PubSub progress propagation, caching, and JWT revocation. Its integration is at Larp-Backend/backend/app/redis.py; WebSocket connection/event management is in Larp-Backend/backend/app/core/websocket.py. The flow is API job creation → background agent execution → Redis progress events → WebSocket client; final artifacts are stored in PostgreSQL.
Frontend Research Workspace
The Vite/React TypeScript client is a research workspace rather than a generic API consumer. Larp-Frontend/research-lab/src/App.tsx coordinates state and WebSocket behavior; Larp-Frontend/research-lab/src/components/ChatResearchView.tsx presents live research and Markdown reports; Larp-Frontend/research-lab/src/components/SourcesPanel.tsx and Larp-Frontend/research-lab/src/components/SavedLibraryView.tsx expose citations and persisted history. It proxies API traffic to the backend during development.
Deployment and Payments
The backend is containerized and can run with local PostgreSQL/Redis via Larp-Backend/backend/Dockerfile, Larp-Backend/backend/docker-compose.yml, and Larp-Backend/backend/entrypoint.sh; Railway deployment metadata exists at Larp-Backend/backend/railway.json. x402 payment behavior spans backend payment APIs/services and a frontend-side orchestration prototype: Larp-Backend/backend/app/services/payment_service.py, Larp-Backend/backend/app/api/v1/endpoints/payments.py, and Larp-Frontend/research-lab/orchestrator/x402PaymentLayer.ts. An EVM wallet key enables real payment headers; absent credentials use simulated receipts.
Main entry points: App.tsx React workspace · authentication.py Security & payment boundary · agent_manager.py Agent manager · research_service.py Research service
Components 18
Research Workspace
- React workspace · Coordinates research state and WebSocket behavior.
Larp-Frontend/research-lab/src/App.tsx - Live research view · Displays live research and Markdown reports.
Larp-Frontend/research-lab/src/components/ChatResearchView.tsx - Sources & library · Exposes citations and saved report history.
Larp-Frontend/research-lab/src/components/SourcesPanel.tsx
Backend API
- Backend application · Application startup and middleware host.
Larp-Backend/backend/app/main.py - Versioned API · Assembles lifecycle, report, account, payment, and live-update APIs.
Larp-Backend/backend/app/api/v1/router.py - Research & report endpoints · Creates research jobs and serves reports.
Larp-Backend/backend/app/api/v1/endpoints/research.py - Live update endpoint
Larp-Backend/backend/app/api/v1/endpoints/websockets.py - Security & payment boundary · Applies JWT, rate, payment, CORS, correlation, and error controls.
Larp-Backend/backend/app/middleware/authentication.py
Research Pipeline
- Agent manager · Controls asynchronous execution and cancellation.
Larp-Backend/backend/app/services/agent_manager.py - Research service · Owns research lifecycle business operations.
Larp-Backend/backend/app/services/research_service.py - Planner → Search → Fact check → Citation · Vendor-isolated research stages.
Larp-Backend/backend/app/agents/base.py - Report generation · Cascades NVIDIA, Groq, Gemini, OpenAI, OpenRouter, then local fallback.
Larp-Backend/backend/app/agents/real_agents.py
State & Events
- Repository layer
Larp-Backend/backend/app/repositories/research_job_repository.py - PostgreSQL · Stores jobs, reports, sources, history, users, payments, and agent logs.
Larp-Backend/backend/app/database.py - Redis
Larp-Backend/backend/app/redis.py - WebSocket event manager · Propagates progress events to active clients.
Larp-Backend/backend/app/core/websocket.py
External Providers
- LLM and web-search vendors · Groq, Tavily, and report-generation providers.
- x402 payments · Uses real EVM payment headers or simulated receipts.
Larp-Backend/backend/app/services/payment_service.py
Connections 22
- React workspace → Live research view: renders
- React workspace → Sources & library: renders
- React workspace → Versioned API: REST requests
- React workspace → Live update endpoint: job updates
- Backend application → Versioned API: mounts
- Versioned API → Security & payment boundary: cross-cutting controls
- Security & payment boundary → Research & report endpoints: authorizes requests
- Security & payment boundary → x402 payments: payment interception
- Research & report endpoints → Research service: research lifecycle
- Research service → Agent manager: starts or cancels jobs
- Agent manager → Planner → Search → Fact check → Citation: executes stages
- Planner → Search → Fact check → Citation → Report generation: validated findings
- Planner → Search → Fact check → Citation → LLM and web-search vendors: LLM and web search
- Report generation → LLM and web-search vendors: fallback cascade
- Research service → Repository layer: persists lifecycle
- Report generation → Repository layer: stores artifacts
- Repository layer → PostgreSQL: async ORM
- Agent manager → Redis: publishes progress
- Redis → WebSocket event manager: PubSub events
- WebSocket event manager → Live update endpoint: delivers updates
- Live update endpoint → React workspace: streams progress
- Security & payment boundary → Redis: JWT revocation