DEV Community

Cover image for Building an AI-Ready Contract Lifecycle Management (CLM) Platform with Next.js, FastAPI, and Tiptap
Andrey Soloduhin
Andrey Soloduhin

Posted on

Building an AI-Ready Contract Lifecycle Management (CLM) Platform with Next.js, FastAPI, and Tiptap

Managing contracts is traditionally a manual, error-prone, and legally tedious process. But from an engineering perspective, it’s a fascinating challenge: How do you build a system that is flexible enough for complex business logic, strict enough for legal compliance, and structured enough for AI to actually understand it?

Meet Ladnost, a scalable, AI-ready Contract Lifecycle Management (CLM) platform designed to automate the creation, approval, signing, and storage of contracts.

Here’s a deep dive into the architecture and engineering decisions behind it.


πŸ›  The Tech Stack

  • Frontend: Next.js (App Router), next-intl for centralized i18n, Tailwind CSS.
  • Backend: FastAPI (Python), PostgreSQL, SQLAlchemy.
  • Document Engine: Tiptap (headless WYSIWYG), markitdown for format conversion.
  • Infrastructure: Docker, Docker Compose, Nginx, pgAdmin.

🧠 1. AI-First Architecture (Not Just a Buzzword)

Most CLMs treat documents as opaque blobs of text. Ladnost treats them as structured data.

  • Dual Storage: Every document is saved as both tiptap-JSON (for AI parsing and engine operations) and the original file (for exact layout preservation and archiving).
  • YAML-Driven Templates: Form filling and template configuration can be driven entirely via YAML. This makes the platform natively compatible with LLMs, allowing AI agents to generate template structures and populate data without human intervention.
  • Computed Fields & Logic: Support for custom formulas, conditional visibility (AND/OR logic), and automatic recalculation across unlimited tables.

πŸ”Œ 2. Full-Stack Modular Plugin System

We wanted businesses to customize the platform without forking the core codebase.

  • Backend: The FastAPI loader automatically scans the ./plugins directory on startup. Each plugin registers its own API endpoints and hooks into a common Event Bus.
  • Frontend: During the Next.js build, a custom script scans the plugins folder and dynamically generates App Router routes (app/(plugins)) and component registries (lib/generatedPlugins.ts).
  • Monetization Ready: The architecture natively supports multi-tenancy and tariff/subscription systems, with payment gateways (like YooKassa) pluggable via modules.

πŸ“ 3. Advanced Document Editor & Universal Format Support

We built the editor on Tiptap to provide a familiar, MS Word-like UX while keeping it headless and extensible.

  • Version Control: Full history with rollback capabilities and clear diff-view highlighting.
  • Seamless Import/Export: Recognizes and converts DOCX, PDF, and RTF using markitdown, and exports ready-to-sign DOCX/PDF files.
  • Developer Quality of Life: Automatic Markdown recognition and conversion when pasting from the clipboard.

🀝 4. Enterprise Collaboration & Workflow

  • Routing: Supports both parallel and sequential approval workflows with automatic task generation.
  • Collaboration: Track Changes mode (visual highlighting), threaded comments with @mentions, and granular Role-Based Access Control (RBAC), including anonymous access links for external counterparties.
  • Notifications: Multi-channel system (email, in-app, webhooks).

πŸš€ Developer Experience: Up and Running in Minutes

We prioritized a frictionless local development experience. The entire stack spins up via Docker Compose:

# 1. Configure environment variables
.env
.env.docker
fastapi/.env.docker

# 2. Build and start
docker-compose up --build -d
Enter fullscreen mode Exit fullscreen mode

Access the frontend at http://localhost, pgAdmin at http://localhost:5050, and the FastAPI Swagger UI internally via Nginx.


πŸ’‘ Why This Matters

  • Reduced Time-to-Contract: Smart templates and automated routing eliminate legal routine.
  • Low TCO: The plugin system allows deep customization without modifying the core.
  • True AI Readiness: Centralized localization (JSON-based) and structured data storage mean you can plug in an AI assistant for risk checking, auto-filling, and contract analysis on day one.

πŸ™Œ Get Involved!

We are actively looking for feedback, contributors, and plugin developers.

Top comments (0)