# supportopenhouse/ohsupplyforms architecture

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

- Interactive diagram: https://gitdiagram.com/supportopenhouse/ohsupplyforms
- Repository: https://github.com/supportopenhouse/ohsupplyforms

## Overview

#### Purpose and Entry Points
Openhouse Forms is a server-rendered/static-client property-management workflow. Ground staff record property visits, sales staff create token/deal records, and managers review records linked by a shared UID. The Node/Express entry point is `openhouse-forms/server.js`; browser entry pages are served from `openhouse-forms/public/`, notably `visit.html`, `token-request.html`, `token-deal.html`, and `admin.html`.

#### HTTP Application Layer
`openhouse-forms/server.js` initializes Express, runs database migration at startup, serves static assets, and mounts route modules. Route modules define the business API boundary between vanilla browser pages and PostgreSQL:
- Visit capture and property lookup: `openhouse-forms/routes/visit.js`
- Token request/deal workflows: `openhouse-forms/routes/token-request.js`, `openhouse-forms/routes/token-deal.js`
- Listing/finalization lifecycle: `openhouse-forms/routes/listing.js`, `openhouse-forms/routes/final.js`
- Scheduling and pending requests: `openhouse-forms/routes/schedule.js`, `openhouse-forms/routes/pending-request.js`

#### Property Workflow and UID Linkage
The central control flow begins with a visit record, which generates or uses a UID and persists property/visit context. Subsequent sales-side flows retrieve this shared identity to prefill or update token, listing, schedule, and deal stages. The route separation suggests the application models operational states as distinct form-driven stages rather than a single generic CRUD interface. Primary UI surfaces include `openhouse-forms/public/visit.html`, `openhouse-forms/public/listing.html`, and `openhouse-forms/public/final.html`.

#### Data Persistence and Reference Data
PostgreSQL is accessed through a shared pool in `openhouse-forms/db/pool.js`. Schema creation/migration is centralized in `openhouse-forms/db/migrate.js` and invoked on server startup; initial city/locality/society and related reference data is loaded by `openhouse-forms/db/seed.js`. Configuration/dropdown APIs are isolated in `openhouse-forms/routes/config.js`, keeping reference-data retrieval separate from transactional workflows.

#### Authentication and Administrative Boundaries
Authentication middleware resides in `openhouse-forms/middleware/auth.js`, establishing a protected-route boundary where applied by the server/routes. Administrative and operational pages are static clients backed by APIs, including `openhouse-forms/public/admin.html` and `openhouse-forms/public/my-properties.html`. Shared client behavior, including common request/UI utilities, is concentrated in `openhouse-forms/public/js/shared.js`.

#### Documents, Billing, and External Integrations
Server utilities handle outbound artifacts and communications: PDF/invoice generation in `openhouse-forms/utils/pdf-template.js` and `openhouse-forms/utils/invoice-template.js`; email via `openhouse-forms/utils/email-sender.js` and `openhouse-forms/utils/gmail-send.js`; WhatsApp messaging through `openhouse-forms/utils/whatsapp.js`. Associated business endpoints include `openhouse-forms/routes/cp-bill.js`, `openhouse-forms/routes/ama-details.js`, and `openhouse-forms/routes/external.js`. OCR ingestion is separately bounded in `openhouse-forms/routes/ocr.js`.

#### Runtime and Infrastructure
The runtime is Node.js with Express and a vanilla HTML/CSS/JavaScript frontend—no frontend build pipeline. PostgreSQL is intended to run on Neon, with `DATABASE_URL` supplied through environment configuration. Render hosts the long-running Node service. PDFKit performs server-side PDF generation; Gmail/email and WhatsApp utilities indicate external messaging-provider dependencies. Deployment must permit startup migrations and a separately invoked seed operation.

