Next.js 14 App Router application that turns an 18-field intake form into a branded Google Doc proposal, a GoHighLevel contact/opportunity, an audit row in a Google Sheet, and a Slack notification — all from a single POST.
- Next.js 14 (App Router) + TypeScript
- Tailwind CSS with Talkerstein brand tokens (navy
#152857, orange#FF8731, burnt sienna#B3530E, beige#F7F6F3, Jost font) - Node 20+
@anthropic-ai/sdkfor proposal copy (Claudeclaude-sonnet-4-5, override withANTHROPIC_MODEL)googleapisfor Drive, Docs, Sheetsfetchfor GoHighLevel API v2 and Slack incoming webhookzodfor schema + env validation
No database. No auth. No DocuSign. No PandaDoc. No new SaaS.
/app
layout.tsx Root layout, brand header
page.tsx Redirect to /intake
globals.css Tailwind + brand variables
/intake
page.tsx 18-field intake form page
/success
page.tsx Confirmation + proposal ref #
/api
/generate/route.ts Main POST orchestrator (90s budget)
/health/route.ts GET health check
/components
IntakeForm.tsx Form with conditional GHL section + live margin
FormField.tsx Reusable field wrapper
PackagePicker.tsx Multi-select for package codes
/lib
anthropic.ts Claude client + generateProposalContent()
google-auth.ts Shared service-account JWT
google-docs.ts Copy template + replaceAllText render
sheets.ts nextRefNumber() + logProposal()
ghl.ts Contact, opportunity, contract, e-sign, Stripe
slack.ts notify() + notifyFailure()
prompt.ts Exported PROPOSAL_SYSTEM_PROMPT
packages.ts Package module library (B/W/M/G/GM/C)
schema.ts Zod schema for intake
margin.ts Margin calc (RED < 55%)
retry.ts Exponential-backoff retry helper
/config
env.ts Typed, Zod-validated env loader
/public
talkerstein-logo.svg Placeholder logo
README.md
ARCHITECTURE.md
.env.example
package.json, tsconfig.json, tailwind.config.ts, postcss.config.js,
next.config.js, railway.json, vercel.json, .gitignore
git clone <this repo>
cd intake
cp .env.example .env
# fill in the values (see sections below)
npm install
npm run build
npm run start # or: npm run devThe build does not require real env vars — env is only validated when a
route or function that touches an external API is actually called. /api/health
works with zero secrets.
All ten variables in .env.example must be present in production. Build passes
without them; runtime integration calls will throw a descriptive Zod error.
| Var | What it is | Where to get it |
|---|---|---|
ANTHROPIC_API_KEY |
Anthropic API key | console.anthropic.com → API Keys |
GOOGLE_SERVICE_ACCOUNT_JSON |
Full service-account JSON, stringified | See Google setup below |
GOOGLE_DOCS_TEMPLATE_ID |
Google Doc template file ID | URL of template doc |
GOOGLE_DRIVE_FOLDER_ID |
Destination Drive folder for generated docs | URL of folder |
GOOGLE_SHEETS_AUDIT_ID |
Audit Sheet ID | URL of sheet |
GHL_API_KEY |
GoHighLevel private integration key | GHL → Settings → Integrations |
GHL_LOCATION_ID |
GHL sub-account ID | GHL → Settings → Business Info |
GHL_WORKFLOW_ID_SEND_PROPOSAL |
Workflow to trigger after contract created | GHL → Automation → Workflows |
SLACK_WEBHOOK_URL |
Incoming webhook URL | api.slack.com/apps → Incoming Webhooks |
APP_BASE_URL |
Public URL of this app | e.g. https://proposals.talkerstein.com |
ANTHROPIC_MODEL |
(Optional) Override Claude model ID. Defaults to claude-sonnet-4-5. |
Anthropic model catalog |
- Create a new Google Cloud project (or reuse one).
- Enable the Google Docs API, Google Drive API, and Google Sheets API.
- Create a service account and generate a JSON key. Download the file.
- Paste the entire JSON contents (single line, quoted) into
GOOGLE_SERVICE_ACCOUNT_JSON. Both\nand real newlines inprivate_keyare handled bylib/google-auth.ts. - In Google Drive, share the template doc, destination folder, and
audit sheet with the service account's
client_emailas an Editor. - Copy the template file ID, folder ID, and sheet ID from each item's URL and put them in the matching env var.
The template must contain these literal tokens. They are replaced via
docs.documents.batchUpdate → replaceAllText.
{{COMPANY_NAME}} {{CONTACT_NAME}} {{DATE}}
{{REF_NUMBER}} {{PROBLEM_STATEMENT}} {{PACKAGE_CODES}}
{{PACKAGE_DESCRIPTION}} {{SCOPE_IN}} {{SCOPE_OUT}}
{{TOTAL_UPFRONT}} {{MONTHLY}} {{PAYMENT_TERMS}}
{{MILESTONE_1}} {{MILESTONE_2}} {{MILESTONE_3}}
To swap in a new template: update the doc → make sure every placeholder above
still appears verbatim → put the new file ID in GOOGLE_DOCS_TEMPLATE_ID. No
code changes needed.
- Get a Private Integration API key from GHL → Settings → Integrations → API. This is the v2-compatible Bearer token.
- Copy your Location ID from Settings → Business Info.
- (Optional) Create a workflow named "Send Proposal" and copy its ID into
GHL_WORKFLOW_ID_SEND_PROPOSAL.
- Create a new Railway service from this repo.
- Add all env vars from
.env.example. - Railway auto-reads
railway.json— build runsnpm run build, start runsnpm run start, and/api/healthis polled as the healthcheck.
vercel→ link the project.- Add all env vars in the Vercel dashboard.
vercel.jsonpins/api/generateto Node 20 with a 90s function timeout.
curl -X POST https://proposals.talkerstein.com/api/generate \
-H 'Content-Type: application/json' \
-d '{
"companyName": "Ridgeline HVAC",
"primaryContact": {
"name": "Sam Novak",
"email": "sam@ridgelinehvac.com",
"phone": "+15551234567",
"title": "COO"
},
"industry": "Home services",
"websiteUrl": "https://ridgelinehvac.com",
"painPoint": "More than half of inbound after-hours calls are never returned.",
"priorAttempts": "Hired a part-time answering service last year; volume and quality were inconsistent.",
"urgencyTrigger": "Entering peak season in 4 weeks.",
"packageCodes": ["B2"],
"ghlAddOns": ["G2"],
"ghlManagedAddOns": ["GM2"],
"consultingAddOns": [],
"markupPercent": 30,
"scopeIn": {
"bullet1": "Two-pipeline CRM build with lead routing",
"bullet2": "Missed-call-text-back and reactivation sequences",
"bullet3": "Calendar booking for service windows"
},
"scopeOut": {
"bullet1": "Paid media spend and ad account management",
"bullet2": "New marketing website"
},
"totalUpfront": 28000,
"monthlyRecurring": 3750,
"paymentSplit": "50/50",
"milestones": {
"m1": { "description": "Intake + pipeline build", "date": "2026-05-08" },
"m2": { "description": "Automation + missed-call flows", "date": "2026-05-22" },
"m3": { "description": "Training + go-live", "date": "2026-06-05" }
},
"salesOwner": "Rish",
"deliveryLead": "Rems"
}'Response shape:
{
"success": true,
"requestId": "req_…",
"refNumber": "TCG-2026-0001",
"docUrl": "https://docs.google.com/document/d/…/edit",
"ghlContractId": null,
"ghlContactId": "…",
"ghlOpportunityId": "…",
"ghlWarnings": ["TODO: GHL upload-contract endpoint …"],
"internalFlags": [],
"marginPercent": 62.3,
"marginIsRed": false
}GoHighLevel's public v2 API surface is not stable for contract/document
workflows. We refused to guess. The following calls are intentionally
unimplemented and emit a TODO warning plus a console.warn:
- Upload Google Doc as a signable Contract/Document. There is no reliable public v2 endpoint. Fallback: attach the doc URL as a note on the contact.
- Enable e-sign on a contract. Handle manually in the GHL UI until the endpoint is confirmed.
- Attach a Stripe deposit link to an opportunity. The deposit amount is
calculated per the
paymentSplitrule and logged; attach manually. - Opportunity pipeline/stage IDs. Required fields are not part of the
intake. Opportunities are attempted without
pipelineIdand a warning is surfaced if GHL rejects.
The warnings are returned in the ghlWarnings array on the success response
and posted to Slack. Once Rishon confirms the correct endpoints, wire them up
inside lib/ghl.ts — no other file needs to change.
Everything operators typically want to change lives in three files. None of
them require touching the orchestrator (app/api/generate/route.ts).
- Prompt / tone / output shape: edit
PROPOSAL_SYSTEM_PROMPTinlib/prompt.ts. Few-shot examples live inlib/anthropic.ts(FEW_SHOT_EXAMPLES). Update the JSON shape in both places if you add a field and also extendGeneratedProposalinlib/anthropic.tsand the template placeholders inlib/google-docs.ts. - Package codes, names, descriptions, costs, prices: edit the
PACKAGESobject inlib/packages.ts. The UI picker, margin calculator, Claude prompt, and Doc renderer all read from this single source of truth. - Brand colors: edit
tailwind.config.ts(colors.navy,colors.orange,colors.sienna,colors.beige) and the:rootvariables inapp/globals.css. - Margin threshold:
MARGIN_RED_THRESHOLDinlib/margin.ts. - Ref number format:
nextRefNumberinlib/sheets.ts.
- External APIs retry 3× with exponential backoff (
lib/retry.ts). Claude is called once (no retry). - Every external call logs with a request ID (
req_<timestamp>_<nonce>). - Type-safe end to end.
anyis avoided in application code. - Build passes without real env vars — env is validated lazily at call time.
- Node 20+ only.