Technology Stack
Terra is built on a modern, serverless-first architecture. Each choice reflects a hypothesis we’re testing about building government intake infrastructure.Monorepo Structure
Terra uses a Turborepo monorepo with pnpm workspaces:Why Monorepo?
- Shared Components: The
@unify/uipackage contains all Shadcn UI components, enabling reuse across future apps - Atomic Deploys: Turborepo ensures dependent packages build in the correct order
- Single Lock File: pnpm workspaces share dependencies, reducing install times and disk usage
@unify/ui Package
All UI primitives (Button, Card, Input, Dialog, etc.) live inpackages/ui:
apps/terra focused on business logic while UI components remain reusable.
Frontend
Next.js 16
App Router with React 19 Server Components. Server-side rendering keeps sensitive logic off the client.
Tailwind CSS 4
Utility-first CSS with Shadcn UI components built on Radix primitives.
Core Libraries
| Library | Version | Purpose |
|---|---|---|
react-hook-form | 7.66 | Form state management with minimal re-renders |
zod | 4.1 | Runtime schema validation for forms and API inputs |
zustand | 5.0 | Lightweight state management for the form builder |
@dnd-kit | 6.3 | Drag-and-drop for form builder and folder organization |
framer-motion | 12.x | Animations and micro-interactions |
recharts | 2.15 | Dashboard charts and visualizations |
lucide-react | 0.555 | Icon library |
Why Next.js App Router?
We’re testing whether React Server Components can improve security posture for government applications:- Server-side by default: Sensitive operations (database queries, auth checks) never reach the client bundle
- Streaming: Large forms render progressively, improving perceived performance
- Edge-ready: Middleware runs at the edge for fast auth checks globally
Backend
Supabase
PostgreSQL with Row Level Security, Auth helpers, and private Storage buckets.
WorkOS AuthKit
Enterprise-ready SSO (SAML, OIDC) with 1M free monthly active users.
Why Supabase?
We’re testing whether pushing authorization into the database layer reduces application risk:Why WorkOS?
We chose WorkOS over Supabase Auth for several reasons:- Enterprise SSO Ready: Government agencies often require SAML/OIDC integration with Azure AD, Okta, or Google Workspace. WorkOS makes this trivial.
- Generous Free Tier: 1 million monthly active users on the free plan—enough for most programs.
- Clean Developer Experience: AuthKit handles session management, token refresh, and middleware with minimal boilerplate.
- Future-Proof: Directory Sync and Audit Logs align with government compliance requirements.
Resend
Transactional email with React Email templates. Production domain:
notifications.withunify.orgWhy Resend?
Resend handles lightweight, brandable receipts—the “your application was received” emails that applicants expect immediately. Complex notification workflows (reminders, status updates, multi-channel delivery) remain in external systems. This keeps Terra focused on intake, not becoming a notification platform.Translations
DeepL
Machine translation API for auto-translating form content and UI strings.
Why DeepL?
Government forms must serve diverse populations. DeepL offers:- Superior Quality: Consistently better translations than Google Translate for formal documents
- Privacy-Conscious: Data not used for training models (important for government)
- Simple API: Single endpoint for translation, no complex setup
- Generous Free Tier: 500,000 characters/month on the free API
Address Verification
Smarty Streets
USPS address autocomplete and validation for accurate mail delivery.
Why Smarty Streets?
Government programs require accurate addresses for benefit delivery. Smarty Streets offers:- USPS Certified: Official CASS-certified address validation
- Autocomplete: Real-time address suggestions as users type (requires US Autocomplete Pro subscription)
- Standardization: Converts “123 main st” to “123 Main Street NW”
- Deliverability: DPV codes indicate if mail can actually be delivered
How It Works
When Smarty credentials are configured:- User starts typing → Autocomplete suggestions appear after 3 characters
- User selects suggestion → All address fields auto-fill + ”✓ Verified” badge appears
- User manually edits → Badge changes to ”⚠ Unverified”
Smarty Products Required
| Product | Purpose |
|---|---|
| US Autocomplete Pro | Type-ahead suggestions ($21/month) |
| US Street API | Address verification (free tier: 250/month) |
Address fields work without Smarty—users just type manually without autocomplete.
Analytics
PostHog
Product analytics for understanding form completion rates and drop-off points.
Security
DOMPurify
XSS sanitization for user-generated HTML content (isomorphic-dompurify for SSR).
Aikido
Automated SAST scanning and dependency vulnerability detection.
Security Utilities
Terra includes centralized security functions insrc/lib/security.ts:
| Function | Purpose |
|---|---|
getSafeRedirectPath() | Prevents open redirect attacks |
sanitizeStoragePath() | Prevents path traversal in file storage |
cleanFileName() | Sanitizes user-provided filenames |
DOMPurify.sanitize() | Strips malicious scripts from HTML |
Developer Tools
Test Commands
Database Schema
Terra uses a small number of tables with JSONB for flexibility:Why JSONB for Forms?
See ADR-001: Recursive Form Schema for the full decision record. TL;DR: Government forms have deeply nested conditional logic. JSONB trees are more flexible than normalized tables for this use case.Secrets Management
Doppler
Centralized secrets management with automatic environment syncing.
Why Doppler?
Managing environment variables across local development, staging, and production is error-prone. Doppler provides:- Single Source of Truth: All secrets in one dashboard
- Environment Branching: Separate configs for dev/staging/prod
- Team Sync: No more sharing
.envfiles over Slack - Audit Logs: Track who accessed which secrets when
- Automatic Rotation: Update secrets without redeploying
Usage
Vercel Integration
Doppler syncs directly to Vercel:- Connect Doppler to Vercel in the Doppler dashboard
- Map your Doppler project to your Vercel project
- Secrets automatically sync on change
Terra works fine with traditional
.env.local files—Doppler is recommended but not required.Infrastructure
| Service | Provider | Purpose |
|---|---|---|
| Hosting | Vercel | Edge-optimized Next.js deployment |
| Database | Supabase | Managed PostgreSQL + Storage |
| Auth | WorkOS | Enterprise SSO and user management |
| Secrets | Doppler | Centralized secrets management |
| Resend | Transactional receipts | |
| Translation | DeepL | Auto-translate form content |
| Address | Smarty Streets | USPS address validation |
| DNS | Cloudflare | DDoS protection and caching |
Next: Architecture Decisions
Read the ADRs explaining why we made these choices.