# h4harsimran/formzero architecture

> Architecture diagram of the GitHub repository h4harsimran/formzero, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/h4harsimran/formzero
- Repository: https://github.com/h4harsimran/formzero

## Overview

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: [`app/routes.ts`](https://github.com/h4harsimran/formzero/blob/main/app/routes.ts) (Route map), [`app/routes/forms.tsx`](https://github.com/h4harsimran/formzero/blob/main/app/routes/forms.tsx) (Dashboard), [`migrations/0001_create_submissions_table.sql`](https://github.com/h4harsimran/formzero/blob/main/migrations/0001_create_submissions_table.sql) (D1 database), [`app/routes/api.forms.$formId.submissions.tsx`](https://github.com/h4harsimran/formzero/blob/main/app/routes/api.forms.$formId.submissions.tsx) (Submission API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_worker["Worker app<br/>cloudflare worker<br/>[app.ts]"]
  node_wrangler["Config<br/>[wrangler.jsonc]"]
end

subgraph group_routes["Routes"]
  node_router["Route map<br/>react-router v7<br/>[routes.ts]"]
  node_root["App shell<br/>ssr root<br/>[root.tsx]"]
  node_ssr["SSR entry<br/>server render<br/>[entry.server.tsx]"]
  node_public["Public flows<br/>route set<br/>[home.tsx]"]
  node_dashboard["Dashboard<br/>route set<br/>[forms.tsx]"]
  node_formviews["Form views<br/>route set<br/>[forms.$formId.tsx]"]
  node_ingestapi(("Submission API<br/>endpoint"))
  node_authapi(("Auth API<br/>endpoint<br/>[api.auth.$.tsx]"))
end

subgraph group_auth["Auth"]
  node_authlib["Auth layer<br/>better-auth<br/>[config.ts]"]
  node_requireauth["Access guard<br/>server guard"]
  node_email["Email service<br/>notification<br/>[email.server.ts]"]
end

subgraph group_data["Data"]
  node_db[("D1 database<br/>persistence")]
  node_migrations["Migrations<br/>schema history"]
  node_types["Domain types<br/>shared types<br/>[form.ts]"]
end

subgraph group_ui["UI"]
  node_sidebar["App shell<br/>ui shell<br/>[app-sidebar.tsx]"]
  node_widgets["Dashboard widgets<br/>ui components<br/>[form-switcher.tsx]"]
  node_table["Submissions table<br/>data table ui<br/>[data-table.tsx]"]
end

node_worker -->|"serves"| node_router
node_worker -.->|"configured by"| node_wrangler
node_router -->|"mounts"| node_root
node_router -->|"renders"| node_ssr
node_router -->|"routes"| node_public
node_router -->|"routes"| node_dashboard
node_router -->|"routes"| node_formviews
node_router -->|"routes"| node_ingestapi
node_router -->|"routes"| node_authapi
node_public -->|"uses"| node_authapi
node_dashboard -->|"protects"| node_requireauth
node_requireauth -->|"verifies"| node_authlib
node_authapi -->|"backed by"| node_authlib
node_ingestapi -->|"writes"| node_db
node_dashboard -->|"reads"| node_db
node_formviews -->|"uses"| node_table
node_dashboard -->|"wraps"| node_sidebar
node_dashboard -->|"uses"| node_widgets
node_ingestapi -.->|"triggers"| node_email
node_db -->|"evolves via"| node_migrations
node_db -.->|"modeled by"| node_types

click node_worker "https://github.com/h4harsimran/formzero/blob/main/workers/app.ts"
click node_wrangler "https://github.com/h4harsimran/formzero/blob/main/wrangler.jsonc"
click node_router "https://github.com/h4harsimran/formzero/blob/main/app/routes.ts"
click node_root "https://github.com/h4harsimran/formzero/blob/main/app/root.tsx"
click node_ssr "https://github.com/h4harsimran/formzero/blob/main/app/entry.server.tsx"
click node_public "https://github.com/h4harsimran/formzero/blob/main/app/routes/home.tsx"
click node_dashboard "https://github.com/h4harsimran/formzero/blob/main/app/routes/forms.tsx"
click node_formviews "https://github.com/h4harsimran/formzero/blob/main/app/routes/forms.$formId.tsx"
click node_ingestapi "https://github.com/h4harsimran/formzero/blob/main/app/routes/api.forms.$formId.submissions.tsx"
click node_authapi "https://github.com/h4harsimran/formzero/blob/main/app/routes/api.auth.$.tsx"
click node_authlib "https://github.com/h4harsimran/formzero/blob/main/better-auth/config.ts"
click node_requireauth "https://github.com/h4harsimran/formzero/blob/main/app/lib/require-auth.server.ts"
click node_db "https://github.com/h4harsimran/formzero/blob/main/migrations/0001_create_submissions_table.sql"
click node_migrations "https://github.com/h4harsimran/formzero/blob/main/migrations/0004_move_to_global_settings.sql"
click node_types "https://github.com/h4harsimran/formzero/blob/main/app/types/form.ts"
click node_email "https://github.com/h4harsimran/formzero/blob/main/app/lib/email.server.ts"
click node_sidebar "https://github.com/h4harsimran/formzero/blob/main/app/components/app-sidebar.tsx"
click node_widgets "https://github.com/h4harsimran/formzero/blob/main/app/components/form-switcher.tsx"
click node_table "https://github.com/h4harsimran/formzero/blob/main/app/routes/forms.$formId.submissions/data-table.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_worker,node_wrangler toneBlue
class node_router,node_root,node_ssr,node_public,node_dashboard,node_formviews,node_ingestapi,node_authapi toneAmber
class node_authlib,node_requireauth,node_email toneMint
class node_db,node_migrations,node_types toneRose
class node_sidebar,node_widgets,node_table toneIndigo
```

## Components

### Runtime

Cloudflare Worker app and SSR host

- [Worker app](https://github.com/h4harsimran/formzero/blob/main/workers/app.ts): cloudflare worker · Entry runtime for the deployed app · `workers/app.ts`
- [Config](https://github.com/h4harsimran/formzero/blob/main/wrangler.jsonc): deployment config · Cloudflare runtime configuration · `wrangler.jsonc`

### Routes

Public, dashboard, and API route boundaries

- [Route map](https://github.com/h4harsimran/formzero/blob/main/app/routes.ts): react-router v7 · Central route definition and request dispatch · `app/routes.ts`
- [App shell](https://github.com/h4harsimran/formzero/blob/main/app/root.tsx): ssr root · Top-level React app and document shell · `app/root.tsx`
- [SSR entry](https://github.com/h4harsimran/formzero/blob/main/app/entry.server.tsx): server render · Server-side rendering entrypoint · `app/entry.server.tsx`
- [Public flows](https://github.com/h4harsimran/formzero/blob/main/app/routes/home.tsx): route set · Home, login, signup, setup, logout, and success pages · `app/routes/home.tsx`
- [Dashboard](https://github.com/h4harsimran/formzero/blob/main/app/routes/forms.tsx): route set · Authenticated form and settings pages · `app/routes/forms.tsx`
- [Form views](https://github.com/h4harsimran/formzero/blob/main/app/routes/forms.$formId.tsx): route set · Per-form overview, submissions, and integration pages · `app/routes/forms.$formId.tsx`
- [Submission API](https://github.com/h4harsimran/formzero/blob/main/app/routes/api.forms.$formId.submissions.tsx): endpoint · Anonymous form submission endpoint for HTML and JSON posts · `app/routes/api.forms.$formId.submissions.tsx`
- [Auth API](https://github.com/h4harsimran/formzero/blob/main/app/routes/api.auth.$.tsx): endpoint · Authentication request surface for login and session actions · `app/routes/api.auth.$.tsx`

### Auth

Authentication and access control

- [Auth layer](https://github.com/h4harsimran/formzero/blob/main/better-auth/config.ts): better-auth · Client and server auth helpers plus protected-route checks · `better-auth/config.ts`
- [Access guard](https://github.com/h4harsimran/formzero/blob/main/app/lib/require-auth.server.ts): server guard · Server-side enforcement for dashboard routes · `app/lib/require-auth.server.ts`
- [Email service](https://github.com/h4harsimran/formzero/blob/main/app/lib/email.server.ts): notification · Submission notification and mail integration · `app/lib/email.server.ts`

### Data

Persistence, migrations, and domain types

- [D1 database](https://github.com/h4harsimran/formzero/blob/main/migrations/0001_create_submissions_table.sql): persistence · Cloudflare D1 storage for forms, users, settings, and submissions · `migrations/0001_create_submissions_table.sql`
- [Migrations](https://github.com/h4harsimran/formzero/blob/main/migrations/0004_move_to_global_settings.sql): schema history · Database schema evolution and settings changes · `migrations/0004_move_to_global_settings.sql`
- [Domain types](https://github.com/h4harsimran/formzero/blob/main/app/types/form.ts): shared types · Form, submission, user, and settings models · `app/types/form.ts`

### UI

Shared shell and design system

- [App shell](https://github.com/h4harsimran/formzero/blob/main/app/components/app-sidebar.tsx): ui shell · Authenticated navigation and workspace chrome · `app/components/app-sidebar.tsx`
- [Dashboard widgets](https://github.com/h4harsimran/formzero/blob/main/app/components/form-switcher.tsx): ui components · Form switcher, settings dialog, and related dashboard controls · `app/components/form-switcher.tsx`
- [Submissions table](https://github.com/h4harsimran/formzero/blob/main/app/routes/forms.$formId.submissions/data-table.tsx): data table ui · Submission list, columns, and table interactions · `app/routes/forms.$formId.submissions/data-table.tsx`

## Connections

- 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
