Skip to content

jamilahmedansari/main-main--final

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Talk-To-My-Lawyer

AI-Powered Legal Letter Generation Platform with Professional Attorney Review

A production-ready SaaS platform that generates professional legal letters with AI assistance and mandatory human oversight. The platform enables users to create legally sound letters through an AI-powered workflow with professional attorney review.


🎯 Overview

Talk-To-My-Lawyer is a three-tier platform designed for:

  • Subscribers: Generate professional legal letters with AI assistance
  • Employees: Earn commissions through referral coupons
  • Admins: Review, edit, and approve all letters before delivery

Core Workflow

Subscriber β†’ AI Draft Generation β†’ Admin Review & Editing β†’ Approval β†’ Subscriber Dashboard

πŸ—οΈ Tech Stack

Frontend

  • Framework: Next.js 15 with App Router (React 19)
  • Language: TypeScript (strict mode)
  • Styling: Tailwind CSS v4.1+ with custom design system
  • UI Components: shadcn/ui (Radix UI primitives)
  • Icons: Lucide React
  • Animations: Motion (Framer Motion)

Backend

  • Database: PostgreSQL via Supabase
  • Authentication: Supabase Auth with role-based access control
  • API: Next.js API Routes (App Router)
  • AI Integration: OpenAI GPT-4 Turbo via Vercel AI SDK
  • PDF Generation: jsPDF
  • Payments: Stripe (checkout + webhooks)

Infrastructure

  • Hosting: Vercel
  • Database: Supabase (PostgreSQL with RLS)
  • Package Manager: pnpm
  • Node.js: 18+

πŸš€ Quick Start

Prerequisites

  • Node.js 18 or higher
  • pnpm (recommended) or npm
  • Supabase account
  • OpenAI API key
  • Stripe account (optional for development)

Installation

# 1. Clone the repository
git clone <repository-url>
cd main-main--final

# 2. Install dependencies
pnpm install

# 3. Set up environment variables
cp .env.example .env.local
# Edit .env.local with your credentials

# 4. Run database migrations
# Use Supabase dashboard SQL editor to run scripts in order:
# scripts/001_setup_schema.sql
# scripts/002_setup_rls.sql
# ... (see CLAUDE.md for complete migration order)

# 5. Start development server
pnpm dev

Visit http://localhost:3000 to see the application.


πŸ’Ό Business Model

Pricing Plans

  • Free Trial: First letter free for new subscribers
  • Single Letter: $299 one-time purchase
  • Monthly Plan: $299/month (4 letters included)
  • Yearly Plan: $599/year (8 letters included)

Employee Program

  • Discount: 20% off for subscribers using employee coupons
  • Commission: Employees earn 5% commission on successful subscriptions

πŸ” User Roles & Access

Subscriber

  • Generate legal letters (AI-powered)
  • View letter status and history
  • Download approved letters as PDF
  • Manage subscription and billing
  • Access: /dashboard/letters, /dashboard/subscription

Employee

  • View personal referral coupon codes
  • Track commission earnings (5% of subscription amount)
  • Monitor coupon usage statistics
  • Employees are salespeople, NOT lawyers - they sell the service
  • CANNOT access letter content (security requirement enforced via RLS)
  • Access: /dashboard/coupons, /dashboard/commissions

