Stage 4 · Dev

PhoneBazaar: Dev Notes

PhoneBazaar · Android phones store · generated by the AiNa pipeline

Stage 4 of the AiNa pipeline · 2026-11-30 · input: 03 PRD

Summary

The storefront and back office are built, tested (14 passing end-to-end tests) and deployed at https://phonebazaar.tehchand.com. It extends the AiNa FastAPI + HTMX golden starter: the starter's design system and admin shell are kept, and the store-specific layout and styles were added on top.

Architecture

phonebazaar/                 ← repo root (github.com/shafialtn/phonebazaar, private)
├── index.py                 ← Vercel entrypoint: imports app.main:app
├── requirements.txt         ← copy of app/requirements.txt for Vercel
├── docs/                    ← pipeline documents (.md) + docs/html/ (self-contained HTML)
├── tools/
│   ├── md2html.py           ← converts docs/*.md → docs/html/*.html
│   └── publish.sh           ← regenerate HTML, commit, push, deploy, smoke-test
└── app/
    ├── app/
    │   ├── main.py          ← FastAPI app, session middleware, nav, /docs, /roadmap, /healthz, /api/phones
    │   ├── store.py         ← storefront + cart + checkout router
    │   ├── admin.py         ← admin router (login, phones, orders)
    │   ├── db.py            ← SQLite schema, seed-on-first-use, query helpers
    │   └── catalog.py       ← 24 seed phones across 9 brands
    ├── templates/
    │   ├── base.html        ← starter sidebar shell (admin)
    │   ├── store_base.html  ← shopper top-bar layout
    │   ├── pages/           ← home, phones, phone, compare, cart, checkout, order,
    │   │                      admin_login, dashboard, admin_phones, admin_phone_form,
    │   │                      admin_orders, docs, roadmap
    │   └── partials/        ← device (SVG macro), phone_card, results, compare_btn, admin_phone_row
    ├── static/css/app.css   ← starter design system (unchanged apart from docs styles)
    ├── static/css/store.css ← storefront layer: Android-green accent, cards, catalog, compare, checkout
    └── tests/test_app.py    ← pytest suite mapped to PRD acceptance criteria

Request flow. Vercel routes every request to index.py, which imports the FastAPI app. Pages are server-rendered with Jinja2. HTMX handles filters (swapping #results and pushing the URL), add-to-cart and compare toggles (out-of-band swaps of the header counters plus an X-Toast header), and admin row actions. Every form also works without JavaScript: non-HTMX posts get a 303 redirect.

State. - Catalog, orders: SQLite. On Vercel the file is /tmp/phonebazaar.db, created and seeded on the first request to each instance. Locally it is app/data/phonebazaar.db. DB_PATH overrides both. - Cart, compare tray, admin flag, the browser's own order numbers: a signed session cookie (pb_session, Starlette SessionMiddleware, HttpOnly, SameSite=Lax, Secure on Vercel, 7-day expiry). - Money: integer pence everywhere, formatted with the gbp Jinja filter.

Feature → code map

PRD feature Routes Template(s) Tests
Home GET / pages/home.html test_health_and_home
Catalog + filters GET /phones (+ HTMX partial) pages/phones.html, partials/results.html test_brand_filter, test_price_ram_storage_5g_filters, test_search_and_htmx_partial, test_empty_state
Detail GET /phones/{slug} pages/phone.html test_detail_and_404
Compare GET /compare, POST /compare/{id}, POST /compare/clear pages/compare.html, partials/compare_btn.html test_compare_max_three_and_highlight
Cart GET /cart, POST /cart/add|update|remove pages/cart.html test_cart_add_increment_cap_and_total, test_out_of_stock_cannot_be_added
Demo checkout GET/POST /checkout, GET /orders/{number} pages/checkout.html, pages/order.html test_checkout_validation_and_order
Admin login GET/POST /admin/login, POST /admin/logout pages/admin_login.html test_admin_requires_login
Admin phones /admin/phones* admin_phones.html, admin_phone_form.html, partials/admin_phone_row.html test_admin_phone_crud_and_visibility
Admin orders + dashboard /admin, /admin/orders, POST /admin/orders/{id}/ship dashboard.html, admin_orders.html test_admin_orders_and_ship
Docs / roadmap /docs, /docs/{slug}, /docs/{slug}.html, /roadmap pages/docs.html, pages/roadmap.html test_docs_served

How to run

cd app
pip install -r requirements.txt pytest httpx
set ADMIN_PASSWORD=choose-one         # PowerShell: $env:ADMIN_PASSWORD="choose-one"
python -m uvicorn app.main:app --reload --port 8000
python -m pytest -q                    # 14 tests

Open http://localhost:8000. Admin is at /admin; without ADMIN_PASSWORD the login page says admin is not configured.

Deploy: from the repo root run bash tools/publish.sh "<message>" <doc-slug>. It regenerates the HTML docs, commits, pushes to GitHub, runs vercel --prod, and checks /healthz and the doc page on the live domain.

Configuration (names only)

Variable Where Purpose
ADMIN_PASSWORD Vercel (production) Admin login. The operator's copy is PHONEBAZAAR_ADMIN_PASSWORD in the private keys file.
SESSION_SECRET Vercel (production) Signs the session cookie. If it is missing, a random per-process key is used, so carts would not survive across serverless instances.
DB_PATH optional Overrides the SQLite location
APP_NAME, APP_TAGLINE optional Branding

QA review (verified)

What's stubbed or limited (honest list)

Roadmap (also at /roadmap)

  1. ✅ Catalog, filters, detail, compare, cart, demo checkout, admin
  2. ⏳ Persistent orders on managed Postgres
  3. ○ Stripe Checkout (test mode, then live)
  4. ○ Customer accounts and order emails
  5. ○ Refurbished phones and trade-ins