mirror of
https://github.com/hanzoai/captable.git
synced 2026-10-16 14:21:29 +00:00
The Billing settings page opens billing.hanzo.ai to manage a subscription and pay.hanzo.ai for the plan catalog, each in a new tab. Both URLs live in src/constants/billing.ts and read NEXT_PUBLIC_BILLING_URL / NEXT_PUBLIC_PAY_URL when a deployment needs different hosts. The hosted surface owns payment state, so the app stores no products, prices, subscriptions or customers and serves no payment webhook.
8.0 KiB
8.0 KiB
Captable, Inc. - LLM Context
Overview
Captable, Inc. is an open-source cap table management platform designed as an alternative to Carta, Pulley, and AngelList. The platform provides comprehensive equity management, fundraising tools, and stakeholder communication features.
Tech Stack
- Framework: Next.js 14 (App Router) with TypeScript
- Database: PostgreSQL with Prisma ORM
- API: tRPC for type-safe APIs
- Authentication: NextAuth with Passkey support
- Styling: Tailwind CSS with shadcn/ui components
- Email: React Email with Nodemailer
- File Storage: AWS S3 compatible (Minio for local dev)
- Payments: hosted on billing.hanzo.ai / pay.hanzo.ai — the app only links out
- PDF: PDF-lib for generation, React-PDF for viewing
- Queue: pg-boss for job processing
- Monitoring: Sentry for error tracking
Core Features
1. Cap Table Management
- Share Classes: Common and Preferred shares with customizable terms
- Securities: Shares, Options (ISO/NSO/RSU), SAFEs, Convertible Notes
- Equity Plans: Employee stock option plans with vesting schedules
- Stakeholder Management: Individual and institutional investors, employees, advisors
2. Fundraising Tools
- SAFE Agreements: YC standard templates (Post-money cap, discount, MFN variants)
- Investment Tracking: Record investments with share issuance
- Convertible Notes: Support for various types (CCD, OCD, NOTE)
3. Document Management
- E-Signing: Full document signing workflow with templates and fields
- Data Rooms: Secure document sharing with access controls
- Document Storage: Secure file uploads with S3-compatible storage
4. Communication
- Investor Updates: Rich-text updates with public/private sharing
- Email Notifications: Automated emails for various workflows
5. Compliance & Security
- Audit Trail: Comprehensive activity logging
- RBAC: Role-based access control with custom roles
- Passkeys: WebAuthn support for passwordless authentication
- API Access: Token-based API access for integrations
Project Structure
src/
├── app/ # Next.js app router pages
│ ├── (authenticated)/ # Protected routes (dashboard, etc.)
│ ├── (unauthenticated)/ # Public routes (login, signup, etc.)
│ ├── (documents)/ # Document-related pages
│ └── api/ # API routes (auth, trpc)
├── components/ # React components organized by feature
├── server/ # Server-side utilities and services
├── trpc/ # tRPC setup and routers
│ ├── api/ # API configuration
│ └── routers/ # Feature-specific routers
├── lib/ # Utility functions and constants
├── providers/ # React context providers
├── hooks/ # Custom React hooks
├── emails/ # Email templates
├── jobs/ # Background job handlers
└── schema/ # Validation schemas
Database Schema
Core Entities
- Company: Central entity representing an organization
- User: System users with authentication
- Member: Company members with roles and permissions
- Stakeholder: Equity holders (investors, employees, etc.)
Securities
- ShareClass: Define share types and terms
- Share: Issued shares with vesting
- Option: Stock options with exercise terms
- Safe: SAFE agreements
- ConvertibleNote: Convertible debt instruments
- EquityPlan: Stock option plans
Documents
- Document: File storage references
- Template: E-sign document templates
- TemplateField: Form fields for e-signing
- DataRoom: Secure document collections
Supporting
- Audit: Activity log entries
- Update: Investor updates
- BankAccount: Company bank accounts
Key API Routes (tRPC)
Authentication & Security
auth: Login, signup, password resetpasskey: WebAuthn registration/authenticationsecurity: Password managementaccessToken: API token management
Company Management
company: Company CRUD operationsmember: Team member managementrbac: Role and permission managementbankAccounts: Bank account management
Securities Management
shareClass: Share class configurationequityPlan: Equity plan managementsecurities: Shares and options issuancesafe: SAFE agreement managementstakeholder: Stakeholder CRUD
Documents & Communication
document: File upload/managementtemplate: E-sign template managementtemplateField: E-sign field configurationdataRoom: Data room managementupdate: Investor update creation/sharing
Other
audit: Audit log accessbucket: File storage operationscommon: Shared utilities
Development Patterns
Authentication Flow
- Uses NextAuth with custom adapters
- Supports email/password and passkey authentication
- Session-based authentication with JWT tokens
- Member-based access control (users can be members of multiple companies)
File Upload Pattern
- Client requests presigned URL from bucket router
- Direct upload to S3-compatible storage
- Reference stored in database
- Access controlled through application logic
E-Signing Workflow
- Upload PDF document
- Create template with recipients
- Add form fields (signature, text, date, etc.)
- Send to recipients
- Track signing progress
- Generate completed document
Background Jobs
Uses pg-boss for job queuing:
- Email sending (verification, invites, notifications)
- PDF generation for completed documents
- Async processing for heavy operations
Environment Configuration
Key environment variables:
DATABASE_URL: PostgreSQL connectionNEXTAUTH_URL/SECRET: Authentication configEMAIL_*: SMTP configurationUPLOAD_*: S3-compatible storage configNEXT_PUBLIC_BILLING_URL/NEXT_PUBLIC_PAY_URL: override the hosted billing and plan pages (defaults insrc/constants/billing.ts)NEXT_PUBLIC_*: Client-side variables
Security Considerations
- Row-Level Security: Enforced through Prisma queries with company/member context
- API Protection: All tRPC procedures check authentication and authorization
- File Access: Presigned URLs with expiration for secure file access
- Audit Trail: Comprehensive logging of all significant actions
- Data Isolation: Multi-tenant architecture with strict data separation
Common Development Tasks
Adding a New Feature
- Define database schema in
prisma/schema.prisma - Create tRPC router in
src/trpc/routers/ - Add to appRouter in
src/trpc/api/root.ts - Build UI components in
src/components/ - Create pages in
src/app/
Working with Securities
- Always check company context
- Validate stakeholder relationships
- Maintain audit trail for compliance
- Handle vesting calculations properly
Email Workflows
- Create email template in
src/emails/ - Create job handler in
src/jobs/ - Register job in
src/jobs/register.ts - Queue job from tRPC procedure
Testing Considerations
- Use seeded data for development (see
prisma/seeds/) - Test multi-company scenarios
- Verify permission boundaries
- Check email delivery in Mailpit (local dev)
Performance Optimizations
- Database: Proper indexing on foreign keys and frequently queried fields
- File Storage: Direct uploads to S3 bypass server
- Pagination: Built into data tables and lists
- Caching: React Query for client-side caching
- Background Jobs: Heavy operations processed asynchronously
Context for All AI Assistants
This file (LLM.md) is symlinked as:
.AGENTS.mdCLAUDE.mdQWEN.mdGEMINI.md
All files reference the same knowledge base. Updates here propagate to all AI systems.
Rules for AI Assistants
- ALWAYS update LLM.md with significant discoveries
- NEVER commit symlinked files (.AGENTS.md, CLAUDE.md, etc.) - they're in .gitignore
- NEVER create random summary files - update THIS file