# Habify Base — Complete LLM, AI Agent & Developer Reference (OpenAPI 3.2.0) Canonical Site: https://dev.habifybase.com Agent Skill Markdown: https://dev.habifybase.com/skill.md (alias https://dev.habifybase.com/skills/habify-base/SKILL.md) Tenant Endpoints: https://{projectSlug}.habifybase.app --- ## 0. Zero-Config Skill & Zero-DevOps Vibe-Coding Quickstart Install our Skill Markdown directly into your AI coding agent before generating backend wiring: - Claude Code: `mkdir -p .claude/skills/habify-base && curl -fsSL https://dev.habifybase.com/skill.md -o .claude/skills/habify-base/SKILL.md` - OpenAI Codex CLI: `mkdir -p .codex/skills/habify-base && curl -fsSL https://dev.habifybase.com/skill.md -o .codex/skills/habify-base/SKILL.md` - Antigravity / Shared Agents: `mkdir -p .agents/skills/habify-base && curl -fsSL https://dev.habifybase.com/skill.md -o .agents/skills/habify-base/SKILL.md` Host your frontend UI on **Vercel, Cloudflare Pages, or Netlify** (free or low-cost tiers) with **zero backend DevOps**, connecting directly to `https://{projectSlug}.habifybase.app`. --- ## 1. Architecture & Product Boundaries - **Physical DB per Project:** `hb_proj_` on PostgreSQL 18 via PgBouncer, split into `public` (developer tables and `WITH (security_invoker = true)` views) and `habify_sys` (Billing Kit, isolated Mode C auth tables, audit logs, webhook deliveries). - **5-Layer PostgreSQL Fair-Use Isolation:** PgBouncer per-project connection pools, per-role PostgreSQL limits (`connection_limit`, `work_mem`, `statement_timeout`, `max_parallel_workers`), structural `max_tables` caps, API RPM/concurrency/payload guards, and 5-minute disk size monitoring triggering HTTP `507 DB_QUOTA_READ_ONLY` (while preserving SQL Editor `DELETE/TRUNCATE/DROP` cleanup and automatic unlock). - **Zero Frontend Hosting / No Edge Functions / No Table-Change DB CDC / No Embedded REST Joins:** Host frontends on Vercel, Cloudflare Pages, Netlify, or your own VPS. Use `/v1/chat/me/*` and `/v1/notification/me/*` over Reverb WebSockets for live chat & user notifications, and `WITH (security_invoker = true)` SQL Views for safe read-only joins. - **3 Isolated Authentication Modes:** 1. Mode A: Shared Habify Account (OIDC + PKCE S256 via `https://auth.habifyhub.com`). 2. Mode B: BYO Auth JWT via SSRF-guarded `jwks_url` (cached 10 minutes; `RS256`, `ES256`, Vault-backed `HS256`). 3. Mode C: Isolated Project Local Auth (`local_auth`) storing `auth_users`, `auth_otp_challenges`, and `auth_refresh_tokens` strictly inside each project's own `habify_sys` schema (scrubbed on Clone-to-Sandbox). Endpoints: `GET /v1/auth/config`, `POST /v1/auth/signup`, `POST /v1/auth/login`, `POST /v1/auth/otp/send`, `POST /v1/auth/otp/verify`, `POST /v1/auth/refresh`, `POST /v1/auth/logout`, `GET|PATCH /v1/auth/me`, `POST /v1/auth/password/change`, `GET /v1/auth/.well-known/jwks.json`. ## 2. Key Separation & Default-Deny RLS - `hb_pk_*` (Publishable Key): Browser-safe (`/v1/*` CORS enabled). Requests without an end-user JWT STILL execute inside `SET LOCAL ROLE hb_rls_` with `app.current_role = 'anon'` and `app.current_user_id = NULL`. - `hb_sk_*` (Secret Key): Server-only. Gateway rejects browser `Origin` requests with `403 SECRET_KEY_BROWSER_FORBIDDEN`. - `hb_at_*` (Scoped AI Agent Token): CLI & MCP token (`habify login`, stored chmod `0600` in `~/.habify/credentials.json`) scoped by `User RBAC ∩ Token Scopes \ Hard Denylist` (no billing, wallets, members, destructive drops, prod key rotation, or browser `Origin` access). - Send API key via `X-Habify-Key: `. End-user JWT goes in `Authorization: Bearer `. - Public tables require `ENABLE ROW LEVEL SECURITY`, `FORCE ROW LEVEL SECURITY`, and at least one policy; otherwise Data API returns `403 RLS_POLICY_REQUIRED`. - Read-only public SQL Views require `WITH (security_invoker = true)` and are checked recursively against underlying public tables (`403 VIEW_SECURITY_INVOKER_REQUIRED`, mutations `405 VIEW_READ_ONLY`). ## 3. Data API (/v1/db/tables/{table}), Migrations & Google Sheets CSV Import - Supports `GET`, `POST`, `PATCH`, `DELETE` on schema `public` only (plus read-only `GET` on compliant SQL Views). - Filter operators: `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `like`, `ilike`, `in`, `is`, plus logical `$or` / `$and` (up to 2 levels via `habify.db.from(...).or([...]).and([...])`). - Exact RLS-scoped total counts: `?count=exact` or `.select('*', { count: 'exact' })` returns `meta.total_count`. - Atomic UPSERT: `POST /v1/db/tables/{table}?on_conflict=col1,col2` (`&ignore_duplicates=true`) or `.upsert(rows, { onConflict: 'col1,col2' })`. - Push SQL migrations idempotently via `habify db push --project ` or `POST https://dev.habifybase.com/api/v1/projects/{project}/db/push` using `Authorization: Bearer ` or `X-Habify-Key: `. - Migrate Google Sheets CSV into PG18 + FORCE RLS + BA Spreadsheet Data Grid (`?tab=tables&view=data`): `POST https://dev.habifybase.com/api/v1/projects/{project}/db/import-csv` (presets: `owner_only`, `public_read_owner_write`, `public_insert_admin_read`, `authenticated_read_write`). ## 4. Project Billing Kit (/v1/billing/*) - Built into tenant `habify_sys` schema from **Starter** tier upward: - `GET|POST /v1/billing/plans` (includes `tax_rate`: `0|5|8|10|kct|none` and `invoice_type`: `vat|sales_receipt`) - `GET /v1/billing/wallet`, `POST /v1/billing/topups` - `GET|POST /v1/billing/subscriptions`, `POST /v1/billing/subscriptions/{id}/cancel` - Immutable append-only ledger enforced via PostgreSQL trigger, `lockForUpdate()`, and `idempotency_key`. - 0% revenue cut by Habify; payments settle directly into customer BYO merchant profiles. ## 5. Unified Gateway (11 Core Services + Realtime Chat/Notification + ERP Bridge) Every gateway path injects `owner_ref = project_id` and `strict_owner_only = true`: - `/v1/payment/*` (BYO SePay QR/Card; BYO PayPal for non-VN buyers per https://dev.habifybase.com/en/docs/guides/byo-paypal-international). One-off BYO checkouts relay upstream callbacks through `/api/webhooks/payment-byo/{project}` signed with your `HABIFY_WEBHOOK_SECRET`. - `/v1/invoice/*` (7 VN e-invoice suppliers + Decree 70/2025 POS series `M` + USD `exchange_rate` support) - `/v1/storage/*` (Managed R2 or BYO S3, prefix `proj_/`, Hard Quota `413`, Live Migration; unauthenticated uploads go via Turnstile-guarded server route using `hb_sk_*`) - `/v1/zalo/*` (OAuth v4 + PKCE OA, ZBS templates) - `/v1/sms/*` (8 BYO carriers: eSMS, SpeedSMS, VietGuys, FPT, VHT, Twilio, Vonage, Generic VN) - `/v1/email/*` (Sandbox `mail.habifybase.app` 50/day or Production BYO SES/SMTP with `layout: "standard"`) - `/v1/ai/*` (BYO AI key = zero markup, or Wallet pass-through) - `/v1/places/*`, `/v1/link/*`, `/v1/erp/events` - `/v1/chat/me/*` & `/v1/notification/me/*`: Browser-safe end-user conversations, messages, typing, reactions, inbox & Reverb WebSocket auth (isolated as `hb::`; guest live chat routes via server `hb_sk_*` + `X-Participant-Ref`). ## 6. Workspace-Pooled Pricing v4 (Excl. VAT) - **Free ($0):** Sandbox (auto-pause 7d idle), 1 Project, 1 Seat, 5k MAU, 500 MB PG18, 1 GB R2, 5 GB Egress, 100k req/mo (60 RPM), manual `.hpb` export (0d auto-backup), 24h logs, PG `3` conn / `30` tables. - **Starter (199,000 VND / $9):** 24/7 Production, Billing Kit + 1 Custom Domain SSL, 1 Project, 1 Seat, 25k Workspace MAU, 2 GB PG18, 10 GB R2, 50 GB Egress, 500k req/mo (200 RPM), daily **3-day** auto-backup, **3-day** log retention, PG `8` conn / `100` tables. - **Pro (490,000 VND / $21 — Popular):** 1 Project (+149k VND / $6 per extra project), 3 Seats (+99k VND / $4 per extra seat), 100k Workspace MAU (+50k/10k), 8 GB PG18 (+15k/GB), 50 GB R2 (+2k/GB), 250 GB Egress (+2k/GB), 3M req/mo (+30k/1M, 600 RPM), unlimited Custom Domains SSL, daily **7-day** auto-backup (+14d/30d add-on available), **7-day** log retention, 99.5% SLA, Compute S/M/L/XL add-ons. - **Team (3,990,000 VND / $169):** 5 Projects (+149k/proj), 15 Seats (+99k/seat), 250k Workspace MAU, 20 GB PG18, 150 GB R2, 1 TB Egress, 15M req/mo (2,000 RPM, 2 parallel query workers), daily **14-day** auto-backup, **28-day** log & audit retention, Compliance-in-a-Box BCT/A05, Project-scoped & Read-Only RBAC, Clone-to-Sandbox PII masking, Live Storage Migration, White-Label Console, Priority Support & **99.9% SLA**. - **Enterprise (Custom, from 15,000,000 VND+ / $599+):** Dedicated PG18 cluster + VN Physical Replica, custom quotas, SSO Dashboard, 99.95% SLA & custom DPA. ## 7. Dual-Secret HMAC Webhook Verification Verify `X-Habify-Signature: t=,v1=[,v1_prev=]` over `"{ts}.{rawBody}"` with 300s replay window and timing-safe comparison. ## 8. Official CLI (`habify`) & MCP Server (@habifybase/mcp — 18 Tools) Install Zero-Dependency CLI & authenticate via browser Device Flow (`POST https://dev.habifybase.com/api/v1/agent-auth/device/start`): ```bash curl -fsSL https://dev.habifybase.com/install.sh | bash habify login habify env init --project ``` MCP config (`npx -y @habifybase/mcp`, automatically reads `~/.habify/credentials.json`): Local tools (5): `habify_project_inspect`, `habify_scaffold_integration`, `habify_test_connection`, `habify_generate_bct_pages`, `habify_verify_production_readiness`. Live Control Plane tools (13): `habify_whoami`, `habify_list_projects`, `habify_create_project`, `habify_list_tables`, `habify_describe_table`, `habify_create_table`, `habify_push_migrations`, `habify_execute_sql`, `habify_apply_rls_policy`, `habify_query_rows`, `habify_mutate_rows`, `habify_import_csv`, `habify_get_logs`. ## 9. Portable Backups (.hpb) & Self-Hosted Modular Bundle - Storage portability modes: `metadata_only`, `inline_files` (`.tar.zst`), `signed_pull_manifest`. - Self-Hosted Docker images pinned by SHA256 digest (zero `:latest`), managed via `habify-base.sh`. ## 10. Real-World Use-Case Blueprints & Architecture Guides - Why Every BaaS Project Needs a Dedicated Physical PostgreSQL Database: https://dev.habifybase.com/en/blog/why-each-baas-project-needs-a-dedicated-postgresql-database (VI: https://dev.habifybase.com/vi/blog/tai-sao-moi-du-an-baas-can-database-postgresql-vat-ly-rieng) Summary: How physical per-project PostgreSQL 18 databases prevent cross-tenant leaks, simplify Law 91/2025 compliance, and unlock lossless .hpb portability. - Designing Automated Subscription Wallets Without Custodial Risk: https://dev.habifybase.com/en/blog/designing-project-billing-kit-without-custodial-money-risk (VI: https://dev.habifybase.com/vi/blog/thiet-ke-project-billing-kit-tu-dong-gia-han-khong-giu-tien-nd-52) Summary: Inside Habify Base's Project Billing Kit: strict BYO merchant isolation, append-only PostgreSQL wallet ledgers, and flexible VAT or sales receipt profiles. - Why Habify Base Never Hosts Frontends and How 3-Mode Isolated Auth Works: https://dev.habifybase.com/en/blog/why-habify-base-does-not-host-frontends-or-separate-user-pools (VI: https://dev.habifybase.com/vi/blog/tai-sao-habify-base-khong-host-frontend-va-khong-tu-lam-user-pool) Summary: Why Habify Base focuses strictly on isolated PostgreSQL, Unified Gateway, and 3-mode per-project authentication instead of hosting UIs or mixing customer passwords on a shared control plane. - Safe Vibe-Coding to Production Workflow Using @habifybase/mcp & /skill.md: https://dev.habifybase.com/en/blog/safe-vibe-coding-to-production-workflow-with-mcp (VI: https://dev.habifybase.com/vi/blog/quy-trinh-vibe-coding-len-production-an-toan-voi-mcp) Summary: Five automated safety gates when shipping AI-generated apps: loading SKILL.md, preventing hb_sk_* exposure, enforcing RLS policies, verifying HMAC webhooks, and generating BCT legal pages. - Self-Hosted VPS Backend vs Managed BaaS: Real Total Cost in 2026: https://dev.habifybase.com/en/blog/diy-vps-backend-vs-baas-habify-base-real-cost-guide (VI: https://dev.habifybase.com/vi/blog/tu-build-backend-vps-hay-dung-baas-habify-base) Summary: Cheap $5–$7 VPS instances look tempting on paper, until you factor in DevOps hours, PostgreSQL tuning, backups, Auth OTP, webhook security, and e-invoicing. Here is an honest cost breakdown. - Vibe Coding to Production with Zero DevOps: Vercel Free + Habify Base: https://dev.habifybase.com/en/blog/vibe-coding-to-production-zero-devops-vercel-habify-base (VI: https://dev.habifybase.com/vi/blog/vibe-coding-deploy-production-khong-can-devops-vercel-habify-base) Summary: AI tools generate slick UIs in 10 minutes, yet 90% of vibe-coded apps stall before production due to databases, auth, backups, and billing. Learn the 2-piece Zero-DevOps stack. - Zero-Config Habify Base Integration with Agent Skill for Claude Code, Codex & Antigravity: https://dev.habifybase.com/en/blog/zero-config-habify-base-integration-ai-agent-skill-llms-txt (VI: https://dev.habifybase.com/vi/blog/tich-hop-habify-base-tu-dong-bang-ai-agent-skill-claude-code-codex-antigravity) Summary: Skip manual boilerplate: drop /skill.md or /llms.txt into Claude Code, OpenAI Codex CLI, or Antigravity so your agent automatically writes FORCE RLS schemas, wires @habifybase/sdk, and validates build security. - Safely Let AI Agents Create Projects, PG18 Tables & APIs via `habify` CLI and Scoped Tokens: https://dev.habifybase.com/en/blog/scoped-ai-agent-tokens-and-cli-autonomous-backend-provisioning (VI: https://dev.habifybase.com/vi/blog/cap-quyen-ai-agent-tu-tao-database-api-an-toan-voi-habify-cli) Summary: Want Claude Code, Codex CLI, or Antigravity to provision PG18 tables, enforce RLS, import Sheets CSVs, and write dev .env keys without handing over Owner credentials? Learn how Device Login + hb_at_* tokens work. ### Use-Case Blueprints - Building a Complete E-Commerce Storefront with OTP Login, Direct QR Pay & Automated Invoicing: https://dev.habifybase.com/en/blog/build-ecommerce-storefront-with-postgresql-rls-otp-and-qr-checkout (VI: https://dev.habifybase.com/vi/blog/xay-dung-website-ban-hang-voi-postgresql-rls-sepay-qr-va-otp) Summary: Run a full storefront backend: filterable product catalogs, deduplicated shopping carts, frictionless phone OTP sign-in, direct bank QR checkout, and automated tax e-invoices. - Building a Customer Support Portal, Ticket Desk, and Realtime Live Chat on Habify Base: https://dev.habifybase.com/en/blog/build-customer-support-portal-and-live-chat-with-baas (VI: https://dev.habifybase.com/vi/blog/xay-dung-cong-ho-tro-khach-hang-va-live-chat-truc-tuyen) Summary: Launch a Help Center, private ticket tracking desk, and realtime live chat widget backed by managed WebSockets without maintaining separate socket clusters. - Building a Clinic Website & Appointment Booking Backend with Phone OTP & Zalo Reminders: https://dev.habifybase.com/en/blog/build-clinic-appointment-booking-backend-with-otp-and-rls (VI: https://dev.habifybase.com/vi/blog/xay-dung-website-phong-kham-dat-lich-kham-benh-zalo-sms-otp) Summary: Build a clinic website and appointment backend on Habify Base: database-level slot collision locks, patient verification via your BYO SMS/Zalo OTP account with 5 anti-abuse layers, and physical database privacy. - Building a Company Career Portal & Secure Online CV Upload Flow on Habify Base: https://dev.habifybase.com/en/blog/build-recruitment-career-portal-and-secure-cv-upload-baas (VI: https://dev.habifybase.com/vi/blog/tao-trang-tuyen-dung-va-nop-cv-truc-tuyen-an-toan-r2-private) Summary: Launch a leak-proof company careers portal on Habify Base: filter open roles publicly, accept PDF/DOCX CVs through a bot-protected server handler into private storage, restrict reads to HR, and automate privacy erasure. - Building SaaS and AI Products with Prepaid Wallets, Auto-Renewal, and Tax Invoicing: https://dev.habifybase.com/en/blog/build-saas-and-ai-app-with-subscription-wallets-and-invoicing (VI: https://dev.habifybase.com/vi/blog/xay-dung-ung-dung-saas-va-cong-cu-ai-thu-phi-theo-goi) Summary: Ship monetized SaaS and AI tools fast using Project Billing Kit (prepaid end-user wallets, auto-renew subscriptions, and zero revenue cut), unified AI Gateway routing with BYO keys, and automated e-invoicing. - Building an Online Course Platform (LMS) and Paid Learning Community on Habify Base: https://dev.habifybase.com/en/blog/build-online-course-lms-and-paid-community-backend (VI: https://dev.habifybase.com/vi/blog/xay-dung-nen-tang-hoc-truc-tuyen-ban-khoa-hoc-va-cong-dong) Summary: Build a leak-resistant online course backend: unlock curriculum automatically upon direct QR payment, protect videos and PDFs behind private signed links, track student completion, and host class discussions. - Building a Multi-Branch Spa, Salon & On-Demand Local Service Booking Backend: https://dev.habifybase.com/en/blog/build-spa-salon-and-local-service-booking-backend (VI: https://dev.habifybase.com/vi/blog/xay-dung-he-thong-dat-lich-spa-salon-va-dich-vu-tai-nha) Summary: Power spas, studios, and on-demand home service teams: conflict-free staff scheduling, address autocomplete via Places Service, automated Zalo ZBS / SMS appointment reminders, and tracked promo links. - Building a Real Estate Listing Portal with Places Search, Verified Brokers, and Context Chat: https://dev.habifybase.com/en/blog/build-real-estate-listing-portal-with-maps-and-broker-chat (VI: https://dev.habifybase.com/vi/blog/xay-dung-san-dang-tin-bat-dong-san-ban-do-va-chat-moi-gioi) Summary: Combine Data API multi-filter queries, Places address lookup, phone-verified sellers, context-card live chat between buyers and agents, and prepaid VIP listing credits on one isolated backend. - Replace Google Apps Script & Google Sheets for Vibe-Coded Prototypes Without Rewriting Backend Routes: https://dev.habifybase.com/en/blog/replace-google-apps-script-google-sheets-for-prototype-mvp (VI: https://dev.habifybase.com/vi/blog/thay-the-google-apps-script-google-sheets-cho-prototype-mvp) Summary: Apps Script + Google Sheets feels fast on day one, then stalls demos with cold starts and forces backend engineers to maintain dual Sheets + SQL routes during handoff. Here is the clean fix. ## 11. Vietnam Go-Live Playbook Guides - Integrate SePay QR/Cards & 7 Vietnam E-Invoice / POS Suppliers (Decree 70): https://dev.habifybase.com/en/guides/sepay-qr-va-xuat-hoa-don-dien-tu-nd-70 (VI: https://dev.habifybase.com/vi/guides/sepay-qr-va-xuat-hoa-don-dien-tu-nd-70) - Vietnam Ministry of Industry & Trade (online.gov.vn) Go-Live Playbook: https://dev.habifybase.com/en/guides/thong-bao-website-bo-cong-thuong-online-gov-vn (VI: https://dev.habifybase.com/vi/guides/thong-bao-website-bo-cong-thuong-online-gov-vn) - Complying with Vietnam Personal Data Protection Law 91/2025/QH15 & Decree 356: https://dev.habifybase.com/en/guides/tuan-thu-luat-bao-ve-du-lieu-ca-nhan-91-2025-qh15 (VI: https://dev.habifybase.com/vi/guides/tuan-thu-luat-bao-ve-du-lieu-ca-nhan-91-2025-qh15) - Build End-User Prepaid Wallets & Auto-Renew Subscriptions with Billing Kit: https://dev.habifybase.com/en/guides/project-billing-kit-vi-va-auto-renew-vnd (VI: https://dev.habifybase.com/vi/guides/project-billing-kit-vi-va-auto-renew-vnd) - Connect Zalo OA/ZBS & 8 BYO SMS Providers via Unified Gateway: https://dev.habifybase.com/en/guides/ket-noi-zalo-oa-zbs-va-8-nha-cung-cap-sms (VI: https://dev.habifybase.com/vi/guides/ket-noi-zalo-oa-zbs-va-8-nha-cung-cap-sms) - Vibe-Coding from Cursor / Claude Code to Production Safely with @habifybase/mcp: https://dev.habifybase.com/en/guides/vibe-coding-to-production-voi-habify-mcp (VI: https://dev.habifybase.com/vi/guides/vibe-coding-to-production-voi-habify-mcp)