DEV Community

mustapha Chaibi
mustapha Chaibi

Posted on

Building ContractPilot AI: A Serverless Multi-Agent Legal Copilot with Vercel and AWS Databases βš–οΈπŸš€

Legal contracts are the lifeblood of business, yet small business owners, freelancers, and startups sign agreements every week that they don't fully understand. Why? Because hiring a lawyer to review a single contract costs upwards of $300 to $500 per hour.

To bridge this gap, we built ContractPilot AIβ€”a serverless, multi-agent contract negotiation copilot that analyzes contracts, highlights risks, proposes redlined counter-offers, and allows users to interactively chat with their documents.

In this article, we'll dive into how we built this application under a weekend for the H0: Hack the Zero Stack hackathon, utilizing Vercel v0 for rapid frontend development and Amazon DynamoDB + Amazon Bedrock for a highly scalable, serverless backend.


The System Architecture

When designing ContractPilot AI, our primary goal was operational simplicity and cost-efficiency. We wanted a "Zero Stack" implementationβ€”meaning zero fixed server costs when the app is idle, combined with the capability to scale instantly to handle heavy burst traffic.

Here is how the components connect:

[User Browser]
      β”‚
      β–Ό (HTTPS / REST API)
[Vercel / Next.js Frontend]  ←───  Built & Iterated with v0.app
      β”‚
      β–Ό (HTTPS Proxy)
[AWS API Gateway HTTP API]
      β”‚
      β–Ό (Serverless Invocation)
[AWS Lambda β€” ASP.NET Core API]
      β”‚
      β”œβ”€β”€β–Ί [Amazon S3] β€” Stores uploaded PDF/DOCX files
      β”‚
      β”œβ”€β”€β–Ί [Multi-Agent Orchestrator] ──► [Amazon Bedrock] (Nova Lite)
      β”‚
      └──► [Amazon DynamoDB] (Single-Table / Serverless Scaling)
Enter fullscreen mode Exit fullscreen mode

🎨 The Frontend: Vercel v0 + Next.js

Building data-dense dashboards and chat interfaces from scratch can take days of layout and design iterations. To solve this, we used Vercel v0.

By describing our dashboard requirements in plain English, v0 scaffolded a modern, premium user interface including:

  • A clean drag-and-drop file upload zone.
  • A visual 0-100 risk score gauge.
  • An interactive clause risk explorer with accordion panels.
  • A clean, responsive chat panel to interact with the contract.

We exported these components into a Next.js 14 project and deployed them to Vercel with zero configuration.


βš™οΈ The Backend: ASP.NET Core on AWS Lambda

Our REST API and agent orchestration layer are built using ASP.NET Core (.NET 9). To keep it serverless, we compiled the API as a self-contained runtime (provided.al2023) and deployed it directly to AWS Lambda behind AWS API Gateway.

This serverless execution model means we only pay for compute when a user uploads a contract, keeping idle costs at exactly $0.


πŸ—„οΈ Database: Amazon DynamoDB

We chose Amazon DynamoDB as our primary database because its fully serverless, pay-per-use scaling model aligns perfectly with bursty AI workloads.

Data Model & Tables:

  1. contractpilot_contracts: Stores document metadata, overall risk score, summary, and lists of highlighted clauses.
  2. contractpilot_chat_messages: Maintains the history of interactive user messages per contract session.
  3. contractpilot_agent_logs: Logs performance and token statistics for each analysis run.

Using the official AWSSDK.DynamoDBv2 library, the .NET backend fetches and stores data with sub-10ms query latencies.


🧠 AI Layer: Multi-Agent Amazon Bedrock (Nova Lite)

ContractPilot AI uses Amazon Bedrock with the Amazon Nova Lite foundation model (amazon.nova-lite-v1:0) to run five specialized legal agents concurrently:

  1. Legal Analyst: Flags problematic clauses and legal terms.
  2. Risk Assessor: Computes risk levels and scores.
  3. Compliance Checker: Verifies alignment with regulations like GDPR.
  4. Negotiation Strategist: Generates redlined counter-proposals with alternative wordings.
  5. Summary Agent: Writes a 5-minute executive summary.

API Optimization:

To minimize cost and latency, our backend consolidates these agent calls into a single structured schema prompt. The model returns typed JSON that matches our backend C# records perfectly, reducing inference time and cost by 4x.


πŸ’‘ What We Learned

  1. Serverless AI is highly cost-effective: Running the Bedrock Nova Lite model costs less than $0.01 per contract analysis. Paired with DynamoDB and Lambda, our fixed monthly infrastructure cost is exactly $0.
  2. v0.app changes the UI workflow: Scaffolding UI in natural language allows developers to spend 90% of their time on backend orchestration and database patterns rather than styling CSS.

🎁 Hackathon Disclaimer

I created this piece of content for the purposes of entering the H0: Hack the Zero Stack hackathon. #H0Hackathon

Top comments (0)