Project Structure
Monorepo Layout
Section titled “Monorepo Layout”TheTerms uses Turborepo with pnpm workspaces. The root turbo.json defines the build pipeline, and each package or app has its own package.json.
theterms/├── apps/│ └── web/ # Next.js 14 application│ ├── src/│ │ ├── app/ # App Router pages and layouts│ │ │ ├── (auth)/ # Auth pages: login, signup, password reset│ │ │ ├── (dashboard)/ # Dashboard pages (protected)│ │ │ ├── api/ # API routes (NextAuth, tRPC)│ │ │ ├── invite/ # Team invitation acceptance page│ │ │ └── s/ # Signer-facing signing page│ │ ├── components/ # React components│ │ ├── hooks/ # Custom React hooks│ │ ├── lib/ # Shared utilities (auth config, tRPC client)│ │ └── server/ # Server-side code│ │ ├── routers/ # tRPC routers (one per domain)│ │ ├── services/ # Email, webhooks│ │ └── trpc.ts # tRPC context, middleware chain│ └── __tests__/ # Test files│├── packages/│ ├── db/ # Prisma schema, client, migrations│ │ └── prisma/│ │ ├── schema.prisma # Data model│ │ └── migrations/ # SQL migration files│ ├── email/ # Email service (Resend integration)│ ├── jobs/ # Background job definitions│ └── ui/ # Shared UI components│├── docker-compose.yml # Production deployment├── docker-compose.dev.yml # Local dev dependencies├── Dockerfile # Multi-stage production build├── docker-entrypoint.sh # Auto-migration on startup├── turbo.json # Turborepo pipeline config└── pnpm-workspace.yaml # Workspace package definitionsPackages
Section titled “Packages”apps/web
Section titled “apps/web”The main Next.js application. Contains all pages, components, API routes, and tRPC routers.
packages/db
Section titled “packages/db”The Prisma schema and generated client. All other packages import the database client from here via @theterms/db.
packages/email
Section titled “packages/email”Email sending service using Resend. Defines React Email templates for signing invitations, team invitations, and admin notifications.
packages/jobs
Section titled “packages/jobs”Background job definitions (future — currently placeholder). Will handle email queuing, webhook delivery, and scheduled tasks.
packages/ui
Section titled “packages/ui”Shared UI components used across packages. Based on shadcn/ui primitives with Tailwind CSS.
tRPC Routers
Section titled “tRPC Routers”The API surface is defined by tRPC routers in apps/web/src/server/routers/:
| Router | Purpose |
|---|---|
account | Profile management, password change, account deletion |
apikey | API key CRUD (for future public API) |
batch | Bulk CSV import for signing invitations |
container | Container CRUD, listing, search |
dashboard | Dashboard statistics, recent activity |
document | Document and version CRUD, clause management |
invitation | Team member invitations |
password-reset | Password reset token generation and redemption |
signing | Signing request creation, signer view/submit, audit trail |
team | Team member listing, role changes, removal |
webhook | Webhook endpoint management (future) |