AniSnap (Supabase Social App)
The 6-beat story
Section titled “The 6-beat story”- What: An anime-themed social app: users post images, follow others, like and comment, and see a feed that updates in real time.
- My role: Solo. Frontend and the Supabase setup (schema, policies, storage).
- Architecture:
React + Vite (Zustand store, React Router)│ supabase-js▼Supabase├─ Auth (email/OAuth → JWT session)├─ Postgres (profiles, posts, likes, follows, comments) + RLS├─ Realtime (postgres_changes on posts/likes)└─ Storage bucket (post images, avatars)
- Hard problem: [e.g., writing RLS policies correctly, avoiding duplicate posts when realtime and fetch both add the same item, image size/upload speed.]
- Result: [working app / deployed link / users]
- Improve: Cursor-based pagination, image compression/resizing before upload, optimistic updates, moving the feed query to a Postgres function/view.
Supabase
Section titled “Supabase”Q: What is Supabase? How is it different from Firebase?
“Supabase is an open-source backend-as-a-service built on PostgreSQL: a hosted Postgres plus Auth, auto-generated REST APIs (PostgREST), Realtime, Storage, and Edge Functions. Firebase uses Firestore, a NoSQL document DB. With Supabase I get a relational SQL database with joins, constraints, and transactions, and it’s open source, so it can be self-hosted.”
Q (🔴): If the frontend talks directly to the database, what stops a user from reading or deleting other people's data?
“Row Level Security (RLS). The anon key in the frontend is public, so security can’t rely on it. I enable RLS on every table and write policies. Supabase passes the user’s JWT, and auth.uid() gives the logged-in user’s ID inside the policy.”
alter table posts enable row level security;
create policy "anyone can read posts" on posts for select using (true);
create policy "users insert their own posts" on posts for insert with check (auth.uid() = user_id);
create policy "users delete their own posts" on posts for delete using (auth.uid() = user_id);“using filters which existing rows you can see/modify; with check validates new/updated rows. The service_role key bypasses RLS, so it must never be in the frontend.”
Q: How does Supabase Realtime work?
“Supabase Realtime listens to Postgres’s logical replication stream (the WAL) and pushes row changes to subscribed clients over WebSockets. In the client: supabase.channel('posts').on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'posts' }, payload => addPost(payload.new)).subscribe(). It respects RLS, so users only receive rows they’re allowed to see. It also has Broadcast and Presence for non-DB events like typing indicators/online status.”
Follow-up — cleanup? Unsubscribe (supabase.removeChannel(ch)) in the useEffect cleanup, or you’ll leak subscriptions and get duplicate events.
Q: How did you handle protected routes and session state?
“On app load I call supabase.auth.getSession() and subscribe to onAuthStateChange to keep the session in my Zustand store. A ProtectedRoute component redirects to /login if there’s no session. Important point: frontend route guards are just UX. The real protection is RLS on the database.”
Q: Storage — public vs private buckets? How do you upload?
“supabase.storage.from('posts').upload(\${userId}/${uuid}.jpg`, file)`. A public bucket gives a permanent public URL, which is fine for posted images. A private bucket needs signed URLs that expire, which you’d use for private content. Storage also has RLS policies, e.g. users can only upload into a folder named with their own user ID.”
Improve: compress/resize images client-side before upload, and restrict file types/size.
Zustand & React
Section titled “Zustand & React”Q: Why Zustand and not Context or Redux?
“Context re-renders every consumer whenever the value changes. That’s fine for theme/auth, but bad for frequently changing data like a feed. Zustand components subscribe with a selector, useStore(s => s.posts), and only re-render when that slice changes. Compared to Redux Toolkit, it has far less boilerplate (no providers, actions, or reducers), which suits an app of this size. For bigger apps with complex flows and devtools needs, Redux Toolkit is fine too.”
Q: Show a Zustand store.
import { create } from 'zustand';
type FeedState = { posts: Post[]; addPost: (p: Post) => void; toggleLike: (id: string) => void;};
export const useFeed = create<FeedState>((set) => ({ posts: [], addPost: (p) => set((s) => ({ posts: [p, ...s.posts] })), toggleLike: (id) => set((s) => ({ posts: s.posts.map((p) => p.id === id ? { ...p, liked: !p.liked, likes: p.likes + (p.liked ? -1 : 1) } : p ), })),}));
// component — re-renders only when posts changeconst posts = useFeed((s) => s.posts);Q: You said Zustand "improved render performance". How did you know?
Honest version: “I used React DevTools Profiler with ‘highlight updates’ and saw that with Context, liking one post re-rendered the whole feed and the profile header. With Zustand selectors and memoized post items, only the affected post re-rendered.” If you didn’t measure it, remove the claim from your resume.
Q: How did you paginate the feed?
“Offset pagination (.range(0, 19)) is simple but has problems: when new posts arrive, items shift and you see duplicates, and large offsets are slow. Cursor pagination is better: where created_at < lastSeenCreatedAt order by created_at desc limit 20, with an index on created_at.” Say which one you used, then describe the improvement.
Q: Optimistic updates — what are they? Did you use them for likes?
“Update the UI immediately as if the request succeeded, then send the request. If it fails, roll back to the previous state and show an error. It makes likes feel instant. You also have to dedupe when the realtime event for your own action arrives.”
Q: How would you model likes and follows in the DB?
profiles(id = auth.users.id, username unique, avatar_url)posts(id, user_id → profiles, image_url, caption, created_at)likes(user_id, post_id, created_at, PRIMARY KEY(user_id, post_id))follows(follower_id, following_id, PRIMARY KEY(follower_id, following_id))comments(id, post_id, user_id, body, created_at)The composite PK on likes prevents double-likes at the DB level. Like counts: either count(*) with an index, or a cached likes_count column updated by a trigger.