Skip to content
All projects

BACKEND / CLOUD / FULL STACK

live

BorrowHood

A neighbourhood lending app: a React single-page app and a Flask modular monolith on PostgreSQL, with a transactional outbox and a background worker. It runs in production on one ARM server in Stockholm, built with Terraform, for about 6 USD a month.

  • Live on AWS
  • 122 API routes
  • 16 domain modules
  • 133 backend tests
Context
Personal product, built and operated end to end
Period
2026

The repository is private. I'm happy to walk through the code in an interview.

Stack

  • Python
  • Flask
  • SQLAlchemy
  • PostgreSQL
  • React
  • TypeScript
  • Vite
  • Docker
  • Caddy
  • Terraform
  • AWS EC2
  • Amazon S3
  • Amazon SES
  • SSM
  • CloudWatch
  • Claude API
  • Google sign-in
  • GitHub Actions

Project overview

Residents list things they own, neighbours request them for specific dates, owners approve, and both sides record pickup, return and a review. The app covers discovery and search on a map, listings with photos, loans with a calendar and checklist, messages, notifications, trust and safety features, moderation and an admin portal, in English and Norwegian.

Listing help comes from the Claude API, and people can sign in with a password or with Google. The whole system is defined as code, from the Flask modules to the Terraform for AWS.

Requirements

  • An item can never be booked twice for the same days, even if two requests arrive at once.
  • Every step of a loan notifies the other person, in the app and by email, without slowing the request down or sending anything twice.
  • Trust comes from a verified email, and sensitive changes need a recent sign-in.
  • Run safely in production for a small pilot on a very small budget, with backups and no SSH.

Architecture

One server runs the whole app in Docker; AWS services handle storage, email, settings and alarms.

The backend has 16 domain modules: identity, profiles, trust, safety, neighbourhoods, listings, media, discovery, search, ai, loans, messaging, notifications, moderation, admin and ops. Each owns its models, service and routes, and modules react to each other through events rather than reaching into each other's tables, so any of them could be split out later.

Loan lifecycle

What happens when someone asks to borrow
  1. 01Borrower→Flask APIPOST /api/v1/loans with session cookie and CSRF token
  2. 02loans module→PostgreSQLCheck rules; save the loan and a loan.requested event in one transaction
  3. 03Flask API→BorrowerAnswer right away; nothing slow runs inside the request
  4. 04worker→outbox_eventsPick up the event; idempotent handlers retry up to 10 times
  5. 05worker→Amazon SESIn-app notification plus an email to the lender
  6. 06Lender→Flask APIApprove: the same pattern repeats through pickup, return and reviews
Loan states and the events they emit
StateEventWho acts
Requestedloan.requestedBorrower
Approved / declinedloan.approved, loan.declinedLender
Picked uploan.picked_upBoth
Handed backloan.handed_backBorrower
Returnedloan.returnedLender confirms condition
Reviewedreview.submittedBoth

Engineering decisions

Transactional outbox
The loan and its event are written in the same database transaction, so a notification can never be lost or sent for a loan that was rolled back. A worker delivers events at least once, and idempotent handlers make retries safe.
Let PostgreSQL prevent double bookings
An exclusion constraint refuses overlapping approved dates for the same item. The rule holds even under concurrent requests, and CI runs the tests against real PostgreSQL to exercise it.
Modular monolith
One codebase and one database keep a small project easy to run, while module boundaries and events keep it ready to split.
Adapters for every outside service
Email (SES, SMTP or log), storage (S3 or local), AI (Claude or none) and identity verification are swappable by configuration, so the app runs fully offline in development.
One server now, a managed setup ready
The low-cost Terraform setup runs everything on one EC2 instance. A second Terraform setup with a load balancer, Fargate, RDS and WAF is ready for when traffic justifies about $100–135 a month.

Security

  • Only ports 80 and 443 are open, with no SSH; admin access goes through SSM Session Manager, and IMDSv2 is required.
  • HTTPS everywhere with HSTS, and a strict Content-Security-Policy from nginx.
  • Secure, HTTP-only session cookies with CSRF tokens, idempotency keys on writes, and a recent sign-in required for sensitive changes.
  • Google sign-in uses OpenID Connect with PKCE.
  • Photos are private in S3 and load through 5-minute signed links.
  • The app refuses to start in production with unsafe settings, such as mock providers, fake email or non-secure cookies.

Cloud, cost & reliability

per month
~$6
on the AWS free trial; about $16–18 from 2027
database dumps
Nightly
14 days on the server, 30 days in S3
disk snapshots
Daily
kept 3 days
open SSH ports
0
SSM Session Manager only

From the project's system design document and Terraform.

  • CloudWatch alarms recover the server onto healthy hardware automatically, and a budget alert emails when usage grows.
  • Settings and secrets live in SSM Parameter Store and reach the server only at deploy time.
  • CI runs ruff and the backend tests on both SQLite and PostgreSQL, and builds the frontend.

Trade-offs

  • One server in one zone: if it fails, the site is down until it recovers.
  • No web application firewall yet; the app's own rate limits stay on.
  • The database shares the server instead of running on RDS.

What I learned

  • Putting critical rules in the database (the exclusion constraint) is more reliable than checking them in application code.
  • The outbox pattern makes background work dependable without adding a message broker.
  • Writing down the cost and the trade-offs of the cheap setup made it easy to see what to upgrade first.

Source