How h4harsimran/formzero works
1. Overall shape
- FormZero is a single full-stack React application deployed as a Cloudflare Worker.
- The same codebase serves the public form-submission API and the authenticated admin dashboard.
2. Runtime and hosting
- The worker entry is in workers/app.ts, with Cloudflare configuration in wrangler.jsonc.
- The app uses React Router v7 with server-side rendering support (app/root.tsx, app/entry.server.tsx) rather than a separate frontend and backend service.
3. Request routing boundary
- app/routes.ts defines the route map.
- Route files under app/routes/ split into:
- public/auth flows (login, signup, logout, setup, home, success)
- authenticated dashboard pages (forms, settings.notifications)
- form-specific views (forms.$formId.*)
- API endpoints (api.auth.$.tsx, api.forms.$formId.submissions.tsx)
4. Public form ingestion path
- External sites submit data to the API route for a specific form ID.
- The ingestion endpoint supports both HTML form posts and JSON payloads per the README.
- Submitted data is persisted as form submissions in D1 and then surfaced in the dashboard.
5. Dashboard and form management
- The forms routes provide the admin experience for creating and inspecting forms.
- forms.$formId.tsx, forms.$formId.submissions.tsx, and forms.$formId.integration.tsx suggest three core dashboard concerns:
- form overview/configuration
- submission listing and inspection
- integration instructions for embedding the endpoint into a site’s form action or fetch call
6. Data and persistence layer
- Persistence is backed by Cloudflare D1, with schema changes captured in migrations/.
- The main persisted entities are implied by the migrations and types:
- submissions
- users
- forms
- settings
- Types in app/types/ mirror these domain objects for server/client consistency.
7. Authentication subsystem
- Auth is handled by better-auth (better-auth/config.ts, app/lib/auth.client.ts, app/lib/auth.server.ts).
- app/lib/require-auth.server.ts indicates server-side access control for dashboard routes.
- The api.auth.$.tsx route acts as the auth API surface.
8. Settings and notifications
- settings.notifications.tsx and app/lib/email.server.ts indicate a notification configuration flow, likely tied to submission events.
- The presence of seed.sql and migrations/0003_create_form_settings_table.sql / 0004_move_to_global_settings.sql suggests settings evolved from per-form to global configuration.
9. Submission analytics and export
- The submissions UI is split into a table/data layer under app/routes/forms.$formId.submissions/.
- Components like columns.tsx and data-table.tsx suggest the dashboard supports richer submission review, filtering, and CSV-style export workflows.
- README features confirm analytics and export are first-class dashboard capabilities.
10. UI composition
- app/components/ contains the application shell and dashboard widgets, while app/components/ui/ is the shared design-system layer based on shadcn/ui and Tailwind.
- app/components/app-sidebar.tsx, form-switcher.tsx, and settings-dialog.tsx indicate a persistent authenticated shell around the main dashboard routes.
11. Onboarding and setup
- setup.tsx, signup.tsx, login.tsx, and welcome/welcome.tsx define the initial user journey.
- This is consistent with the Cloudflare deployment model described in the README: first run, create an account, configure auth/database secrets, then land in the dashboard.
12. Key architectural boundary to capture in a diagram
- There are two primary traffic classes:
- anonymous submission traffic from external static sites into the worker API
- authenticated admin traffic from the dashboard into the same worker and D1 database
- Both paths converge on the same persistence layer, but only the dashboard path passes through auth and user/session checks.
Main entry points: routes.ts Route map · forms.tsx Dashboard · 0001_create_submissions_table.sql D1 database · api.forms.$formId.submissions.tsx Submission API
Components 19
Runtime
Cloudflare Worker app and SSR host
- Worker app · Entry runtime for the deployed app
workers/app.ts - Config · Cloudflare runtime configuration
wrangler.jsonc
Routes
Public, dashboard, and API route boundaries
- Route map · Central route definition and request dispatch
app/routes.ts - App shell · Top-level React app and document shell
app/root.tsx - SSR entry · Server-side rendering entrypoint
app/entry.server.tsx - Public flows · Home, login, signup, setup, logout, and success pages
app/routes/home.tsx - Dashboard · Authenticated form and settings pages
app/routes/forms.tsx - Form views · Per-form overview, submissions, and integration pages
app/routes/forms.$formId.tsx - Submission API · Anonymous form submission endpoint for HTML and JSON posts
app/routes/api.forms.$formId.submissions.tsx - Auth API · Authentication request surface for login and session actions
app/routes/api.auth.$.tsx
Auth
Authentication and access control
- Auth layer · Client and server auth helpers plus protected-route checks
better-auth/config.ts - Access guard · Server-side enforcement for dashboard routes
app/lib/require-auth.server.ts - Email service · Submission notification and mail integration
app/lib/email.server.ts
Data
Persistence, migrations, and domain types
- D1 database · Cloudflare D1 storage for forms, users, settings, and submissions
migrations/0001_create_submissions_table.sql - Migrations · Database schema evolution and settings changes
migrations/0004_move_to_global_settings.sql - Domain types · Form, submission, user, and settings models
app/types/form.ts
UI
Shared shell and design system
- App shell · Authenticated navigation and workspace chrome
app/components/app-sidebar.tsx - Dashboard widgets · Form switcher, settings dialog, and related dashboard controls
app/components/form-switcher.tsx - Submissions table · Submission list, columns, and table interactions
app/routes/forms.$formId.submissions/data-table.tsx
Connections 21
- Worker app → Route map: serves · Worker dispatches requests into the route map
- Worker app → Config: configured by · Deployment and runtime settings come from Cloudflare config
- Route map → App shell: mounts · Application shell and document structure wrap routed content
- Route map → SSR entry: renders · Server entry performs SSR for matched routes
- Route map → Public flows: routes · Anonymous onboarding and account flows
- Route map → Dashboard: routes · Authenticated dashboard area
- Route map → Form views: routes · Per-form management views
- Route map → Submission API: routes · External submission traffic lands here
- Route map → Auth API: routes · Auth requests are handled on the same worker
- Public flows → Auth API: uses · Login and signup flow through the auth API
- Dashboard → Access guard: protects · Dashboard pages require authenticated access
- Access guard → Auth layer: verifies · Server guard delegates session and identity checks
- Auth API → Auth layer: backed by · Auth route is implemented via better-auth
- Submission API → D1 database: writes · Incoming submissions are persisted in D1
- Dashboard → D1 database: reads · Dashboard pages load forms, submissions, and settings
- Form views → Submissions table: uses · Submissions pages use the table/data layer for review
- Dashboard → App shell: wraps · Authenticated shell provides navigation and workspace chrome
- Dashboard → Dashboard widgets: uses · Form switching and settings controls support admin workflows
- Submission API → Email service: triggers · Submission events can drive notification email flows
- D1 database → Migrations: evolves via · Schema is defined and updated through migration files
- D1 database → Domain types: modeled by · Domain types mirror persisted records