I use github to host the files, Claude chat AI to make a project requirements document, and claude code to actually do all the work. I wanted to show you what a brief pre-chat can do to make a PRD and ensure you get a good "core" app to refine with 1 super prompt.
The following is the back and forth I did with AI to create a project requirements document for a new addon to my SquareDashboardTool I am developing - a delivery manager
ME:
I have an existing app, I need to add a new function to it and need a project requirements document. We should be using open maps (or other free map service for routing) and square api to create a delivery scheduling app. We already grab a number of square features and have a webhook working. Ideally this will become a new component for this existing app. Claude will be workign with a copy of the github repo and have access to its existing code base. It will collect all orders from Square, clear orders based on squares status, "new" "ready" "delivered" I want a route calculator for all "active" orders that calculate the most efficient route based on a user defined starting address. We should also have the ability to add manual orders into the que, but will auto collect and clear active orders from the Square webhook/api - All orders should have a notes section available for active orders that may need follow up or other notes until fulfilled is marked completed. Ask me any questions you need for this to make a viable addon to our app.
Show less
6:35 PM
AI:
Identified critical gaps and prioritized clarifying questions strategically.
The user wants a project requirements document for a delivery scheduling app component. Let me ask clarifying questions to fill in the gaps. They mentioned they have ADHD and prefer minimal text, so I'll keep this tight.
Key gaps I need to fill:
Tech stack of existing app
Current Square integration scope
User roles/auth
Mobile vs desktop
Delivery windows/time constraints
Multi-driver support?
Address storage/customer data
What "active" means exactly in their workflow
Quick clarifying questions:
Tech Stack
What's your existing app built with? (React, Vue, Node, etc.)
Hosted where? (Vercel, self-hosted, etc.)
Workflow 3. Single driver or multi-driver routing? 4. Do orders have delivery windows/time slots, or just "get there efficiently"? 5. What triggers "ready" status in Square — manual or automated?
Data 6. Are customer addresses already stored in Square order data, or pulled from elsewhere? 7. Do you need route history/logging, or just live "today's route"?
UI 8. Desktop-only, or need mobile for driver use? 9. Does the driver need turn-by-turn, or just the optimized stop order + addresses?
Edge Cases 10. What happens if a new order comes in mid-route — auto-recalculate or manual refresh?
Answer what you can, skip what you're unsure about — I'll make reasonable assumptions and flag them in the doc.
ME:
We are self hosted on a pi5 running on psql and node.js currently single driver routing, me - Proof of delivery should be an option we can start me upload pic from camera roll, but ideally will pull up camera in app (this will be webbased primarily not device driven) Square has an order status we should be able to read it from webhook, staff trigger as ready from new All addresses should be in the order aside from manual added to que System should follow our multi tenant approach to allow for SAAS marketing of the tool Driver just needs Efficient order list with addresses We would need to go back to depot to get new orders once we "leave" currently we have a "same day cut off" lets make that user configurable - Same day before 5pm for me currently, but plan to adjust that. or perhaps a check box and generate route from all active orders would be easier
AI:
Synthesized requirements and pinpointed critical clarifications needed.
The user is giving me good details. Let me summarize what I understand and identify gaps:
Confirmed:
Self-hosted Pi5, PostgreSQL, Node.js
Single driver (but multi-tenant for SaaS)
Web-based app
Proof of delivery with photo upload (camera roll now, native camera later)
Square webhook triggers status changes (staff marks ready)
Addresses in Square orders
Multi-tenant architecture required
Driver needs optimized stop list with addresses (not turn-by-turn)
User-configurable same-day cutoff time
Checkbox approach to generate route from active orders seems preferred
Still need clarity on:
How is multi-tenancy currently implemented? (tenant ID in tables? separate DBs?)
What's the existing webhook structure look like?
Route history/logging needs?
What happens when order is marked "delivered" - just status change or any other actions?
Manual order fields - what data is required for a manual order?
Does "depot" mean driver needs to return to starting point for new orders, or just refresh the app?
Should the system prevent adding to route after "route started" until route completed?
Let me ask the most critical remaining questions to write a solid PRD.
Good info. Few more critical gaps:
Multi-tenant
How is tenancy currently handled? (tenant_id column? schema per tenant? other?)
Each tenant gets their own Square connection/credentials already?
Route Logic 3. When you "leave" — is that a button press that locks the route? Or just mental? 4. Should completed deliveries stay visible in today's view, or immediately archive? 5. Return-to-depot as final stop in route calculation, or just one-way optimization?
Manual Orders 6. Required fields for manual add? (Name, address, phone, items — what's minimum?)
Proof of Delivery 7. Photo only, or also capture signature/timestamp/GPS? 8. Who sees the POD — just you, or customer gets copy?
Notifications 9. Any customer notifications needed? (SMS/email "driver en route" or "delivered") 10. Or strictly internal tool for now?
Once I have these, I'll draft the PRD. Keep answers short — I'll interpret.
ME:
there is a merchant id in the schema because we were single tenant prior and converted, address and phone number, photo only, kept on file for 60 days for (for credit card challenge, is there a time limit we should plan for that is longer?) square handles notifcations once we mark completed in square, perhaps the option to mark completed in square via webhook that will send the notifications
6:43 PM
AI:
Synthesized requirements and prepared to draft comprehensive specification.
The user has answered most of my questions. Let me summarize what I know:
Multi-tenant: merchant_id in schema (converted from single tenant)
Manual orders: address and phone number required
POD: photo only, kept 60 days for chargeback disputes
Notifications: Square handles it - just need to update order status via API which triggers Square's notifications
They asked about chargeback time limits. I should look this up - chargebacks can be filed up to 120 days typically for Visa/Mastercard, but some can go longer. I should search to give accurate info.
Remaining questions I still need:
Route locking mechanism (when they "leave")
Return to depot in calculation or not
Completed deliveries - archive immediately or stay visible
But honestly, I think I have enough to draft a PRD now. I can make reasonable assumptions and flag them. Let me ask the last critical questions quickly and then offer to draft.
Chargeback window: 120 days is standard for Visa/MC. Recommend 180 days retention to be safe with processing delays.
Last 3, then I'll draft:
"Leave" trigger — button press that locks current route, or checkbox "generate route" that snapshots active orders at that moment?
Return to depot — include as final stop in optimization, or just optimize delivery sequence?
Completed orders — stay visible in today's view until end of day, or archive immediately after POD?
ME:
Generate route checkbox, return to user defineable address (i myself plan to go home after routes generally, others may return to store or depot)
6:46 PM
AI:
Synthesized delivery routing system with customizable return destinations.
The user has answered my questions. Let me summarize what I know:
Tech Stack:
Self-hosted on Pi5
PostgreSQL + Node.js
Web-based
Multi-tenant (merchant_id in schema)
Workflow:
Single driver routing (per tenant)
"Generate route" checkbox triggers route snapshot
User-definable end address (home/depot/store)
Same-day cutoff is user-configurable (e.g., 5pm)
Staff trigger orders as "ready" from "new" in Square
Data:
Addresses from Square orders
Manual orders need: address + phone number (minimum)
POD: photo only, 180 days retention
Notes section for active orders
Route:
Efficient order list with addresses
Uses free mapping (OpenRouteService, OSRM, etc.)
Optimize sequence, end at user-defined address
Square Integration:
Already have webhook working
Read order status from webhook
Mark completed in Square via API (triggers Square's customer notifications)
Multi-tenant:
merchant_id column approach
Each tenant would need their own Square connection (already exists)
Completed orders:
User didn't answer directly, but I'll assume archive after POD/completion - keep in history but not in active view
Let me draft a PRD for this delivery scheduling component.
Got it. Drafting PRD now
Identified key feature requirements and user customization needs.
Good, the file is now available to the user. I should summarize the key decisions and open questions that need their input.
PRD ready.
Key decisions I made (flag if wrong):
180-day POD retention
Route locks on generate — new orders wait for next batch
No built-in turn-by-turn, just tap-to-open native maps
Need your input on Open Questions:
Geocoding — Square may not have lat/lng. Should I plan for OpenRouteService geocoding step, or do you know Square provides coords?
Failed delivery — customer not home. Separate status? Back to pending? Skip for now?
Duplicate orders — same customer, same day. Merge into one stop or keep separate?
Offline — browser cache route if Pi drops? Or accept risk for MVP?
Once you answer, I'll be ready to review your existing codebase when you share it.
ME:
Square does not provide coordinates, only address mark a failed delivery with skip order and nothing will happen in Square, and if we mark the route finished, it will just get added to next que keep order seperate, we can mark skip or mark confirmed and just take a seperate picture offline, is offline, we also need to ensure we follow security when deisgning this, including requiring our login sessions, we dont want customer info exposed
6:51 PM
AI:
Synthesized delivery workflow, offline capabilities, and security protocols.
The user has clarified:
Square doesn't provide coordinates - need geocoding step
Failed delivery = "skip" status, stays in system, rolls to next queue when route finished
Separate orders even for same customer - individual POD per order
Offline is offline (accept the risk), but security is critical - require login sessions, protect customer data
I should update the PRD with these clarifications and add security requirements.
Updating PRD with clarifications and security requirements.
Synthesized delivery logistics and security requirements.
Good, the file has been updated and presented. Now I should summarize the key changes for the user.
Updated PRD with:
Geocoding step added (OpenRouteService, cached per order)
skipped status + rollback flow on route finish
Security section (auth required, no client-side PII caching, authenticated POD endpoint, tenant isolation)
DB indexes for performance
One flag: OpenRouteService free tier = 2,000 requests/day for geocoding. If you're doing 50+ orders/day across tenants as SaaS, you'll hit limits. Options:
Self-host Nominatim (free, but Pi may struggle)
Paid tier when needed (~$50/mo)
Cache aggressively — repeat customers = no re-geocode
Ready to review your codebase when you share it.
The result of this 3 minute conversation is a block of text I will give claude, it will code the entire app and then I will use futher prompts to debug and refine as needed:
Delivery Scheduler Component — PRD
Overview
Add-on component for existing JTPets multi-tenant app. Manages delivery routing, proof of delivery, and Square order sync.
Core Features
1. Order Ingestion
Auto-collect orders via existing Square webhook when status = "ready"
Auto-clear orders when Square status = "completed" or "cancelled"
Manual add: Form with fields — name, address, phone, notes (optional)
Orders tagged with merchant_id for multi-tenant isolation
2. Order States (Internal)
State Description
pending Ready in Square, not yet on route
active On today's generated route
skipped Driver skipped (not home, etc.) — rolls to next queue
delivered POD captured, pending Square sync
completed Synced to Square as fulfilled
3. Route Generation
Trigger: "Generate Route" checkbox/button
Inputs:
Start address (user-configurable, stored per user)
End address (user-configurable — home/depot/store)
All pending orders at snapshot time
Engine: OpenRouteService API (free tier) or OSRM
Output: Ordered list of stops optimized for distance/time
Locking: Once generated, route is snapshot — new orders go to next batch
4. Cutoff Configuration
Per-tenant setting: same_day_cutoff_time (default 17:00)
Orders marked ready after cutoff = next day unless manually added
Consider: simple checkbox override "Include in today's route" for flexibility
5. Driver View
Mobile-friendly web view
Shows: Stop # → Customer name → Address → Phone → Notes
Tap address = opens in device maps app (Google/Apple/Waze intent)
No turn-by-turn built-in — leverage native maps
6. Proof of Delivery
Capture: Button per stop to upload/capture photo
Phase 1: Upload from camera roll
Phase 2: Direct camera capture via getUserMedia API
Storage: Local filesystem or S3-compatible, linked to order
Retention: 180 days auto-purge (chargeback buffer)
7. Order Notes
Editable text field per order
Visible throughout lifecycle until completed
Use cases: gate codes, "call on arrival", follow-up reminders
8. Square Sync
Inbound: Webhook updates order status
Outbound: API call to mark order "completed" in Square
Triggers Square's customer notification system
Webhook endpoint: extend existing handler
Data Model (Additive)
sql
-- Delivery orders (extends/references Square orders)
CREATE TABLE delivery_orders (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
merchant_id UUID NOT NULL REFERENCES merchants(id),
square_order_id VARCHAR(255), -- null for manual orders
customer_name VARCHAR(255) NOT NULL,
address TEXT NOT NULL,
address_lat DECIMAL(10, 8), -- geocoded latitude
address_lng DECIMAL(11, 8), -- geocoded longitude
geocoded_at TIMESTAMP, -- null = needs geocoding
phone VARCHAR(50),
notes TEXT,
status VARCHAR(50) DEFAULT 'pending', -- pending, active, skipped, delivered, completed
route_position INTEGER, -- sequence in generated route
route_date DATE,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
CREATE INDEX idx_delivery_orders_merchant_status ON delivery_orders(merchant_id, status);
CREATE INDEX idx_delivery_orders_route_date ON delivery_orders(merchant_id, route_date);
-- Proof of delivery
CREATE TABLE delivery_pod (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
delivery_order_id UUID NOT NULL REFERENCES delivery_orders(id),
photo_path TEXT NOT NULL,
captured_at TIMESTAMP DEFAULT NOW(),
latitude DECIMAL(10, 8), -- optional, if we add GPS
longitude DECIMAL(11, 😎
);
-- Tenant delivery settings
CREATE TABLE delivery_settings (
merchant_id UUID PRIMARY KEY REFERENCES merchants(id),
start_address TEXT,
end_address TEXT,
same_day_cutoff TIME DEFAULT '17:00',
pod_retention_days INTEGER DEFAULT 180
);
-- Route history (optional, for auditing)
CREATE TABLE delivery_routes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
merchant_id UUID NOT NULL REFERENCES merchants(id),
route_date DATE NOT NULL,
generated_at TIMESTAMP DEFAULT NOW(),
total_stops INTEGER,
total_distance_km DECIMAL(10, 2),
estimated_duration_min INTEGER
);
API Endpoints
Method Endpoint Description
GET /api/delivery/orders List orders by status/date
POST /api/delivery/orders Manual order add
PATCH /api/delivery/orders/:id Update notes/status
DELETE /api/delivery/orders/:id Remove manual order
POST /api/delivery/orders/:id/skip Mark order skipped
POST /api/delivery/route/generate Snapshot & optimize route
GET /api/delivery/route/active Get today's active route
POST /api/delivery/route/finish End route, roll skipped → pending
POST /api/delivery/orders/:id/pod Upload POD photo
POST /api/delivery/orders/:id/complete Mark complete + sync Square
GET /api/delivery/settings Get tenant settings
PUT /api/delivery/settings Update tenant settings
UI Components
Settings Page
Start address input
End address input
Same-day cutoff time picker
POD retention days (admin only?)
Order Queue
Filter tabs: Pending | On Route | Completed Today
Each card: Name, address (truncated), status badge, notes preview
Actions: Edit notes, Remove (manual only)
Route View
"Generate Route" button (disabled if route exists for today)
Ordered stop list with:
Stop number
Customer name
Full address (tap to open maps)
Phone (tap to call)
Notes (expandable)
POD button (camera icon)
Complete button
Progress indicator: 3/8 stops completed
POD Capture Modal
Camera preview (Phase 2) or file upload (Phase 1)
Confirm/retake buttons
Auto-advances to next stop on confirm
Security Requirements
Authentication
All delivery endpoints require valid session token
Extend existing auth middleware — no new auth system
Session timeout: match existing app settings
No "remember me" on shared/driver devices
Authorization
Tenant isolation enforced at query level (WHERE merchant_id = ?)
POD photos stored in tenant-namespaced paths
No cross-tenant data access possible
Data Protection
Customer PII (name, address, phone) never cached client-side beyond current session
Route data cleared from browser on logout/session expire
POD photos: no customer address in filename, use UUID only
HTTPS required — no HTTP fallback
API responses exclude soft-deleted/archived orders
Driver View Security
Driver view = same auth as admin, just different UI
No anonymous/public route links (Phase 3 customer tracking will need separate token system)
Auto-logout on browser close (no persistent local storage of sensitive data)
Audit Trail
Log: who generated route, when, how many stops
Log: who marked complete, when, POD captured Y/N
Log: failed login attempts (existing system)
POD Storage
Files stored outside web root, served via authenticated endpoint
No direct URL access to photos
180-day retention, then hard delete (not soft delete)
Integration Points
OpenRouteService (Routing)
Endpoint: https://api.openrouteservice.org/v2/directions/driving-car
Optimization: Use /optimization endpoint for TSP (Traveling Salesman)
Rate limit: 2,000 requests/day free tier — sufficient for single-tenant low volume
Fallback: OSRM self-hosted if rate limits become issue
Square API
Read: GET /v2/orders/{order_id} — verify status
Update: PUT /v2/orders/{order_id} — mark fulfilled
Webhook: Extend existing handler for order.updated events
Phases
Phase 1 (MVP)
Order ingestion from Square webhook
Manual order add/remove
Basic route generation (distance-optimized)
Driver view with stop list
POD upload from camera roll
Mark complete → sync to Square
Tenant settings (addresses, cutoff)
Phase 2
Direct camera capture for POD
Route history/audit log
Re-optimize route (if order removed mid-route)
GPS capture with POD
Phase 3 (SaaS)
Multi-driver support per tenant
Driver assignment UI
Customer-facing tracking link
Analytics dashboard (avg delivery time, etc.)
Resolved Questions
Geocoding: Square does NOT provide coordinates. All addresses must be geocoded via OpenRouteService before route optimization. Cache geocoded coords in delivery_orders table to avoid repeat lookups.
Offline handling: Accept risk. Offline = offline. No service worker caching for MVP. Security takes priority over offline access.
Duplicate orders: Keep separate. Same customer, same day = separate stops, separate POD photos. Driver can skip or complete individually.
Failed delivery flow: "Skip" status. Order remains in system, does not sync to Square. When route marked finished, skipped orders roll back to pending for next route generation.
Tech Notes
Geocoding flow: On order ingest (webhook or manual), queue geocoding job. OpenRouteService geocoding = 2,000/day free. Cache results in address_lat/address_lng. Route generation fails if any order not geocoded — show error "X orders need address verification".
Route optimization = NP-hard. For <20 stops, brute-force or nearest-neighbor heuristic is fine. OpenRouteService optimization handles this.
Camera API (getUserMedia) requires HTTPS. Ensure Pi has valid cert or use tunneling for dev.
POD photos: compress client-side before upload to save Pi storage. Target ~500KB/image.
Skipped order rollback: POST /route/finish sets all skipped orders back to pending, clears route_position and route_date.
Success Metrics
Route generated in <5 seconds
POD capture to Square sync <10 seconds
Zero missed chargebacks due to missing POD (180-day coverage)
Driver can complete full route without returning to queue screen
I fed the prompt to claude and it has done the work - Tomorrow I will verify the code runs and debug if it does not, before beginning refinement of the design and quality of life imprvements to make it work "better" and do some security audits to reduce risk of breech:
I've successfully implemented the Delivery Scheduler Component. Here's a summary of what was created:
| GET | /api/delivery/orders | List orders by status |
| POST | /api/delivery/orders | Create manual order |
| PATCH | /api/delivery/orders/:id | Update order notes |
| DELETE | /api/delivery/orders/:id | Remove manual order |
| POST | /api/delivery/orders/:id/skip | Mark order skipped |
| POST | /api/delivery/orders/:id/complete | Complete + sync to Square |
| POST | /api/delivery/orders/:id/pod | Upload POD photo |
| GET | /api/delivery/pod/:id | Serve POD photo |
| POST | /api/delivery/route/generate | Generate optimized route |
| GET | /api/delivery/route/active | Get today's route |
| POST | /api/delivery/route/finish | Finish route, roll skipped |
| GET/PUT | /api/delivery/settings | Manage settings |
| GET | /api/delivery/stats | Dashboard statistics |
The changes have been committed and pushed to branch claude/delivery-scheduler-component-IozB4.
You are scaring me now...how do you find time to run a business, do the life stuff plus all this. Do you sleep? Very impressive!
I would say I do not infact sleep, I lose conscienceness for about 5 or 6 hours - not sure it counts as sleep tho. This is done while I am at work - the nice thing about a pet store is half my day is spent petting puppies and watching tiktok. So I just refocus that energy into my claude subscription 🙂
What I wouldn't give to be thirty years younger and to have the time and wherewithal to do this sort of thing! That's pretty darned impressive, John. Might I add that it is a tad scary, too? Ha.
Sick!!! Love to see it
Square Community