How I Built an Open-Source Bilingual AI Social PWA with FastAPI, pgvector & QLoRA Qwen
DEV Community

How I Built an Open-Source Bilingual AI Social PWA with FastAPI, pgvector & QLoRA Qwen

Most social feeds optimize for outrage and endless scrolling. I wanted to build the opposite: a calm, bilingual (EN/ES) space where people share pure thoughts, cross ideas semantically with other thinkers like neurons, and synthesize perspectives with AI - without addictive algorithms.

That became Think it (Live App ยท MIT GitHub Repo). Rather than just shipping prompts in a wrapper, I focused on the system design, database isolation, and cloud/local AI parity behind it.

3-Layer Decoupled Architecture

[React 19 + TypeScript + Tailwind v4 PWA (Vercel)]
โ”‚ HTTPS + JWT + FormData
โ–ผ
[Async FastAPI + SQLAlchemy (Render)]
โ”œโ”€โ”€ /api/auth -> JWT, bcrypt, server-enforced is_demo blocks
โ”œโ”€โ”€ /api/thoughts -> Feeds, private Daily Think, pgvector HNSW RAG
โ”œโ”€โ”€ /api/interactions -> Sparks, Bounces, Neurons, Follows
โ””โ”€โ”€ /api/messages -> 1-on-1 DMs with privacy enforcement
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ–ผ                           โ–ผ
[Groq / QLoRA Qwen .gguf]   [Supabase PostgreSQL 16 + pgvector]

Hard-Won Production Lessons

Async SQLAlchemy + PgBouncer (statement_cache_size=0)

Deploying async FastAPI (asyncpg) behind managed PostgreSQL transaction pooling (PgBouncer) immediately breaks prepared statements unless statement_cache_size=0 is explicitly configured in the async engine connect args. Catching and enforcing that early keeps pooled serverless connections stable under load.

Dual Cloud / Local AI Parity (THINKIT_AI_PROVIDER)

During development, I fine-tuned Qwen 2.5 7B via QLoRA (Unsloth) and quantized it to q4_k_m.gguf running locally in Ollama for 5 synthesis lenses (Perspective Spark, Critical Contrast, Micro-Steps, Synthesis Quote, Open Question). For zero-GPU cloud production, a single environment switch routes the exact same lens prompts through Groq - while semantic crossing uses pgvector HNSW cosine similarity over 384d embeddings.

Server-Enforced Demo Isolation & Rate Limiting

Interactive demo accounts (is_demo) let visitors test the live app safely without polluting real users' DMs or mutating restricted account settings - all blocked server-side in FastAPI dependencies alongside sliding-window rate limiting.

Packaging Reproducible Rules in SKILL.md

To avoid losing architectural context between iterations, I documented the deployment topology, pooler constraints, test gates (pytest, tsc --noEmit, oxlint, ruff), and launch policies in .skills/thinkit-lifecycle/SKILL.md.

Try It & Inspect the Code

  • Live Web & Installable PWA: thinkit-saas.vercel.app
  • Full Source Code + 30s Demo Video: github.com/abmserrut/thinkit-saas
  • LinkedIn: Abraham Moreno

Would love feedback from fellow Python, FastAPI, and React engineers on the architecture trade-offs!

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.