Tender Management System
A simulated end-to-end build: from a client brief and a written SRS to a tested, deployed, public backend on Cloudflare Workers
This project is a simulation of how I would build an app for a client, end to end. It started from a business brief with a lot of rules and a short deadline, and I used it to practice (and show) the whole path: requirements, system design, implementation, testing, hardening, and shipping something public.
The domain is commercial tenders (“licitaciones”): a company drafts a tender for a client, attaches a proposal document, sends it by email, tracks it until it is won or lost, invoices it, and collects payments. Simple to describe, but full of the things that make backends interesting: a strict lifecycle, money, files, email, scheduled jobs, concurrency, and roles.
You can try it right now: the live demo has a one-click read-only login, and the API is documented in Swagger UI. The code is on GitHub.
The process, not just the result
I wanted this to show how I work, so the steps are part of the project:
- First build. A working version in a few days from the brief: Hono on Cloudflare Workers, Supabase Postgres and Auth, R2 for proposal files, Resend for email with attachments, and Cron Triggers for expiry and reminders.
- Audit. I went back over it with a critical eye. The review produced 22 findings, which I grouped into 7 issues and worked through one by one.
- A written SRS. Before fixing more, I wrote a Software Requirements Specification with scope, roles, functional requirements, business rules, error contract, data model, lifecycle, security and quality attributes, and a traceability appendix. It became the source of truth for what the system must do and for what the tests must cover.
- Issue-driven delivery. Work was split into GitHub issues, each implemented test-first (red, green, refactor) with atomic commits, then reviewed against two questions: does it follow the repo’s standards, and does it match the spec?
- Redesign. The first UI worked but looked generic for an internal B2B tool. I defined a design system first (semantic tokens, shared table, tooltip and dialog components), then a couple of pilot screens, then the rest.
- Going public. Opening the repo meant a security pass: restricted CI token permissions, pinned actions by SHA, CodeQL scanning, Dependabot, a security policy, and a demo account that cannot write.
I used AI coding assistants throughout, as I would on a real team: to explore options, write and review code, and run checklists. The decisions, the trade-offs and the invariants below are mine, and each one is enforced in code and tests rather than only described in prose.
System design
Browser (React SPA)
│ same origin
▼
Cloudflare Worker (Hono + chanfana) ──► R2 proposal PDFs
│ │ └──► Resend emails with attachment
│ └── Cron Triggers: expiry + 48h reminders
▼
Hyperdrive (connection pooling)
▼
Supabase Postgres + Auth (Drizzle ORM)
One Worker serves the API and the SPA (through the assets binding), so there is one deployable unit and no CORS surface. Routes are one-class-per-file chanfana endpoints with Zod schemas, which gives typed validation and an always-accurate OpenAPI spec for free.
The layering is deliberate. Endpoints are thin. Everything that knows a business rule lives in src/domain/tenders/ (state machine, rules, payments, locking). External services are isolated in src/services/. That separation is what lets the tests exercise the rules through the real API instead of mocking internals.
Design decisions
One writer for the state machine
Tenders move through draft → active → finalized → for_collection → collected, or to lost. Any other transition must be rejected. Rather than check this in each endpoint, a single function, transitionTender(), is the only code allowed to write tenders.status. It validates against a whitelist and writes the history row in the same operation, so no endpoint or cron job can skip the rules or leave the audit trail out of sync.
Row locking for every mutation
Requests and the cron job can touch the same tender at the same time. Every mutation (edit, send, finalize, invoice, pay, expire) runs inside withLockedTender(): one transaction that takes SELECT ... FOR UPDATE on the tender row. Two concurrent payments cannot both pass the balance check, and the expiry job cannot race a manual action.
Money is compared in cents
Payments are checked against the outstanding balance, and when it reaches zero the tender moves to collected automatically. Floating point makes 1000 - 333.33 - 666.67 miss zero, which would leave a tender stuck forever in for_collection. Comparing integer cents fixes it, and a test was written first to prove the bug before the fix.
Idempotent reminders with retry
The 48-hour reminder is the kind of job that fails in interesting ways. Each reminder runs under the tender lock, the email is sent first, and reminder_sent_at is written only after the send succeeds. So a failed send is retried by the next run, and overlapping runs queue on the lock instead of double-sending. The send is capped at 10 seconds so a hung provider cannot hold the lock. Delivery is at-least-once, and I documented the one remaining edge case instead of hiding it. Sending a tender with under 48 hours left marks the reminder as already sent, so the client does not get two emails in a row.
Hyperdrive instead of per-request connections
Short-lived Worker isolates would open a new Postgres connection per request. All runtime queries go through the HYPERDRIVE binding, which pools them. The Worker never reads DATABASE_URL; that exists only for drizzle-kit migrations.
Files, email and secrets
Proposal documents go to R2 (S3-compatible, no egress fees) and a tender cannot be sent without one. Emails are real, with the proposal attached, HTML-escaped, and a provider failure maps to a clear 502 EMAIL_DELIVERY_FAILED instead of a silent success. Secrets never live in wrangler.jsonc: local values go in .dev.vars, production ones through wrangler secret put, with a helper script that refuses to run against a local Supabase.
Roles and the public demo
Admins create users; a viewer role is read-only across the whole API through middleware, and the UI disables write actions with a tooltip explaining why. That lets me publish a working login without trusting anonymous visitors with write access.
Testing
The test suite runs inside the real Workers runtime (@cloudflare/vitest-pool-workers) against a real local Supabase, not mocks. It covers the API contract, cron behavior, the state machine, mutation locking, integrity constraints, pagination, search, uniqueness and the send flow. Only the outgoing Resend call is stubbed, so tests never send real email. The set of behaviors that must be covered is defined in the SRS (Appendix B), and CI runs typecheck, lint and the full suite on every push and pull request.
The frontend
The SPA is intentionally secondary to the backend work, but it is built to feel like a real internal tool: a dashboard with charts and an activity feed, server-side search, sorting and pagination with filters in the URL, a command palette (Ctrl+K, plus g then a key to navigate), lazy-loaded pages, and semantic design tokens instead of raw palette classes.
Why it is on my portfolio
This project shows my ability of turning requirements into a spec, protecting invariants with design, proving them with tests, and leaving a repo that someone else can read, run and trust.