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.
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
Subscriber β AI Draft Generation β Admin Review & Editing β Approval β Subscriber Dashboard
- 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)
- 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)
- Hosting: Vercel
- Database: Supabase (PostgreSQL with RLS)
- Package Manager: pnpm
- Node.js: 18+
- Node.js 18 or higher
- pnpm (recommended) or npm
- Supabase account
- OpenAI API key
- Stripe account (optional for development)
# 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 devVisit http://localhost:3000 to see the application.
- 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)
- Discount: 20% off for subscribers using employee coupons
- Commission: Employees earn 5% commission on successful subscriptions
- Generate legal letters (AI-powered)
- View letter status and history
- Download approved letters as PDF
- Manage subscription and billing
- Access:
/dashboard/letters,/dashboard/subscription
- 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
- 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/*
Subscriber creates letter β AI generates draft β Status: "pending_review"
Admin opens letter β Reviews/edits content β Can use AI to improve β Approves or Rejects
Letter approved β Visible in subscriber dashboard β Can download PDF or send via email
draft- Initial state, not submittedgenerating- AI is creating the letterpending_review- Waiting for admin reviewunder_review- Admin is reviewingapproved- Admin approved, ready for usercompleted- Final delivered staterejected- Admin rejected, needs revisionfailed- Error occurred during generation
- 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
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
- β 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
- CLAUDE.md - Comprehensive AI assistant guide and development workflows
- PLATFORM_ARCHITECTURE.md - Detailed system architecture and workflows
- DATABASE_FUNCTIONS.md - Database function reference
- START_APP.md - Quick start guide for development
- SETUP.md - Initial setup instructions
- SUPABASE_DEPLOYMENT.md - Supabase deployment guide
- SECURITY_CHECKLIST.md - Security guidelines
- MANUAL_QA_SCRIPT.md - Quality assurance testing
- PRODUCTION_CHECKLIST.md - Production deployment checklist
- FREE_TRIAL_IMPLEMENTATION.md - Free trial system details
# 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 databaseSee .env.example for all required environment variables.
Required for development:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEYOPENAI_API_KEYADMIN_EMAIL/ADMIN_PASSWORD/ADMIN_PORTAL_KEY
Optional:
- Stripe keys (for payment testing)
- Redis/Upstash (for rate limiting)
- Connect repository to Vercel
- Add all environment variables
- Deploy
# 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- β 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
- β Automatic coupon code generation
- β 20% discount for referred subscribers
- β 5% commission on successful subscriptions
- β Real-time commission tracking dashboard
- β Usage statistics and analytics
- β
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
- 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
/
βββ 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
βββ ...
This is a production application. For development:
- Read CLAUDE.md for development guidelines
- Follow TypeScript strict mode requirements
- Ensure all tests pass before committing
- Follow security best practices
- Update documentation for any changes
For questions or issues:
- Check documentation in
CLAUDE.mdandPLATFORM_ARCHITECTURE.md - Review the appropriate specialized guide
- Consult database function reference in
DATABASE_FUNCTIONS.md
See LICENSE file for details.
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