Building a Zero-Fee Hyperlocal Giving Platform with FastAPI, IRS Data, and Every.org

Most charitable giving platforms optimize for national campaigns or viral fundraisers. Meanwhile, the organizations that shape your daily neighborhood—local food pantries, animal rescues, youth programs, housing shelters—often struggle to win recurring monthly donors.

If you want to split $25/month across four local 501(c)(3)s in your ZIP code, you usually have to set up four separate recurring donations on four different websites.

Here is how the architecture works—specifically, how we solved zero-custody payments and hyperlocal IRS nonprofit discovery without expensive geo APIs or massive upfront data imports.

So I built ZipDonate: a zero-fee platform that lets donors discover verified nonprofits within a radius of their ZIP code and split a single monthly giving pool across them.


1. The Hard Constraint: Never Touch Donor Money

Early on, I made one non-negotiable architectural decision: ZipDonate never collects payment details, holds funds, or disburses money.

Handling charitable funds directly introduces PCI-DSS scope, money-transmitter compliance, and tax-receipt headaches. Instead, ZipDonate delegates 100% of checkout, payment processing, and 501(c)(3) disbursement to Every.org via their Nonprofit API and Donate Links:

  1. Discovery & Pool Math: Donors search by ZIP code and radius, pick 1–5 local nonprofits, and allocate percentages summing to 100%.
  2. Guided Activation: ZipDonate generates pre-filled Every.org Donate Links (build_donate_link in src/everyorg_client.py) for each allocation with the exact monthly dollar amount and charity identifier.
  3. Webhook Reconciliation: Every.org processes the payment and fires a partner webhook to /api/webhooks/everyorg (src/routers/webhooks.py). ZipDonate verifies the Bearer token with secrets.compare_digest, deduplicates on chargeId, and records the transaction in the donor’s ledger.

The result: 0% ZipDonate platform markup, full IRS-compliant tax receipts handled by Every.org, and a much smaller security footprint.


2. Hyperlocal Discovery: Bundled ZIP Centroids + Lazy IRS Caching

A pure keyword search against an external charity API is great for national brands, but it breaks down when someone asks: “Show me verified food or animal nonprofits within 15 miles of 29201.”

To make radius search fast and self-contained (src/zip_search.py), ZipDonate combines two data sources:

Step A: Fast In-Memory ZIP Radius Filtering

We bundle a compressed US ZIP centroid dataset (data/us_zips.csv.gz) and load it once via @lru_cache(maxsize=1). Given a 5-digit ZIP and radius in miles, find_nearby_zips() does a quick latitude/longitude bounding-box pre-filter before running the Haversine formula—returning all matching ZIPs and the set of states they intersect:

lat_delta = radius_miles / 69.0
lon_scale = max(math.cos(math.radians(origin_lat)), 0.1)
lon_delta = radius_miles / (69.0 * lon_scale)

Step B: Lazy Per-State IRS EO BMF Caching

Instead of pre-loading millions of US nonprofits into Postgres on startup, ZipDonate fetches the public IRS Exempt Organizations Business Master File (https://www.irs.gov/pub/irs-soi/eo_{state}.csv) lazily per state on the first search that touches that state:

  • Per-state locking: A threading.Lock per state (_get_state_lock(state)) prevents concurrent requests from triggering duplicate IRS CSV downloads.
  • 30-day TTL: State cache freshness is tracked in IrsStateCache, and parsed organizations are stored in CachedNonprofit (SQLite for local dev, PostgreSQL in production).
  • NTEE Cause Mapping: Cause filters map directly to IRS NTEE major group prefixes—for example, food -> ("K",), animals -> ("D",), housing -> ("L",), youth -> ("O",).

This keeps the Docker image small, avoids paying for third-party geocoding APIs on every search, and ensures every listed organization is an IRS-verified 501(c)(3).


3. Keeping the Stack Boring and Maintainable

For a civic-tech side project, boring technology wins:

  • Backend: Python 3.12 + FastAPI split into modular APIRouters (auth, pools, pages, admin, webhooks), SQLAlchemy, and Alembic migrations.
  • Frontend: Server-rendered Jinja2 templates with pre-compiled Tailwind CSS (no heavy SPA build pipeline) and Leaflet.js + OpenStreetMap for the interactive charity map.
  • Security Hardening: HttpOnly JWT session cookies with server-side logout revocation, double-submit CSRF protection, slowapi rate limiting, brute-force login lockout, and structured audit logging.
  • Deployment: Portable Docker + Docker Compose setup.

Try It or Get in Touch

The repository is currently private. If you are a developer interested in civic tech, want to collaborate, or run a local 501(c)(3) and want to test how your listing looks by ZIP code, give it a spin and reach out to me at support@zipdonate.org.

Leave a Reply