Skip to main content
Full-Stack TypeScript Monorepo · SaaS Platform
Source-Verified Implementation

Form Engine (Fieldwork)

Full-stack SaaS form builder featuring a visual drag-and-drop canvas, atomic two-phase field index reordering, httpOnly cookie sessions, and unified tRPC/OpenAPI surfaces.

Role: Full-Stack Developer
Form Engine (Fieldwork) Interface Preview

Project Overview

Form Engine (shipped in the UI under the product name Fieldwork) is a full-stack form creation and response-collection platform built within a clean Turborepo monorepo.

The product treats the visual builder, publishing gate, respondent experience, and response analytics as a single continuous workflow rather than isolated CRUD screens.

Architected with Next.js 16 (App Router), React 19, Express 5, tRPC, PostgreSQL, and Drizzle ORM, with absolute boundary separation between user interface, services, and database layers.

The Problem & Motivation

  • Most form builders separate form configuration, public sharing, and submission inspection across disconnected views, forcing users through jarring context switches.
  • Traditional form database schemas often rely on naive sequential integer indexing, which causes expensive re-indexing writes and race conditions during drag-and-drop operations.
  • The engineering objective was to build an end-to-end type-safe TypeScript monorepo that delivers an instant keyboard/drag-and-drop editing canvas with strict request-level ownership authorization and zero client-side credential exposure.

Architectural Solution

  • Engineered a pnpm/Turborepo workspace where apps/web (Next.js 16) and apps/api (Express 5) share typed packages for database, services, logger, and tRPC contracts without leaking SQL or private secrets to the client.
  • Implemented a dual-surface API router: one tRPC router mounted for direct type-safe client RPCs and compiled via trpc-to-openapi into an OpenAPI REST specification with interactive Scalar API documentation at /docs.
  • Designed a two-phase transaction-safe field reordering algorithm that parks rows on negative temporary indices to respect unique PostgreSQL constraints during rapid drag reordering.
  • Enforced httpOnly cookie sessions, request-level ownership checks (IDOR protection), formula injection-resistant client-side CSV exports, and HMAC-SHA256 password digests with per-user 16-byte random salts (chosen to eliminate native build dependencies, with the explicit disclosure that HMAC-SHA256 is a fast cryptographic digest and NOT a memory-hard password hashing function like Argon2id or bcrypt; in high-threat enterprise deployments, a migration to a memory-hard KDF would be required).

Technology Stack & Evidence

Technologies categorized by source verification and documented implementation scope:

Frontend & UI Architecture

Next.js 16
React 19
Tailwind CSS 4
TanStack Query
tRPC Client
Lucide React

Backend & API Engine

Express 5
tRPC Server
trpc-to-openapi (Scalar Docs)
Zod Schema Validation
Winston Logger

Data Layer & Persistence

PostgreSQL
Drizzle ORM
drizzle-kit
Docker Compose

Monorepo & Tooling

Turborepo
pnpm Workspaces
TypeScript 5.9
Prettier

Architecture & System Flow

1

Web Application (apps/web)

Next.js 16
React 19
TanStack Query
Tailwind CSS 4

Responsive dashboard, drag-and-drop form canvas, and lightweight public respondent route (/form/[id]) consuming the shared tRPC client.

2

API Server & Routing (apps/api & packages/trpc)

Express 5
tRPC
trpc-to-openapi
Scalar

Mounts both /trpc and /api OpenAPI endpoints, validates request payloads via Zod, and enforces authentication and IDOR ownership checks.

3

Data Access & Business Logic (packages/services)

TypeScript
Drizzle ORM
Winston

Encapsulated service layer managing form lifecycle, atomic reordering transactions, duplication, and response queries without exposing SQL to the web tier.

4

Persistence & Monorepo Infrastructure

PostgreSQL
Drizzle Schema
Turborepo
pnpm

Normalized relational schema with foreign key integrity, migration tracking, and pnpm workspace isolation.

Core Implemented Features

Visual Drag-and-Drop & Keyboard Builder

Palette of five field types (short text, number, email, yes/no, password) with live canvas previews, optimistic local ordering, and full keyboard navigation (arrows, 1-5 shortcuts, duplicate).

Dual tRPC & OpenAPI REST Surfaces

Single tRPC server router mounted both as an end-to-end typed RPC endpoint for Next.js and as a public REST API with generated OpenAPI JSON and Scalar docs UI.

Two-Phase Atomic Field Reordering

Reorders form fields inside a database transaction by parking rows on negative indices, completely avoiding UNIQUE(form_id, index) constraint collisions.

Secure Response Explorer & Sanitized CSV Export

Master-detail response inspector with full-text answer search, masked password fields, and client-side CSV serialization that neutralizes spreadsheet formula injection (=, +, -, @).

Technical Challenges & Trade-Offs

01.Avoiding Unique Constraint Collisions During Field Reordering

Challenge

Form fields enforce a strict UNIQUE(form_id, index) database constraint. In-place reordering permutations directly update indices, which throws unique constraint violation errors when swapping adjacent items.

Engineering Approach

Engineered a two-phase reordering transaction: phase 1 shifts target field indices to temporary negative values (-1, -2, etc.); phase 2 assigns the final zero-based positive sequence.

Result

Reliable in-transaction index swapping without UNIQUE constraint collision errors during rapid drag-and-drop or keyboard reordering.

02.Exposing Dual API Surfaces from a Single Router

Challenge

Maintaining separate REST and RPC endpoints leads to duplicate validation schemas, documentation drift, and fragmented auth middleware.

Engineering Approach

Integrated trpc-to-openapi with the root tRPC router in Express, generating an OpenAPI 3.0 specification and interactive Scalar UI at /docs from the exact same schema definitions.

Result

End-to-end type-safe internal RPC calls for the web client while effortlessly providing standard REST documentation for external consumers.

03.Preventing IDOR & Leaking Unpublished Schemas

Challenge

Draft forms must remain strictly confidential to the creator, while public respondent links (/form/[id]) must allow submission only when explicitly published.

Engineering Approach

Separated public and authenticated procedure paths. getForm checks creator ownership: unauthenticated requests for draft forms receive only an empty shell, and submitForm rejects any non-PUBLISHED form.

Result

Strict separation between private draft configurations and published respondent experiences, reducing unauthorized field discovery.

Key Engineering Takeaways

Demonstrated how Turborepo and pnpm workspaces enforce clean separation of concerns across enterprise-scale TypeScript projects.
Mastered transaction-safe database indexing patterns to build high-performance visual drag-and-drop user experiences.
Eliminated API contract drift by unifying tRPC and OpenAPI generation under a single TypeScript source of truth.
Evaluated the security trade-off of using Node's native HMAC-SHA256 with per-user random salts to eliminate native build dependencies, while explicitly documenting that high-threat enterprise deployments require dedicated memory-hard functions like Argon2id or bcrypt.