Clever Offers prototype
A working slice of the investor-offers system from my proposal. An agent builds a package, the system matches it to investors and says why, sends it to the top few, investors make offers, and the agent compares them and accepts one. Every record has one owner, the deal's status lives in one place with a timeline, and each status change reaches HubSpot through an outbox. If HubSpot is down, the update waits and retries; it doesn't get lost.
Demo-only shortcuts
I took these on purpose so the prototype runs with one command. None of them would ship.
- No real logins for the agent and investor pages. The "view as" page (
/view-as/) lets anyone act as any agent or investor. - Investors see the full property address. In production the address stays hidden until the investor accepts terms.
- Reachable on your network while running. The port is published as
8000:8000, as the submission rules ask. DEBUGis on, the secret key is a placeholder,ALLOWED_HOSTSis*, and it runs on Django's built-in server.- All data is made up: people, companies, streets and cities.
Run it
docker compose up --build
Open http://localhost:8000/. The first start migrates and loads the demo data. Later starts leave your changes alone. This README and the technical design are also linked from the yellow banner on every page (/docs/readme/ and /docs/technical-design/).
- Django admin: http://localhost:8000/admin/, user
admin, passworddemo-admin-password. - Start another deal with New deal on the agent's deal list, or reset the demo data with
docker compose down -v, thendocker compose up --build. - Run the outbox worker:
docker compose exec web python manage.py run_outboxsends whatever is due. Add--nowto skip the retry waits (demo only). - Run the tests while it's running (about 7 seconds):
docker compose exec web python manage.py test - Memory: the web container fits in 2 GB. Clever's test limit (
mem_limit) applies when the container runs, not todocker compose build.
A short walkthrough
You start as agent Dana Whitfield and investor Alan Brightwater. The header shows both, with a Switch link.
- Matching with reasons. On Agent deals, open 412 Sample Oak Lane (a draft) and click Find investors. Six investors match, ranked by close rate, each with the reason. The top 5 are marked "Will be sent" and one is "Over cap". Tessa Underhill would match too, but she's paused in the admin, so she isn't listed. If you lower the send cap before sending (in the admin, open Matching policies, change the number in the Cap column and click Save), more investors show "Over cap".
- Send. Click Send. The deal moves to "Sent" and the timeline records who it went to. Sending again, from a double-click or two people at once, creates nothing new and says "Already sent".
The status now also says "HubSpot sync: 1 pending / 0 dead". That's the outbox: the deal moved on without waiting for HubSpot, and the update is queued. Nothing sends it until the worker runs, so run
docker compose exec web python manage.py run_outboxand reload; it says "up to date". Run it again after the steps below whenever you want the line cleared. - An investor offers. Go to Investor deals (you're Alan). Open 88 Example Court, which says "No response yet", and submit an offer.
- Compare and accept. Go back to Agent deals → 88 Example Court → Compare offers. There are three offers side by side, each against the listing estimate, labeled "before costs, not net to seller". Accept one. The others are declined, and the timeline says so.
- Close. On the deal page, under Close or end this deal, choose Closed (sale completed) and click Save outcome. The status changes to "Closed" and the timeline shows every step.
- See the rest. Switch to agent Marcus Oyelaran (a deal with an accepted offer, and a closed one) or Priya Raman-Cole (two ended deals; the deal list shows each reason, and on "contract fell through" the accepted offer stays accepted). Switch to investor Fiona Garrity to see a declined offer and a send that closed when another offer was accepted.
- Break HubSpot on purpose (about a minute). HubSpot here is a stand-in table.
- Run
docker compose exec web python manage.py run_outboxonce so nothing from the earlier steps is still waiting. - In the admin, open Integration settings, tick the box in the Hubspot failing column and click Save.
- Change a deal's status. For example, Switch to agent Marcus Oyelaran and open 1500 Placeholder Drive. It starts at "Offer accepted" with "HubSpot sync: up to date". Under Close or end this deal, choose Closed (sale completed) and click Save outcome. The deal page now says "Closed" and "HubSpot sync: 1 pending / 0 dead".
- Run
docker compose exec web python manage.py run_outbox --nowfour times. The first three runs fail and schedule a retry; the fourth marks the message dead. The deal page says "HubSpot sync: 0 pending / 1 dead". - In the admin's Integration settings, untick the box and click Save. Then open Outbox messages, click Dead under the filter on the right, tick the row, choose Replay selected dead messages in the Action list and click Go.
- Run
docker compose exec web python manage.py run_outboxonce more. The message is sent, Fake hub spot deals shows the deal as "closed", and the deal page says "up to date". Replaying it again does no harm.
- Run
- Start your own deal. New deal on the agent's list creates a property, a draft deal and its package in one step. Then run steps 1 and 2 on it. A draft isn't sent to HubSpot; the first update goes when it's sent to investors.
- Admin. Deals, sends, offers, the timeline and the outbox are read-only in the admin. Investors (including the pause flag), buy boxes, the send cap and the HubSpot fail switch are editable; the send cap and the fail switch can be changed right on their list pages.
How the 5 apps map to the 8 production modules
Dependencies run one way: integrations ← deals ← investors ← matching ← offers. A lower app never imports a higher one.
| Prototype app | Production modules | What it owns here |
|---|---|---|
integrations |
The shared Integrations piece | The outbox, the retry worker, the fail switch, and a fake HubSpot. Imports nothing from the other apps. |
deals |
Properties, Packages, Deals | Properties, packages, deals, the deal status rules and the timeline |
investors |
Investors | Investors (with the pause flag) and buy boxes. There are no write rules yet; staff edit them in the admin. |
matching |
Matching | match(), the send cap, and sends with their match reasons |
offers |
Offers, plus the workflow layer | Offers, and the workflows that change several apps at once (send, offer, pass, accept, close, end) |
| (not built) | Fees | Fee tracking. See docs/technical-design.md. |
The workflows sit in offers because it's the top app, the only one allowed to import all the others. The technical design describes the same thing: a thin workflow layer above the modules.
Code tour
deals/services.py: the deal status rules (DEAL_TRANSITIONS),change_status, andrecord_event, the only way a timeline row is written.integrations/services.py:enqueue(called bychange_status, inside its transaction),process_due(the retry worker),replay, and the fake HubSpot.matching/services.py:match(). It filters by buy box, ranks, marks the top N, and builds the "why it matched" text.offers/services.py: the cross-app workflows. Each one locks the deal row, re-reads it, checks the rules, then writes.*/models.py: the database constraints listed below.deals/access.py,investors/access.py,matching/access.py: who you're acting as, and the lookups that only return your own deals or sends. Real logins would replace these few functions.*/admin.py: the locked-down admin.offers/management/commands/seed.py: the demo data. Deals, packages, sends and offers are created through the same services the screens use, so their timelines are real.- Tests:
*/tests.pyandoffers/test_workflow.py. scripts/verify_submission.py: zips the project, unzips it in a clean folder, builds with no cache under a 2 GB limit, and checks that it starts, answers on a non-localhost host name, and restarts cleanly.
Failure handling in the code
The outbox. Every deal status change writes an outbox row in the same transaction, so the change and the "tell HubSpot" work commit or roll back together. A worker command sends due rows, waits longer after each failure (10, 30 and 90 seconds here, short for the demo), and marks a row dead after four failed tries. Each row's key is fixed when it's written (hubspot_deal_status:<deal>:<version>), so sending it twice does no harm.
Two simplifications to know about:
- The fake HubSpot lives in the same database, so the worker sends and records "sent" in one transaction. In production the call to HubSpot happens outside any transaction, and a worker can crash after HubSpot accepted the update but before recording it. Then the update goes out twice. A test sends one twice on purpose to show the second does nothing.
- The fake HubSpot ignores an update older than the one it has. Real HubSpot won't, so in production our side keeps the order; the technical design says how.
Left in the written design: Celery and Redis (here the worker is a command you run), leases so several workers can share the list, reconciliation, email and SMS, and alerts.
The integrity guards. These keep the data right when people click twice, act at the same time, or try something out of order.
- Every workflow runs in a transaction and locks the deal row (
select_for_update) before checking its status, so two people acting on one deal are handled one after the other. A test checks that each workflow takes the lock before it writes anything, and another races two real accepts on one deal against Postgres: exactly one wins. I haven't load-tested it. - Database constraints are the backstop: one deal in progress per property, one send per deal and investor, one offer per send, one accepted offer per deal, "ended" if and only if there's a reason, prices above zero, a buy box's minimum at or below its maximum, and a send cap of at least 1.
- Each record has one table of allowed status changes. A refused change shows as a message, never a 500, and writes nothing.
- Sending a deal twice returns the same sends.
- Accepting an offer declines the others and closes the open sends in the same transaction. Ending a deal does the same.
- The admin can't add, change or delete deals, sends, offers or timeline rows.
- An agent only reaches their own deals, and an investor only their own sends. Anything else is a 404.
Corners cut
The full list, with how production would handle each one, is in docs/technical-design.md. The biggest:
- The outbox is a thin slice: one worker run by hand, a fake HubSpot, no Celery, leases, reconciliation, email or SMS.
- No real logins, and addresses aren't hidden from investors.
- Plain Django pages stand in for the React screens. Agent screens would live in the existing Agent Portal.
- Matching ranks by close rate only, and the cap is the only setting. Production has weighted ranking, waves and a versioned policy.
- No package versions, offer revisions, net-to-seller figures or fees.
Offer.dealis a copy of the send's deal so the database can enforce one accepted offer per deal. Only the offers service sets it, and accept checks it. Production would use a composite foreign key.
Notes on the code
I wrote it so someone new to the codebase, or an AI tool, can follow it on a first read: plain service functions you can call and test, and no Django signals. My background is .NET, so you'll see .NET comparisons in the comments, like select_for_update as an UPDLOCK and a partial unique constraint as an EF Core filtered index.
This is my first Django project. My experience with each piece:
| Technology | My experience |
|---|---|
| Python | Through AI only; little hand coding |
| Django and its test framework | None before this |
| PostgreSQL (including JSONB) | Production |
| Docker Compose | Some |
How this was built
I set the context and made every decision; AI drafted and built.
- Plan, build, review. Each build step was planned with a stronger model (Claude Opus) and built with a faster one (Claude Sonnet). A reviewer agent playing a senior Django engineer reviewed every step, and I decided on each finding. The tests and the verify script were rerun after every builder report rather than taking its word for it, which once caught a failing test the builder had reported as passing.
- Reviewer agents. Ten role-based reviewers challenged the plan before the build, and six of them reviewed the finished prototype. The roles: Head of Product, a founder, the Offers PM and ops lead, an engineering manager, a staff engineer, a senior Django engineer, QA and reliability, security and compliance, a red team comparing it to a generic AI answer, and an editor.
- The review log (
docs/review-log.md) lists every finding and what I accepted, rejected and why.