Getting started
Contract drafting
Turn the notes of a client intake meeting into a drafted contract with Pydantic AI, send it for e-signature on a Next.js signing page, and deploy it with Docker on your own Hostinger VPS.
In this course you build an app that turns the notes of a client intake meeting into a contract. You upload the notes, AI drafts the right contract section by section, and the client signs it online. The signed PDF lands in both inboxes.
It is a full-stack GenAI project, from a starter repo to a deployed app with a public signing page. FastAPI and Postgres do the work, Next.js draws the screens and the PDF, and everything runs on your own server. This guide accompanies a video made in collaboration with Hostinger.
The company
Pinewick Systems is a fictional three-person AI consultancy. It builds AI phone agents, support agents, automations, and internal tools for small businesses. Every deal starts with an intake meeting, and turning those notes into a contract takes the founder an evening per client. A wrong price or start date is expensive.
The app knows three contract types.
| Type | When | What the client signs |
|---|---|---|
fixed_price | A project with a fixed scope and one agreed total | A statement of work with milestones and a payment table |
retainer | Ongoing monthly work for a monthly fee | A monthly retainer with a terms box |
discovery | A short paid audit that ends in a roadmap | A one-page discovery and AI audit |
Anything else, such as a job offer or a call without a deal, goes to a person for review.
How it works
The first model call picks the contract type and extracts the client, the price, and the dates as structured output. Python then checks that the price really appears in the notes, and sends anything doubtful to review. A second model call writes each section with its own prompt. Prices, dates, and legal clauses never come from the model. The model proposes, code decides.
What you will build
- A FastAPI backend with one Postgres table, defined as a SQLAlchemy model, running in Docker.
- LLM step 1 with Pydantic AI and structured output, plus the Python checks on its answer.
- Contract templates as plain data, and LLM step 2 with one call per section.
- Background processing with a live status for the contract and every section.
- A Next.js admin page behind a password, and a public signing page with initials, a signature, and a signed PDF.
- Evals on ten sample intakes with known answers.
- A deployment with Docker Compose on a Hostinger VPS.
What you need
- Python 3.13, uv, Node 22 or later, pnpm, Docker, Git, and a GitHub account.
- A code editor with a coding agent, such as Cursor, Claude Code, or Codex.
- An Anthropic API key.
- A new Gmail account to send the emails from. Do not use your personal inbox.
- A Hostinger VPS. KVM 2 is the plan to pick, because Postgres and the Next.js build run on the server itself. Use the code
DAVEVPSat checkout for 10% off. The code works on your first purchase with a yearly plan, and the yearly plan is the best deal.
The repository
Repository: daveebbelaar/e2e-contract-drafting
The repo has three branches. main is the clean starting point. development is where the build happens, with a checkpoint commit after every stage. solution is the final result. Check out development to follow along, or solution to run the finished app.
The starter holds the client brief, the architecture, ten sample intakes, the environment template, and pinned dependencies for the backend and the frontend. The stylesheet and fonts of the signing page are in there too, so you never type CSS. The application code is absent, and building it is what this guide is for.
If you fall behind, diff your work against the solution, or point your coding agent at it and ask it to get you to the same point.
How to use this guide
- Every step names a file and gives its full code. Copy it with the copy button on the code block.
- Replace means overwrite the whole file. The highlighted lines are the ones that changed.
- Every page ends with a check. Do not move on until it passes.
Keep a coding agent such as Cursor, Claude Code, or Codex open for small things along the way, such as explaining a line, fixing an error, or checking a file against the guide. The build itself is copy and paste.
Explain what review_reasons in backend/app/ai.py does.I get this error when I upload notes: <paste the error>. Fix it.Not a beginner course
You should be comfortable with Python, some TypeScript, and the command line. If you are new to Python, start with the free Python course first.
Kept simple on purpose
There is no queue, no worker container, and no ORM in this build. One table holds everything about a contract, a background task in the FastAPI process runs the pipeline, and one password protects the admin page. The app runs on plain HTTP at the server's IP address, so you need no domain. The last page covers what a production version adds.