Architecting a 31 kB RTL-First Co-Living & Budgeting PWA on $0/Month: From Problem to Agent-Ready Ops

2026-12-03来源 dev.toEnglish

Live Demo: https://safy-platform-eg.web.app (Guest Mode available: explore without creating an account)

ملخص تنفيذي بالعربية

صافي (Safy) هو تطبيق ويب تقدمي (PWA) ثنائي اللغة ومُصمَّم بالأساس للغة العربية والاتجاه من اليمين إلى اليسار (RTL-First)، يهدف إلى تنظيم الميزانية الشخصية والمصروفات المشتركة في السكن التشاركي داخل مصر. يعمل التطبيق في بيئة تجمع بين النقد وInstaPay دون طلب بيانات بنكية أو تقديم استشارات استثمارية، مع لوحة عمليات للمُؤجِّر (/landlord) وبنية تشغيلية جاهزة لوكلاء الذكاء الاصطناعي بتكلفة إطلاق 0 دولار شهرياً وحجم حزمة دخول يبلغ 31.55 kB فقط (gzip).

1. Why We Built Safy

In Egypt's day-to-day economy, young professionals and students live in a hybrid cash + InstaPay reality. Bank-scraping aggregators fail here for two reasons: most shared flat expenses happen in cash or P2P transfers, and users rightly hesitate to hand over banking credentials.

Safy draws a strict boundary around personal budgeting and shared-flat expense organization:

  • Personal Safe-to-Spend vs. Shared-Flat Float: Keep your true personal disposable balance isolated from pooled rent, utilities, and groceries ("who owes whom" across roommates).
  • Sakan Ops: Structured flatmate settlements, recurring bill splits, and transparent balances without spreadsheets.
  • /landlord Workspace: A dedicated, lazy-loaded workspace for small landlords managing rooms, leases, and maintenance logs.
  • Clear Product & Regulatory Scope: Strictly personal budgeting and shared-flat expense organization (no bank login and no investment advice).

2. Five CI-Enforced Non-Functional Requirements

Rather than treating performance, RTL quality, and portability as guidelines, we encoded five Non-Functional Requirements (NFRs) directly into CI gates:

  1. Entry JS Budget (< 50 kB gzip): Currently 31.55 kB gzip for the entry bundle. Every kilobyte matters on mid-range Android devices over congested 4G connections.
  2. Zero-Tolerance RTL Hygiene (lint:rtl): 0 violations enforced in CI. Physical CSS directional properties (ml-*, mr-*, text-left, right-0) fail the build; logical properties (ms-*, me-*, text-start, inset-inline-end) are mandatory.
  3. Exact Monetary Math & FRA Guardrails: All money is stored and computed in integer piasters (100 piasters = 1 EGP), never IEEE-754 floats, alongside strict copy and feature guardrails compliant with Egypt's Financial Regulatory Authority (FRA) boundaries (no investment advice, no credit underwriting, no bank credential ingestion).
  4. $0/month Launch + Vendor Portability (check:portability): Built to run on free tiers at launch ($0/mo) while guaranteeing zero lock-in. Our check:portability static gate scans 114 files with 0 violations to prevent cloud-specific SDK leakage into domain logic.
  5. Solo-Founder Operability (manual_only AI Ops): Operations cannot require 24/7 babysitting or runaway LLM bills. AI-assisted ops run in manual_only mode (0 background tokens burned passively), keeping the founder in the loop.

3. Implementation Highlights

Zero-Dependency Sentry Poster (ErrorBoundary.tsx, lines 36–83)

Importing the official @sentry/react SDK blows up a sub-50 kB entry budget. Instead, ErrorBoundary.tsx (lines 36–83) implements a minimal, zero-dependency fetch poster directly to Sentry's /store/ endpoint with DSN parsing, stack formatting, and environment tagging in under 50 lines of TypeScript. That preserves production error visibility at effectively 0 kB overhead.

core.* vs. Private ops.* RLS Across 24 Postgres Migrations

Across 24 Postgres migrations, user-facing domain tables live in core.* protected by strict Row-Level Security (RLS) policies scoped to the authenticated user and flat membership, while operational telemetry, audit trails, and agent proposals are isolated inside a private ops.* schema inaccessible to standard client JWTs.

Dual-Auth admin-ops Edge API

Our admin-ops surface exposes a compact, agent-ready operational contract with dual authentication (founder JWT or scoped ops token):

  • GET /summary (< 2 KB payload): Token-efficient operational snapshot designed so an AI agent or CLI can diagnose system health in a single tiny read.
  • GET /tools: Self-describing operational capabilities manifest.
  • manual_only Execution (0 background tokens): Agents never spin autonomously in the background; actions execute only on explicit trigger.
  • always_on_notify Proposals in ops.admin_notifications: Deterministic backend triggers write structured proposals and alerts into ops.admin_notifications without invoking an LLM until the founder inspects them.

Decoupled @nawa/admin-kit & Route-Level Code Splitting

All admin UI primitives are isolated behind an AdminOpsAdapter interface inside @nawa/admin-kit. Combined with route-level lazy loading:

  • Entry JS: 31.55 kB gzip
  • Lazy /admin chunk: 8.65 kB gzip
  • Lazy /landlord chunk: 8.47 kB gzip

4. Trade-Offs Table & Verified Numbers

Dimension Decision Trade-Off Accepted Verified Metric
Error Reporting Custom /store/ poster in ErrorBoundary.tsx (L36–83) No automatic breadcrumbs/replay 31.55 kB entry JS gzip (< 50 kB budget)
Admin & Landlord UI Lazy routes + @nawa/admin-kit (AdminOpsAdapter) Slight first-navigation chunk fetch 8.65 kB (/admin), 8.47 kB (/landlord)
Arabic / RTL Support Logical CSS enforced via lint:rtl Stricter lint errors during UI iteration 0 RTL violations
Cloud Lock-In Ports/adapters enforced via check:portability Extra abstraction boilerplate 114 files scanned, 0 violations
Database Isolation core.* vs. private ops.* schemas + RLS Explicit cross-schema SQL functions 24 Postgres migrations
Workspace Health Strict monorepo TypeScript project refs Slower cold CI check vs. loose tsconfig 11/11 packages passing typecheck
AI & Infra Cost manual_only ops + always_on_notify triggers No autonomous background triage $0/mo launch cost (0 background tokens)

5. Lessons for Solo Founders & Solution Architects

  1. Enforce NFRs as CI gates on Day 1, not "before launch." A < 50 kB bundle budget or 0-violation RTL rule only stays cheap if every PR is checked automatically.
  2. Design operational APIs for agents and humans. A < 2 KB GET /summary endpoint and GET /tools contract cost almost nothing to build, yet turn maintenance into a fast, low-token workflow.
  3. Separate deterministic triggers from LLM inference. Writing proposals to ops.admin_notifications deterministically keeps background token spend at 0 while preserving real-time awareness.
  4. Build portability boundaries before you need to migrate. Scanning 114 files with check:portability ensures your $0/mo launch stack never becomes a permanent prison.

Try the live PWA (Guest Mode supported, no signup required): https://safy-platform-eg.web.app

原文:https://www.a8q9.cn/en/article/architecting-a-31-kb-rtl-first-co-living-budgeting-pwa-on-0-month-from-problem-t-2c15be.html

相关文章