Skip to content

yonal-io/lex-templates

Repository files navigation

LexTemplates - Legal Document Automation Platform

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.

Table of Contents

  1. The Problem
  2. The Solution
  3. Technology Stack
  4. Prerequisites
  5. First-Time Setup
  6. Development Workflow
  7. Project Structure
  8. Key Scripts
  9. Database Management
  10. Environment Variables
  11. Dependency Management
  12. Building for Production
  13. Docker Management
  14. Troubleshooting

The Problem

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.

The Solution

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.

Technology Stack

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.

Prerequisites

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.

First-Time Setup

To get the project running for the first time, clone the repository and use the automated setup script.

  1. 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
  2. Run the Setup Script: This single command installs dependencies, starts the Docker services, and prepares the database.

    ./setup.sh

Development Workflow

Once the initial setup is complete, use the following command for your daily development work:

pnpm dev

This 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.

Project Structure

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

Key Scripts

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

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.

  1. Apply Schema Changes:

    pnpm --filter @lex-templates/api run prisma:push

    This script is defined in packages/api/package.json.

  2. Generate Prisma Client:

    pnpm --filter @lex-templates/api run prisma:generate

    This script is also defined in packages/api/package.json.

Environment Variables

The project requires certain environment variables to be set up properly:

API Environment Variables

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"

Dependency Management

This project uses pnpm to manage dependencies within the workspaces.

  • Adding a dependency to a specific package: Use the --filter flag 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

Building for Production

To create a production-ready build of the application, run the following command from the root directory:

pnpm build

This command, defined in the root package.json, creates optimized builds in the dist folder of each package.

Docker Management

Starting Docker Services

To start the Docker services:

pnpm docker:up

Safely Stopping Docker Without Losing Data

⚠️ IMPORTANT: Using pnpm docker:down will stop containers AND delete all your data!

To safely stop Docker containers while preserving your data:

docker-compose stop

To start them again:

docker-compose start

You can add these commands as scripts in your package.json:

"scripts": {
  "docker:stop": "docker-compose stop",
  "docker:start": "docker-compose start"
}

When to Use Each Command

  • docker-compose stop or pnpm docker:stop: Use when you want to stop containers but keep your data
  • docker-compose down or pnpm docker:down: Use only when you want to completely reset your environment and delete all data

Troubleshooting

  • pnpm dev fails with database connection errors:
    • Ensure Docker Desktop is running.
    • Run pnpm docker:up to make sure the containers are started.
    • Check the service logs with pnpm docker:logs.
    • Verify that the .env file in packages/api has the correct database connection string.
  • Changes to shared-types not appearing:
    • The dev script for shared-types should automatically rebuild on changes. If not, you can manually rebuild it by running pnpm --filter @lex-templates/shared-types run build.
  • API health check:
    • You can verify the API is running correctly by accessing http://localhost:4000/api/health

About

LexTemplates - Legal Document Management Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors