Dev.to AI πŸ€– Ai πŸ‘ 2 πŸ“– 2 min read

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, a

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.

1. 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]



  1. 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

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

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.