SaaS Development AI software development Frontend development Backend development
Product

A legal document automation platform for small businesses and sole proprietors. Users select a template and answer a guided questionnaire. The system automatically populates document placeholders with customer information and includes relevant legal clauses based on their answers. Users can preview and edit their personalized documents before exporting them to Word.

Delivery

A searchable, filterable template catalog, a live document editor, a personal workspace, and Stripe billing for individual purchases and subscriptions. The platform also includes an admin workspace where AI converts existing legal templates into dynamic templates with automatically defined, editable variables, which legal teams can review and approve.

Devstark’s role

We handled full-stack development, from designing the catalog-to-document experience to building the template engine, billing and access rules, AI-powered template conversion, dynamic questionnaires, and automated document assembly.

The context

The client had a catalog of around 80 legal templates sold as individual files through WordPress and WooCommerce. Small businesses and sole proprietors could buy a document, but they still had to replace placeholders, work out which clauses applied, and check the finished file themselves. For the client, turning that catalog into a service meant making the templates easier to use while preserving the option to buy them individually.

We turned the catalog into a platform where Romanian small businesses and sole proprietors can buy individual templates or subscribe, complete a guided form, preview their document, and export it to Word.

AI converts existing static templates into dynamic templates by identifying placeholders and automatically defining editable variables. The system uses customer information to populate these placeholders and include applicable legal clauses based on predefined conditions. The legal team retains control over reviewing and approving templates.

The initial product was designed for Romania, with prices in RON and Romanian legal content. Romanian and English localization provides a foundation for future expansion into other European markets.

How we built it

Turning static templates into dynamic documents

Challenge:

The client's original templates used blank lines and underscores where customers were expected to fill in their details.

Manually converting a catalog of around 80 documents would require substantial effort from the legal team and introduce the risk of errors in variable definitions and conditional clauses.

Our approach:

We made the template the shared source for the form, preview, and export. Each template pairs Markdown content with a configuration that defines its fields, types, and conditions.

Rather than generating legal content from scratch, the AI assistant works with existing legal documents. It automatically identifies placeholders, creates named variables, and converts them into Liquid-style syntax. All generated variables remain editable.

Legal and content teams can import existing templates from Google Docs. The AI preparation pipeline follows three stages: preparation, review, and commit. The assistant returns structured JSON validated against Zod schemas. Administrators can compare the proposed Markdown with the list of variables, remove unnecessary suggestions, and rerun the preparation process.

Committing the results creates reusable global variables and updates the template's field configuration, while final saving remains a separate administrative action.

The system checks that placeholders match the field configuration, and administrators retain control over saving and publishing templates. A shared catalog of variables also lets the team reuse fields and localized labels across documents.

Templates are versioned and managed through draft, published, and archived states. AI call telemetry is collected through Langfuse to support quality and latency monitoring.

AI legal document automation platform

Personalizing documents through conditional logic

Challenge:

A contract can require different clauses for a sole proprietor and a limited company, with another condition within a clause depending on the payment arrangement. The same rules also determine which questions the user needs to answer.

Our approach:

We built a client-side, Liquid-style template parser that uses stack-based matching and recursive processing to handle nested conditional blocks. The parser is connected to the form's visibility rules.

Typed fields also control how values appear in the final text, such as displaying a date in the expected format or using a readable label for a selected option.

The system collects customer information through a dynamic questionnaire, automatically populates document placeholders, and includes relevant legal clauses. Depending on whether the customer is an individual or a legal entity, their answers determine which sections appear in the document and which additional questions need to be answered. Once a template has been approved, variable substitution and clause selection are handled by deterministic rules without additional AI requests.

This lets the legal team manage variations within a single template and gives users a shorter questionnaire tailored to their situation, without requiring them to manually select clauses or replace placeholders.

AI legal document automation setup

Preserving purchases when subscriptions change

Challenge:

A customer might buy one template, subscribe later, and then let the subscription expire. The platform had to preserve access to the purchased template while ending access to templates available only through the subscription. An error in either direction could undermine customer trust and lead to billing disputes.

Our approach:

We gave each user a personal workspace that is automatically created during registration. The workspace maintains separate collections for accessible and individually purchased templates, allowing subscription-only access to be revoked without affecting previous purchases.

Stripe webhook handlers synchronize payment records, subscription status, and template access while triggering email confirmations. Individually purchased templates remain available after a subscription ends.

The catalog reflects what the customer can do with each template, showing whether they can use it or need to purchase access. Customers can also manage their subscription and review payment history from their account.

Subscription plans define document creation limits, which are displayed in the user's personal dashboard.

Purchases confirmation block AI legal document automationBilling subscription AI legal document automation

Making the document visible before download

Challenge:

Users needed to understand how their answers changed a long document with dozens of fields and conditional clauses. Sending every field update to the server would introduce unnecessary latency into the document-editing experience.

Our approach:

When a customer creates a document, the system copies the template content and field configuration into an individual document instance, which stores the customer's field values within their personal workspace.

The editor renders the preview in the browser as users type or select an answer. It highlights missing values, and clicking one in the preview takes the user to the corresponding field.

Users can save their work and return to it from their workspace. When they request a download, the browser sends the completed Markdown to the server, where Pandoc converts it to an editable DOCX file.

Variable substitution and conditional rendering take place in the browser, while the more resource-intensive document conversion runs on the server only when requested.

Live preview AI legal document automation

What we delivered

We delivered a legal document automation platform that transforms static legal templates into interactive, personalized documents. AI automates placeholder identification and variable creation, while a rule-based document engine uses customer information to populate fields and assemble relevant legal clauses.

The platform connects template discovery, individual purchases, subscriptions, guided questionnaires, live document previews, and editable Word exports within a single workflow. Legal and content teams can manage, prepare, and review dynamic templates through a dedicated administrative workspace.

The frontend and backend share a unified TypeScript codebase built with Next.js and Payload CMS. The domain model separates templates, document instances, and personal workspaces, while centralized access rules restrict template management to administrators, document access to their owners, and the public catalog to published templates.

Technologies and their roles

  • Next.js, React, TypeScript, Tailwind CSS, and shadcn/ui for the catalog, workspace, live document editor, and user interface components.

  • Payload CMS and PostgreSQL for templates, documents, workspaces, and access control.

  • Stripe for one-time purchases, subscriptions, account billing, and webhook synchronization.

  • OpenAI, Vercel AI SDK, Zod, and Langfuse for AI-assisted variable extraction, dynamic template preparation, structured response validation, and AI observability.

  • Google Drive API and Pandoc for importing Google Docs as Markdown and exporting completed documents to Word.

  • next-intl and MailerSend for Romanian and English localization and purchase and subscription emails.

  • Vitest and Playwright for integration and end-to-end tests.

final product AI legal document automation platformAI legal document automation
cta image

AI RX med finder

An MVP SaaS service featuring an AI agent that will find your prescription medication in stock in pharmacies nearby.

AI-powered presentation generator for Google Slides

AI SaaS development connecting content generation, outline editing, templates, and subscriptions within a familiar presentation workflow.

AI platform for pharmacy compounding records and quality control

Learn how we developed a pharmacy document platform that turns compounding PDFs into searchable, editable records for professional quality review.

AI-powered events aggregator

An AI pipeline able to aggregate and validate hyper-local event data from thousands of sources, boosting onboarding from 1 client every two months to 3–5 per month with 95%+ data quality.

AI-assisted career guidance platform

A full-stack development of a career guidance platform connecting questionnaires, staged AI analysis, personalized reports, and organizational licensing.