Admin (Single Licensed Attorney)

  • There is exactly ONE admin who is the licensed attorney
  • Review all pending letters in the Review Center
  • Edit letters manually or improve with AI assistance
  • Approve or reject letters (attorney review)
  • View analytics and user management
  • PDF shows "reviewed by a licensed attorney" when admin approves
  • Access: /secure-admin-gateway/*

πŸ“ Letter Workflow

1. Generation (Subscriber)

Subscriber creates letter β†’ AI generates draft β†’ Status: "pending_review"

2. Review (Admin)

Admin opens letter β†’ Reviews/edits content β†’ Can use AI to improve β†’ Approves or Rejects

3. Delivery (Subscriber)

Letter approved β†’ Visible in subscriber dashboard β†’ Can download PDF or send via email

Letter Statuses

  • draft - Initial state, not submitted
  • generating - AI is creating the letter
  • pending_review - Waiting for admin review
  • under_review - Admin is reviewing
  • approved - Admin approved, ready for user
  • completed - Final delivered state
  • rejected - Admin rejected, needs revision
  • failed - Error occurred during generation

πŸ—„οΈ Database Schema

Core Tables

  • profiles - User accounts with role-based access (subscriber/employee/admin)
  • letters - Legal letters with AI drafts and admin-approved content
  • subscriptions - User subscription plans and letter allowances
  • employee_coupons - Employee referral discount codes (20% off)
  • commissions - Employee commission tracking (5% rate)
  • letter_audit_trail - Complete audit log of all letter actions

Row Level Security (RLS)

All tables have RLS policies enforced:

  • Subscribers can only access their own data
  • Employees cannot access letter content (business requirement)
  • Admins have full access to all data

πŸ›‘οΈ Security Features

  • βœ… Row Level Security on all database tables
  • βœ… Role-based access control
  • βœ… Admin portal with separate authentication
  • βœ… Complete audit trail for all letter changes
  • βœ… Server-side AI API key protection
  • βœ… Input validation and sanitization
  • βœ… Secure session management
  • βœ… Employee isolation from letter content

πŸ“š Documentation

Essential Reading

  1. CLAUDE.md - Comprehensive AI assistant guide and development workflows
  2. PLATFORM_ARCHITECTURE.md - Detailed system architecture and workflows
  3. DATABASE_FUNCTIONS.md - Database function reference
  4. START_APP.md - Quick start guide for development

Additional Guides


πŸ§ͺ Development

Available Commands

# Development
pnpm dev              # Start development server
pnpm build            # Build for production
pnpm start            # Start production server
pnpm lint             # Run ESLint

# Database
supabase start        # Start local Supabase
supabase db push      # Push migrations
supabase db reset     # Reset database

Environment Variables

See .env.example for all required environment variables.

Required for development:

  • NEXT_PUBLIC_SUPABASE_URL
  • NEXT_PUBLIC_SUPABASE_ANON_KEY
  • SUPABASE_SERVICE_ROLE_KEY
  • OPENAI_API_KEY
  • ADMIN_EMAIL / ADMIN_PASSWORD / ADMIN_PORTAL_KEY

Optional:

  • Stripe keys (for payment testing)
  • Redis/Upstash (for rate limiting)

πŸš€ Deployment

Vercel (Recommended)

  1. Connect repository to Vercel
  2. Add all environment variables
  3. Deploy

Environment Setup

# Production environment variables
NEXT_PUBLIC_APP_URL=https://www.talk-to-my-lawyer.com
NEXT_PUBLIC_SUPABASE_URL=<your-project>.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=<your-anon-key>
SUPABASE_SERVICE_ROLE_KEY=<your-service-key>
OPENAI_API_KEY=sk-...
STRIPE_SECRET_KEY=sk_live_...
# ... see PRODUCTION_CHECKLIST.md for complete list

🧩 Key Features

For Subscribers

  • βœ… Free first letter (no credit card required)
  • βœ… AI-powered letter generation (OpenAI GPT-4 Turbo)
  • βœ… Professional attorney review and editing
  • βœ… PDF generation and email delivery
  • βœ… Subscription management with letter allowances
  • βœ… Complete letter history and status tracking

For Employees

  • βœ… Automatic coupon code generation
  • βœ… 20% discount for referred subscribers
  • βœ… 5% commission on successful subscriptions
  • βœ… Real-time commission tracking dashboard
  • βœ… Usage statistics and analytics

For Admins

  • βœ… Dedicated admin portal (/secure-admin-gateway)
  • βœ… Review queue with FIFO ordering
  • βœ… AI-powered letter improvement tool
  • βœ… Manual editing with rich text editor
  • βœ… Approve/reject workflow with notes
  • βœ… Complete audit trail visibility
  • βœ… User and subscription management

πŸ”’ Data Privacy & Compliance

  • All user data protected with RLS policies
  • Employees cannot access subscriber letter content
  • Complete audit trail for all letter modifications
  • Secure admin authentication with dual-factor verification
  • GDPR-compliant data handling

πŸ› οΈ Project Structure

/
β”œβ”€β”€ app/                     # Next.js App Router
β”‚   β”œβ”€β”€ api/                 # API routes
β”‚   β”œβ”€β”€ auth/                # Authentication pages
β”‚   β”œβ”€β”€ dashboard/           # User dashboards
β”‚   β”œβ”€β”€ secure-admin-gateway/# Admin portal
β”‚   └── ...
β”œβ”€β”€ components/              # React components
β”‚   β”œβ”€β”€ admin/               # Admin-specific
β”‚   └── ui/                  # shadcn/ui components
β”œβ”€β”€ lib/                     # Utilities and helpers
β”‚   β”œβ”€β”€ auth/                # Authentication utilities
β”‚   └── supabase/            # Supabase configuration
β”œβ”€β”€ scripts/                 # Database migration scripts
β”œβ”€β”€ public/                  # Static assets
└── ...

🀝 Contributing

This is a production application. For development:

  1. Read CLAUDE.md for development guidelines
  2. Follow TypeScript strict mode requirements
  3. Ensure all tests pass before committing
  4. Follow security best practices
  5. Update documentation for any changes

πŸ“ž Support

For questions or issues:

  • Check documentation in CLAUDE.md and PLATFORM_ARCHITECTURE.md
  • Review the appropriate specialized guide
  • Consult database function reference in DATABASE_FUNCTIONS.md

πŸ“„ License

See LICENSE file for details.


βœ… Production Status

Current Status: Production-ready MVP

Completed:

  • βœ… Three-tier user system (subscriber/employee/admin)
  • βœ… AI letter generation (OpenAI GPT-4 Turbo)
  • βœ… Admin review and approval workflow
  • βœ… Free trial system
  • βœ… Subscription and payment integration
  • βœ… Employee coupon and commission system
  • βœ… Complete audit trail
  • βœ… Row Level Security
  • βœ… PDF generation
  • βœ… Email delivery

Next Phase:

  • Advanced analytics dashboard
  • Real-time notifications
  • Letter templates library
  • Multi-language support

Last Updated: December 2025 Version: 1.0.0 Production Domain: www.talk-to-my-lawyer.com

About

Talk-To-My-Lawyer: AI-powered legal letter SaaS with mandatory attorney review

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5