LexTemplates is a full-stack application designed to solve a critical efficiency problem in corporate law firms. It automates the generation of legal documents for business incorporations, saving significant time and reducing errors.
- The Problem
- The Solution
- Technology Stack
- Prerequisites
- First-Time Setup
- Development Workflow
- Project Structure
- Key Scripts
- Database Management
- Environment Variables
- Dependency Management
- Building for Production
- Docker Management
- Troubleshooting
In corporate law firms, paralegals spend countless hours on repetitive data entry for business incorporation documents, which can often exceed 24 pages. This manual process is prone to errors, leading to a lengthy back-and-forth review cycle with lawyers that can consume up to 10 hours per client.
LexTemplates automates this entire workflow. It provides a simple web form where a paralegal can enter client information once. The platform then automatically populates this information across the entire stack of legal documents, error-free. This eliminates redundant data entry, minimizes mistakes, and drastically reduces the time required to prepare documents for validation.
The platform is built using a modern and robust technology stack:
- Monorepo: Managed with pnpm workspaces for efficient code sharing and management.
- Backend: An Express.js API with Prisma ORM for database interactions.
- Frontend: A React application built with Vite for a fast and responsive user experience.
- Database: PostgreSQL for reliable and structured data storage.
- Cache: Redis for session management and performance enhancement.
- Containerization: Docker and Docker Compose to ensure a consistent and isolated development environment.
Before you begin, ensure you have the following installed on your system. The required versions are specified in the root package.json.
- Node.js: Version 20.0.0 or higher.
- pnpm: Version 8.0.0 or higher.
- Docker Desktop: Must be running before you start the setup process.
To get the project running for the first time, clone the repository and use the automated setup script.
-
Clone the Repository:
# Using SSH git clone git@github.com:yonal-io/lex-templates.git # OR using HTTPS git clone https://github.com/yonal-io/lex-templates.git cd lex-templates
-
Run the Setup Script: This single command installs dependencies, starts the Docker services, and prepares the database.
./setup.sh
Once the initial setup is complete, use the following command for your daily development work:
pnpm devThis command starts all development servers in parallel, as defined in the root package.json. The frontend will be available at http://localhost:3000 and the API at http://localhost:4000.
The project is a monorepo with a packages directory containing the different parts of the application.
lex-templates/
├── docker-compose.yml # Docker configuration for services
├── package.json # Root package.json with top-level scripts
├── pnpm-workspace.yaml # Defines the pnpm workspaces
├── setup.sh # The initial setup script
└── packages/
├── api/ # The backend Express.js application
├── web/ # The frontend React application
└── shared-types/ # Shared TypeScript types for the API and web packages
These scripts are run from the root of the project and are defined in package.json.
| Command | Description |
|---|---|
pnpm dev |
Starts all development servers concurrently. |
pnpm build |
Builds all packages, ensuring shared-types is built first. |
pnpm docker:up |
Starts the Docker services (postgres, redis) in detached mode. |
pnpm docker:down |
Stops the Docker services and removes the data volumes. |
pnpm docker:logs |
Tails the logs from the running Docker services. |
pnpm prisma:studio |
Starts the Prisma Studio to view and edit data in the database. |
Database management is handled by Prisma. The schema is located at packages/api/prisma/schema.prisma. To apply schema changes, use the following commands from the project root.
-
Apply Schema Changes:
pnpm --filter @lex-templates/api run prisma:push
This script is defined in
packages/api/package.json. -
Generate Prisma Client:
pnpm --filter @lex-templates/api run prisma:generate
This script is also defined in
packages/api/package.json.
The project requires certain environment variables to be set up properly:
Create a .env file in the packages/api directory with the following variables:
DATABASE_URL="postgresql://yonah:POSTGRES_PASSWORD_PLACEHOLDER@localhost:5432/lex_templates"
REDIS_URL="redis://localhost:6379"
PORT=4000
JWT_SECRET="your-super-secret-jwt-key-for-development"
This project uses pnpm to manage dependencies within the workspaces.
-
Adding a dependency to a specific package: Use the
--filterflag to target the correct package.# Example: Add 'axios' to the 'web' package pnpm --filter @lex-templates/web add axios # Example: Add 'bcryptjs' to the 'api' package pnpm --filter @lex-templates/api add bcryptjs
To create a production-ready build of the application, run the following command from the root directory:
pnpm buildThis command, defined in the root package.json, creates optimized builds in the dist folder of each package.
To start the Docker services:
pnpm docker:uppnpm docker:down will stop containers AND delete all your data!
To safely stop Docker containers while preserving your data:
docker-compose stopTo start them again:
docker-compose startYou can add these commands as scripts in your package.json:
"scripts": {
"docker:stop": "docker-compose stop",
"docker:start": "docker-compose start"
}docker-compose stoporpnpm docker:stop: Use when you want to stop containers but keep your datadocker-compose downorpnpm docker:down: Use only when you want to completely reset your environment and delete all data
pnpm devfails with database connection errors:- Ensure Docker Desktop is running.
- Run
pnpm docker:upto make sure the containers are started. - Check the service logs with
pnpm docker:logs. - Verify that the
.envfile inpackages/apihas the correct database connection string.
- Changes to
shared-typesnot appearing:- The
devscript forshared-typesshould automatically rebuild on changes. If not, you can manually rebuild it by runningpnpm --filter @lex-templates/shared-types run build.
- The
- API health check:
- You can verify the API is running correctly by accessing
http://localhost:4000/api/health
- You can verify the API is running correctly by accessing