Main entry points: [`openhouse-forms/server.js`](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/server.js) (Express server), [`openhouse-forms/db/pool.js`](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/db/pool.js) (Database pool), [`openhouse-forms/public/js/shared.js`](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/js/shared.js) (Shared client utilities), [`openhouse-forms/routes/cp-bill.js`](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/cp-bill.js) (Billing and external API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Static browser client"]
  node_visit_ui["Visit form<br/>HTML page<br/>[visit.html]"]
  node_sales_ui["Sales forms<br/>HTML pages<br/>[token-request.html]"]
  node_lifecycle_ui["Listing lifecycle forms<br/>HTML pages<br/>[listing.html]"]
  node_admin_ui["Admin operations<br/>HTML pages<br/>[admin.html]"]
  node_shared_client["Shared client utilities<br/>browser JavaScript<br/>[shared.js]"]
end

subgraph group_api["Express API"]
  node_server{{"Express server<br/>Node.js entry point<br/>[server.js]"}}
  node_auth["Auth middleware<br/>route protection<br/>[auth.js]"]
  node_visit_api["Visit and property API<br/>route module<br/>[visit.js]"]
  node_token_api["Token workflows<br/>route modules<br/>[token-request.js]"]
  node_lifecycle_api["Listing and final API<br/>route modules<br/>[listing.js]"]
  node_operations_api["Schedule and pending API<br/>route modules<br/>[schedule.js]"]
  node_config_api["Reference data API<br/>route module<br/>[config.js]"]
  node_business_api["Billing and external API<br/>route modules<br/>[cp-bill.js]"]
end

subgraph group_data["PostgreSQL data layer"]
  node_pool["Database pool<br/>PostgreSQL client<br/>[pool.js]"]
  node_migration["Schema migration<br/>startup migration<br/>[migrate.js]"]
  node_seed["Reference-data seed<br/>seed operation<br/>[seed.js]"]
  node_postgres[("Neon PostgreSQL<br/>managed database")]
end

subgraph group_integrations["Documents and integrations"]
  node_documents["PDF and invoice generation<br/>server utility<br/>[pdf-template.js]"]
  node_messaging["Email and WhatsApp<br/>messaging utilities<br/>[email-sender.js]"]
  node_providers(("Messaging providers<br/>external services"))
end

node_render{{"Render<br/>service host"}}

node_visit_ui -->|"uses"| node_shared_client
node_sales_ui -->|"uses"| node_shared_client
node_lifecycle_ui -->|"uses"| node_shared_client
node_admin_ui -->|"uses"| node_shared_client
node_shared_client -->|"API requests"| node_server
node_server -->|"applies where protected"| node_auth
node_server -->|"mounts"| node_visit_api
node_server -->|"mounts"| node_token_api
node_server -->|"mounts"| node_lifecycle_api
node_server -->|"mounts"| node_operations_api
node_server -->|"mounts"| node_config_api
node_server -->|"mounts"| node_business_api
node_visit_api -.->|"shared UID context"| node_token_api
node_token_api -.->|"advances shared records"| node_lifecycle_api
node_visit_api -->|"queries and persists"| node_pool
node_token_api -->|"reads and updates"| node_pool
node_lifecycle_api -->|"persists stages"| node_pool
node_operations_api -->|"reads and updates"| node_pool
node_config_api -->|"reads reference data"| node_pool
node_business_api -->|"reads business records"| node_pool
node_pool -->|"DATABASE_URL"| node_postgres
node_server -->|"runs at startup"| node_migration
node_migration -->|"migrates schema"| node_postgres
node_seed -->|"loads reference data"| node_postgres
node_business_api -->|"generates artifacts"| node_documents
node_business_api -->|"sends notifications"| node_messaging
node_messaging -->|"delivers"| node_providers
node_render -->|"hosts"| node_server

click node_visit_ui "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/visit.html"
click node_sales_ui "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/token-request.html"
click node_lifecycle_ui "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/listing.html"
click node_admin_ui "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/admin.html"
click node_shared_client "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/js/shared.js"
click node_server "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/server.js"
click node_auth "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/middleware/auth.js"
click node_visit_api "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/visit.js"
click node_token_api "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/token-request.js"
click node_lifecycle_api "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/listing.js"
click node_operations_api "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/schedule.js"
click node_config_api "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/config.js"
click node_business_api "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/cp-bill.js"
click node_pool "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/db/pool.js"
click node_migration "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/db/migrate.js"
click node_seed "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/db/seed.js"
click node_documents "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/utils/pdf-template.js"
click node_messaging "https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/utils/email-sender.js"

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_visit_ui,node_sales_ui,node_lifecycle_ui,node_admin_ui,node_shared_client toneBlue
class node_server,node_auth,node_visit_api,node_token_api,node_lifecycle_api,node_operations_api,node_config_api,node_business_api toneAmber
class node_pool,node_migration,node_seed,node_postgres toneMint
class node_documents,node_messaging,node_providers toneRose
class node_render toneNeutral
```

## Components

### Static browser client

- [Visit form](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/visit.html): HTML page · Ground staff capture property visits and UID context. · `openhouse-forms/public/visit.html`
- [Sales forms](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/token-request.html): HTML pages · Token request and deal forms use the shared property identity. · `openhouse-forms/public/token-request.html`
- [Listing lifecycle forms](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/listing.html): HTML pages · Listing and finalization are distinct operational stages. · `openhouse-forms/public/listing.html`
- [Admin operations](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/admin.html): HTML pages · `openhouse-forms/public/admin.html`
- [Shared client utilities](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/public/js/shared.js): browser JavaScript · Common request and UI behavior for static pages. · `openhouse-forms/public/js/shared.js`

### Express API

- [Express server](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/server.js): Node.js entry point · Serves static clients, runs migrations, and mounts APIs. · `openhouse-forms/server.js`
- [Auth middleware](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/middleware/auth.js): route protection · `openhouse-forms/middleware/auth.js`
- [Visit and property API](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/visit.js): route module · Captures visits and performs property lookup. · `openhouse-forms/routes/visit.js`
- [Token workflows](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/token-request.js): route modules · Request and deal stages retrieve and update shared UID records. · `openhouse-forms/routes/token-request.js`
- [Listing and final API](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/listing.js): route modules · Handles listing and finalization lifecycle stages. · `openhouse-forms/routes/listing.js`
- [Schedule and pending API](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/schedule.js): route modules · `openhouse-forms/routes/schedule.js`
- [Reference data API](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/config.js): route module · Separates dropdown and configuration data from transactions. · `openhouse-forms/routes/config.js`
- [Billing and external API](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/routes/cp-bill.js): route modules · Exposes billing, AMA, external, and OCR business endpoints. · `openhouse-forms/routes/cp-bill.js`

### PostgreSQL data layer

- [Database pool](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/db/pool.js): PostgreSQL client · `openhouse-forms/db/pool.js`
- [Schema migration](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/db/migrate.js): startup migration · Creates or upgrades schema at service startup. · `openhouse-forms/db/migrate.js`
- [Reference-data seed](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/db/seed.js): seed operation · Loads initial city, locality, society, and related data separately. · `openhouse-forms/db/seed.js`
- **Neon PostgreSQL**: managed database · Connected through DATABASE_URL.

### Documents and integrations

- [PDF and invoice generation](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/utils/pdf-template.js): server utility · Produces outbound PDF and invoice artifacts with PDFKit. · `openhouse-forms/utils/pdf-template.js`
- [Email and WhatsApp](https://github.com/supportopenhouse/ohsupplyforms/blob/main/openhouse-forms/utils/email-sender.js): messaging utilities · Sends email and WhatsApp communications through providers. · `openhouse-forms/utils/email-sender.js`
- **Messaging providers**: external services · Gmail/email and WhatsApp delivery dependencies.

### Other components

- **Render**: service host · Hosts the long-running Node service.

## Connections

- Visit form → Shared client utilities: uses
- Sales forms → Shared client utilities: uses
- Listing lifecycle forms → Shared client utilities: uses
- Admin operations → Shared client utilities: uses
- Shared client utilities → Express server: API requests
- Express server → Auth middleware: applies where protected
- Express server → Visit and property API: mounts
- Express server → Token workflows: mounts
- Express server → Listing and final API: mounts
- Express server → Schedule and pending API: mounts
- Express server → Reference data API: mounts
- Express server → Billing and external API: mounts
- Visit and property API → Token workflows: shared UID context
- Token workflows → Listing and final API: advances shared records
- Visit and property API → Database pool: queries and persists
- Token workflows → Database pool: reads and updates
- Listing and final API → Database pool: persists stages
- Schedule and pending API → Database pool: reads and updates
- Reference data API → Database pool: reads reference data
- Billing and external API → Database pool: reads business records
- Database pool → Neon PostgreSQL: DATABASE_URL
- Express server → Schema migration: runs at startup
- Schema migration → Neon PostgreSQL: migrates schema
- Reference-data seed → Neon PostgreSQL: loads reference data
- Billing and external API → PDF and invoice generation: generates artifacts
- Billing and external API → Email and WhatsApp: sends notifications
- Email and WhatsApp → Messaging providers: delivers
- Render → Express server: hosts
