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)│ │ │ ├── pricing/ # Public pricing page│ │ │ ├── invite/ # Team invitation acceptance page│ │ │ ├── s/ # Signer-facing signing page│ │ │ └── api/│ │ │ ├── auth/[...nextauth]/ # NextAuth handler│ │ │ ├── trpc/[trpc]/ # tRPC handler│ │ │ ├── v1/[...path]/ # Public REST API (Hono)│ │ │ └── webhooks/stripe/ # Stripe billing webhook receiver│ │ ├── components/ # React components│ │ ├── hooks/ # Custom React hooks│ │ ├── lib/ # Shared utilities (auth config, tRPC client, URL safety)│ │ ├── types/ # Ambient type declarations│ │ ├── middleware.ts # Next.js middleware│ │ └── server/ # Server-side code│ │ ├── routers/ # tRPC routers (one per domain)│ │ ├── services/ # Domain logic — one service per resource│ │ ├── actions/ # Server actions (e.g. auth)│ │ ├── api/v1/ # Public REST API — routes, schemas, middleware│ │ ├── config/ # Tier limits and plan configuration│ │ ├── errors.ts # Shared error types│ │ └── 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/ # Stub — `export {}`, not yet implemented│ ├── jobs/ # Stub — `export {}`, not yet implemented│ └── ui/ # Stub — `export {}`, not yet implemented│├── docker-compose.yml # Internal deployment stack (not a customer-facing self-hosting option)├── docker-compose.dev.yml # Local dev dependencies (Postgres, Redis)├── Dockerfile # Multi-stage 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, packages/jobs, packages/ui
Section titled “packages/email, packages/jobs, packages/ui”All three are placeholder stubs today — each is just export {}; behind a package.json. Nothing in the app imports from them yet. Email sending currently lives directly in apps/web/src/server/services/email.ts (Resend integration) and email-templates.ts, not in packages/email.
tRPC Routers
Section titled “tRPC Routers”The internal API surface is defined by tRPC routers in apps/web/src/server/routers/. This powers the web app only — it’s separate from the public REST API (apps/web/src/server/api/v1/), which is a hand-written Hono layer, not generated from these routers.
| Router | Purpose |
|---|---|
account | Profile management, password change, account deletion |
apikey | API key CRUD |
batch | Bulk CSV import for signing invitations |
billing | Stripe subscription and tier management |
container | Container CRUD, listing, search |
dashboard | Dashboard statistics, recent activity |
document | Document and version CRUD, clause management |
email-verification | Signup email verification token issuance and redemption |
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 |
template | Mark/unmark containers as templates, cloning |
webhook | Webhook endpoint management — shipped, not future |