My last article shared the high-level architecture of KODA (my AI coding mentor built on a POCO C55). Then Artur commented: "Can you expand the idea? It looks very interesting."
So here's the deep dive. Real schema, real policies, real scars.
🗄️ 1. THE SCHEMA (the whole backbone)
create table public.chats (
id serial primary key,
user_id uuid,
role text, -- 'user' or 'assistant'
content text,
conversation_id uuid,
created_at timestamptz default now()
);
Six tables total: profiles, conversations, chats, submissions, votes, files. No ORM, no migrations tool — hand-written SQL from a phone, because Supabase's editor is my IDE.
🔐 2. RLS IS THE LAW
The frontend is a suggestion. The database is the law:
alter table public.chats enable row level security;
create policy "users see own chats"
on public.chats for select
using (auth.uid() = user_id);
Even if someone deletes every if statement in my JavaScript, they still can't read another user's chats. When nyaomaru (Senior Dev, Japan, User #001) stress-tested this, he called it "a highly resilient architecture pattern." I printed that.
🔁 3. THE FALLBACK CHAIN (+ OFFLINE SENSEI)
const MODELS = ['llama-3.3-70b-versatile', 'openai/gpt-oss-20b',
'llama-4-scout', 'qwen3-32b'];
// model fails → next model. ALL fail → OFFLINE SENSEI MODE.
Why? Because VP_xudon taught me Groq is blocked behind the Great Firewall. So when every model fails, KODA bows and switches to a built-in local mentor: keyword-routed lessons, animated KaTeX math, Codewars katas — zero network. The dojo works in a basement, on a bus, behind a firewall.
⚔️ 4. THE Z-INDEX WAR
A hosting badge kept floating over my UI. My solution, after three failed attempts:
.modal-overlay { z-index: 2147483647; } /* the max integer. yes. */
Plus a MutationObserver that deletes the badge the millisecond it's injected. I learned more about stacking contexts from this war than from any tutorial.
📱 5. WHY ONE FILE
No build step, no node_modules, no webpack. One index.html = editable on a phone, deployable by dragging a zip, losable never. If my phone dies mid-edit, I lose one file — not a monorepo.
🔭 NEXT
Artur, this one's for you. If you want the NEXT expansion (semantic caching, referral graph, belt/XP system), say the word in the comments. I expand what you ask for. 🥋
2,358 followers. One phone. Zero fear. 🏆