LexAI-AI-Courtroom-Debate-Simulator: LexAI: The Courtroom Simulator That Turns Argument Into a State Machine

A lean Node, MySQL, and vanilla JS stack coordinates judge, counsel, and advisor agents into a structured legal debate system that remembers, scores, and teaches.

6 to 8 min read • View on GitHub • More from Priyanshu-Rai01

A wide courtroom table reimagined as a mechanical control surface. A judge sits at one end like a gavel-shaped instrument panel, while counsel and advisor appear as smaller opposing stations. Argument cards feed into score dials, showing that the system turns debate into a measurable workflow rather than a freeform chat.
LexAI’s core idea is not a chatbot. It is a courtroom workflow with roles, memory, and scoring.
Key Takeaways

LexAI-AI-Courtroom-Debate-Simulator does not try to be a clever legal chatbot. It tries to be a legal process. That distinction changes everything: the app does not just answer, it stages a dispute, preserves the transcript, grades the argument, and feeds the result back into the next round.

Introducing LexAI - your autonomous open-source debate simulator. Witness AI agents lock horns, refine arguments, and present compelling cases with unparalleled precision.

Priyanshu Rai, Project Creator and Maintainer · Priyanshu Rai (@Priyanshu_Rai01) on X

Not a Chatbot, a Debate Engine

The easiest way to miss LexAI is to file it under “AI app.” It is more specific than that. It splits a single dispute into distinct roles, then makes each role contribute to a structured legal loop: user argument, judge response, advisor hint, score update, next turn.

That is why the project feels different from a normal assistant. A chatbot tries to be helpful in one stream of text. LexAI separates intent, opposition, and instruction. The result is closer to a simulator than a conversation window.

A close-up view of dialogue being transformed into structured records. Raw transcript slips into a filing tray, then splits into labeled cards for user, judge, counsel, and advisor before snapping into a ledger and dashboard. The image explains how the app converts conversation into durable case state and scores.
The hidden trick is conversion. LexAI turns freeform speech into records the system can reuse.

The Courtroom Is a Workflow

The user journey is simple on the surface. A case is loaded, a round begins, the user argues, the judge responds, and the system scores performance across multiple dimensions. Underneath, each turn is written back into session history so the next prompt is not blind.

A courtroom turn is not a one-off generation. It is a state transition with persistence at every step.

This matters because the model is not trusted to remember on its own. The app supplies memory from the outside. That makes the simulation stable enough to teach from, instead of drifting into generic legal talk.

How LexAI Keeps a Stateless Model Honest

The technical core is constraint. LexAI’s AI layer uses role-specific prompts and a strict JSON response format, so the output can be parsed, stored, and reused without fragile text scraping. That is the difference between a demo and a system.

async function callJsonCompletion({ prompt, schema }) {
  const response = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: prompt }],
    response_format: { type: "json_object" }
  });

  return JSON.parse(response.choices[0].message.content);
}

async function loadSessionContext(sessionId) {
  const session = await getSession(sessionId);
  const caseData = await getCase(session.case_id);
  const transcript = await getTranscript(sessionId);

  return {
    caseContent: caseData.content,
    history: transcript,
    currentRound: session.current_round
  };
}

The important move is not the specific model. It is the shape of the contract. The backend asks for structured fields, not prose, then writes those fields into the database as the source of truth.

That lets the next prompt rebuild context from durable records. In practice, the app manufactures memory by joining session data, case data, and transcript history before every new turn.

The Advisor Whisper Is the Secret Sauce

LexAI’s three-role design is what keeps the experience from collapsing into a generic duel. Judge and counsel are adversarial. Advisor is supportive. That split creates a teaching loop, not just a win-or-lose contest.

The advisor pattern is especially useful because it changes the emotional tone of the app. The user is not only challenged. They are coached. That makes the simulator feel closer to a training environment than a chat interface pretending to be a courtroom.

RoleBehaviorOutputWhy it matters
JudgeEvaluates the exchangeScores and feedbackCreates accountability
CounselPushes the opposing caseArgumentative responseForces rebuttal
AdvisorGuides the userStrategic hintsTurns debate into learning

Why the Schema Matters

LexAI’s database is not just storage. It is the memory system. The transcript, the round scores, and the user stats rollup all serve a single purpose: preserve the debate as a sequence of state changes, not an amorphous chat log.

That matters because stateful products need more than message history. They need normalized records that can support dashboards, scoring, and future context reconstruction. In LexAI, the schema is part of the product, not an implementation detail.

TableJobWhat it storesWhy it is useful
argumentsTranscript historyRole, content, roundRebuilds the debate
round_scoresPerformance trackingArgument strength, legal accuracy, rebuttal scoreMakes feedback explicit
user_statsRollup metricsTotals and strongest topicSupports the dashboard
sessionsCase stateCurrent round and session metadataKeeps the simulation moving

A Lean Stack With Strong Opinions

The stack is plain in a good way. Node and Express handle the API. MySQL holds the state. JWT and bcrypt cover auth. Vanilla JavaScript powers the frontend. Nothing here is decorative, and that restraint helps the product stay legible.

That choice also signals a product philosophy. LexAI is not chasing framework complexity. It is optimizing for a narrow workflow where the interesting problems are prompt control, persistence, and feedback. A smaller stack makes those trade-offs easier to see.

Where It Sits in the Landscape

LexAI is narrower than a general agent framework and more educational than a commercial legal product. It is not trying to solve every agent problem, and it is not trying to replace legal research tools. It is trying to simulate argument with enough structure that a user can improve inside the loop.

ToolPrimary purposeStrengthWeakness relative to LexAIBest use case
LexAICourtroom debate simulationRole-based scoring and memoryNarrower domainTraining, demos, experimentation
LangChainLLM application orchestrationFlexible building blocksNot opinionated about courtroom flowGeneral AI app development
AutoGPTAutonomous task executionBroad agent experimentationToo open-ended for structured debateAgent research and prototypes
Casetext / CoCounselLegal research assistancePractical practitioner workflowsNot a simulation environmentProfessional legal work
Generic chatbotOpen-ended conversationEasy to useNo persistent courtroom structureCasual Q&A

That comparison is the point. LexAI is not trying to win on breadth. It wins on specificity. By narrowing the interaction to a courtroom workflow, it can teach something the broader tools usually leave implicit.

Why This Pattern Scales Beyond Law

The real lesson here is portable. Any serious LLM product that needs progression, evaluation, and memory can borrow the same pattern: separate roles, constrain outputs, persist each turn, and score on dimensions that users can act on.

That applies to training systems, review tools, simulations, and decision support products. LexAI is interesting because it shows how far a small stack can go when the workflow is the product and the model is only one component of it.