Nguyen Le Phong

Ăn Gì and Wishjar in the C4 Model, Including What Won't Scale Yet

C4 diagrams of two side projects I run in production: where state lives, how paid APIs are capped, and what would break first at ten times the traffic.

You open a friend's side project. It's fast, it looks good, and you start wondering what's underneath. Maybe a three-thousand-line server.js. Maybe something that would survive a day with ten times the traffic. You can't tell from the UI; you have to look at the architecture.

So here is the architecture of two side projects I run in production: Ăn Gì, which picks one place to eat near you, and Wishjar, a jar of Vietnamese wishes. Both are small and both run on a single VPS. I drew them in C4 to show where I left room for growth on purpose, and where I haven't yet.

The C4 model in two minutes, and how to read these diagrams

Simon Brown's C4 model draws a system at four zoom levels, the way you zoom a map. L1 System Context shows who uses the system and which outside systems it depends on. L2 Container opens it into the things that run and store data on their own: the web app, the database, the cache. L3 Component opens one container into its main building blocks. L4 is the code itself, so I skip it.

What I like about C4 is that each level answers one question. A product person can stop at level 1. Someone about to deploy reads level 2. Someone about to change the code reads level 3. Nobody has to squint at one giant poster.

The diagrams are dense and small on a phone. Open large shows one full screen, where you can drag, zoom and tap any box for its explanation. Boxes with a level underneath have a Look inside button.

Ăn Gì: a monolith with clear borders

Ăn Gì is a Next.js app. On the L1 diagram, look at two things: who is allowed to call outside services, and how each paid one is capped.

Ăn Gì · C4 L1: System ContextThree kinds of people use Ăn Gì; the app calls five outside services for drafting, nearby search, directions, maps and analytics.[Person]Hungry visitorPhone or desktop browser,Vietnamese or English[Person]ContributorTells the assistant abouta place they like[Person]Admin (me)Reviews every submissionbehind a login token[Software System]Ăn GìPicks one place to eat,every field traced to a source[External: Anthropic]Claude HaikuDrafts place cardswith tool use[External: place search]HERE, Google PlacesNearby search, harddaily caps per provider[External: directions]Google MapsDeep link and embedfor the last step[External: open data]Map tiles, weatherOpenFreeMap tiles,Open-Meteo forecast[External: analytics]PostHogEvents without PII,via a same-origin relayPick a dish, spinTell about a placeReview each oneDraft a cardFind nearbyOpen directionsTiles, weatherAnonymous eventsIn focusPersonExternal systemRequestOptional, build time
Three kinds of users and five outside services. The paid ones are called only by the server, each with a daily cap.

Ăn Gì depends on five outside services. The three that cost money or carry a quota (Claude, HERE, Google Places) are called only from the server, behind hard caps in code: 900 HERE calls a day and 30 Google Places calls. A traffic spike can thin out the nearby list, but it can't run up the bill. Directions go to Google Maps entirely. Routing is a different product, and people already trust Google Maps for it.

Ăn Gì · C4 L2: ContainerA PWA in the browser talks over a Cloudflare tunnel to one Next.js container, backed by Postgres and Valkey on a single VPS.Your browserVPS · Docker Compose[Person]VisitorPhone or desktop[Container: React 19]Ăn Gì PWASpin, search without accents,offline copy in IndexedDB[Edge + cloudflared]Cloudflare TunnelNo public porton the VPS[Container: Next.js 16, Node 22]angi-webPages, server actions, API,admin console, the Shield[Container]Postgres 16Places, submissions,nightly pg_dump[Container]Valkey 8.1Counters, cache,64 MB LRU[External]PostHogWeb vitals, events[External]Claude HaikuContribute chat[External]HERE, GooglePlaces around a cellUsesHTTPSSQLRESPEvents, no PIIDraft a card1.1 km cellIn focusPersonIn the systemExternal systemData storeRequestOptional, build time
Postgres holds what must survive, Valkey holds what can be lost, and the web container sits between them on one VPS with no public port.

Scaling starts at L2. Data lives in Postgres, and rate-limit counters and the nearby cache live in Valkey, so the web container keeps almost nothing of its own. That's the stateless processes rule from the Twelve-Factor App. "Almost" because the Next cache and the chat limits still live inside the container; both are in the table at the end.

The two stores also play different roles. Postgres must survive, so a nightly pg_dump keeps 14 copies. Valkey has persistence turned off on purpose: losing it resets rate limits and a 30-minute cache, nothing more. When something breaks at 2 a.m., you already know which one to save first.

The VPS has no public port. Cloudflare Tunnel dials out from the machine, so a port scan of its IP finds nothing to knock on.

Ăn Gì · C4 L3: Components in angi-webPage requests and data reads pass the Shield, then reach pages, server actions, the admin console or the contribute API, which share one data layer with a tagged cache.angi-web · Next.js 16[Component: proxy + src/lib/shield]ShieldNonce CSP with strict-dynamic, HMAC data tokens, rate limits in Valkey, verified Googlebot and Bingbot, 24-hour bans for attack probes and scripts[Component: app/actions]Server actionsData reads, answers sealedper session (AES-GCM)[Component: app/[lang]]Pages and SEOHub, dish and area pages,JSON-LD, sitemap, OG[Component: app/admin]ModerationQueue, approve, reject,quality checks[Component: app/api/chat]Contribute APIAssistant with three tools,schema-checked drafts[Component: lib/nearby]Nearby service0.01° grid, daily caps,provider fallback[Component: src/db + lib/data]Data layerDrizzle schema, migrations on start, unstable_cachetagged "places", cleaned at read time[External]HERE, Google Places900 and 30 calls a day[Container]ValkeyShared counters[Container]PostgresAbout 20 indexes[External]Claude HaikuPrompt caching onFrom the tunnelRevalidateSave draftTool useGrid cell30 min cacheSQLIn focusIn the systemExternal systemData storeRequest
Every page request and data read passes the Shield first, and every read goes through one data layer whose cache is flushed by tag when a place is approved.

Two things at L3 are worth a close look. First, every page request and data read goes through one gate called the Shield: a nonce CSP, HMAC data tokens, rate limits, DNS checks for Googlebot and Bingbot, and 24-hour bans for attack probes and scripted clients. A new page gets all of that by default. Nobody has to remember to copy a check.

Second, every read goes through one data layer with a cache tagged places. Approving a place writes it to the database and calls revalidateTag in the same action. There's no TTL to guess: the cache refreshes when the data changes.

Wishjar: static reads, one paid path

Wishjar is much smaller. The library of 1,008 wishes is static content, and the "ask AI to tweak this" button is the only thing that costs money, so the design keeps those two apart.

Wishjar · C4 L1: System ContextA sender uses Wishjar on the phone; the maintainer grows the library with Codex CLI; Claude rewrites, PostHog counts, messaging apps receive the wish.[Person]SenderNeeds one good linefor a chat, right now[Person: me]MaintainerGenerates, reviews, ships[Software System]Wishjar1,008 Vietnamese wishes,28 occasions, 11 audiences,works offline[External]Search enginesRead 29 static pages[External: build time]Codex CLIWrites new lines froma JSON schema[External: Anthropic]Claude HaikuThree rewrites per tap[External]PostHogLoads after first paint[External]Zalo, MessengerText or a 1080×1350 cardShake, AI tweakpnpm generateReview, deployChecked JSONRead /loi-chuc3 rewritesAnonymous eventsShare sheetIn focusPersonExternal systemRequestOptional, build time
At runtime only Claude costs money. Codex CLI writes the content ahead of time, at build time.

At runtime Wishjar has a single paid dependency, Claude, and one at build time, Codex CLI. Codex writes new lines against a JSON schema, a script checks each line and drops near-duplicates, and I read them before committing. The content exists before anyone opens the app, so a tap returns a line instantly.

Wishjar · C4 L2: ContainerThe PWA and its service worker run on the phone; a Node server and a SQLite file run on the VPS; a build step bakes the library into the image.Your phoneVPS · Docker Compose[Person]SenderOn a phone[Container: Vite + TS]Wishjar PWAWhole library in the bundle,state in the URL,favorites in localStorage[Container: Workbox]Service workerPrecache, offline shell,fonts kept for a year[Shared VPS edge]Cloudflare, Traefik30 req/s per IP,burst 60[Container: node:http, Node 22]wishjar-webStatic files, POST /api/rewrite,256 MB, read-only root[Container: node:sqlite, WAL]SQLite archiveEvery fresh AI line, FTS5[External]Claude Haikumessages.parse + schema[External]PostHogOnly with a key[Container: tsc, vite build, prerender]Build pipelineTypecheck, bundle the library, write 29 SEO pages,sitemap and robots, then docker buildUsesFetchHTTPSai_wishesRewriteEventsdist/ in imageIn focusPersonIn the systemExternal systemData storeRequestOptional, build time
Reading a wish never reaches the VPS. Only the AI tweak does, and that path carries every limit.

At L2, the whole library ships in the bundle (the main chunk is about 73 KB gzip) and a service worker precaches the app. Reading a wish never touches the server, and the jar still shakes offline. The Node server serves static files and exactly one endpoint, POST /api/rewrite. Each fresh AI line lands in SQLite so I can review the good ones and serve them to other people later.

Wishjar · C4 L3: Components in the Node serverA request is routed to static files or to the rewrite path, which runs a guard, a limiter chain, a cache, the model call, a validator and an archive.wishjar-web · node:http[server/index.ts]RouterCSP, HSTS, COOPon every answer[server/index.ts]Static filesHashed assets cachedfor a year[server/index.ts]Request guardOrigin allowlist,JSON only[server/limits.ts]Limiter chainIP 6/min, 60/day,visitor 40/day[server/limits.ts]Answer cache24 h, 20,000 entries,shared in-flight calls[server/rewrite.ts]Model callOn a miss: 3,000/dayin total, 8 in flight[server/rewrite.ts]ValidatorSchema, 320 chars,dedupe, max 3[server/store.ts]Archive storeMigrations byuser_version[External]Claude HaikuThe paid call[Docker volume]SQLite filewishjar.dbFrom TraefikGET /*POSTMissParseNew linesKeep 24 hWAL, FTS5In focusIn the systemExternal systemData storeRequest
Cheap checks run first and Claude runs last. Any step can turn the request away.

L3 is a pipeline where any step can turn the request away, and the cheap steps run first. The origin and content type are checked first. Then come the per-caller limits: 6 calls a minute and 60 a day per IP, 40 a day per visitor. Only then is the body read, capped at 1 KB, and looked up in the 24-hour answer cache, where identical requests arriving together share one call. On a cache miss, two more checks run: 3,000 calls a day in total and at most 8 model calls in flight. Claude only sees a request that every cheaper step let through.

The request never carries free text, either. The client sends a library id, a style and an audience, and the prompt contains only our own lines, so there's nothing to inject. The reply is parsed against a schema and checked again against the same token and length rules the generator applies.

What "ready to scale" means here

Neither app needs to scale today. I put the borders in the right places, so on the day it matters I replace one box on the diagram and leave the rest alone. Six habits cover most of it:

  • Separate state that must survive from state you can lose. Postgres and the SQLite file get backups; Valkey, caches and rate limits can vanish.
  • Every paid path has a ceiling, written in code, not only in a provider's dashboard.
  • One gate for outside requests: the Shield in Ăn Gì, the request guard in Wishjar. Abuse rules live in one place.
  • Caches know when to refresh: Ăn Gì flushes by tag when data changes, and Wishjar keys its cache on the wish, the style and the audience.
  • Do work as early as you can: at build time (prerendering, content generation), at the edge (immutable assets, image cache), or on the device (search, spin, offline).
  • Monolith first. Martin Fowler noticed that almost every successful microservice story started with a monolith that grew too big and was then split. Clear borders inside a monolith are far cheaper than network borders between services.

One more habit sits outside the diagrams: write the reasons down. Ăn Gì has 33 ADRs as of 22 November 2026, over 1,000 Vitest tests and over 200 Playwright tests. I write ADRs for future teammates, and the teammate is usually me a few months later.

When the UI grows

An app that gains a screen every week gets messy fast if the interface has no system behind it. Ăn Gì has about 100 design tokens as CSS custom properties for color, spacing and type, 39 of them redefined for dark mode, CSS Modules per component, one shared Sheet component for every slide-up panel, and typed Vietnamese and English dictionaries, so a missing translation fails the build.

Performance has a budget too: the server sends the first 20 place cards, about 11 to 13 KB gzip, and the rest arrives after first paint. A bundle check script blocks leaked source maps and keys. Mobile LCP is still 2.9 to 3.7 seconds against my own 2.5-second target, so that's next on the list. Wishjar goes the other way: no UI framework, state in the URL so a shared link reopens the same card, and the whole app in about 73 KB gzip.

Where they aren't ready yet

These are the places that would break first under real growth, and what I plan to do when that day comes:

AppBreaks firstNext step
Ăn GìThe data layer loads every place into memory, and the client receives the full dataset after first paint. Fine for a few hundred places.Query by area and paginate in Postgres, keeping the same cache tag.
Ăn GìMigrations run on startup. Two web replicas would run them twice.Run migrations as a separate deploy step before the new version takes traffic.
Ăn GìThe Next cache lives on local disk, and chat rate limits live in memory.A shared cache handler, and every counter moved to Valkey.
Ăn GìOne VPS, backups only as a nightly dump plus one before each deploy, errors only as PostHog exceptions, no tracing.WAL archiving or a managed Postgres, then a real error tracker and OpenTelemetry. More in observability as a design choice.
WishjarRate limits, the answer cache and in-flight calls are all in memory. The code says so: safe for one container only.Move them to Valkey before running a second copy.
WishjarSQLite allows many readers but one writer at a time, and writes run synchronously on the event loop.Fine for an archive. Move to Postgres once reviewing AI lines becomes a real feature.
WishjarThe library ships in the bundle, so more lines mean a heavier bundle.Split the JSON per occasion and load only the one on screen.
WishjarDeploy builds on the VPS and has no rollback.Build the image in CI and keep the previous tag. Ăn Gì has a documented manual rollback, but it builds on the VPS too.

I found most rows of this table while drawing the diagrams. Once the borders are on paper, weak spots tend to sit on the arrows: state held in memory, or a step that would run twice with two copies. For the deeper version of each fix, there are posts on cache pitfalls, scaling a database one step at a time and when to split a monolith.

Try it on your own side project

This week, take a sheet of paper and draw levels 1 and 2 of your side project, nine boxes at most per level. Mark three things: which paths cost money, which state has to survive, and how many gates an outside request passes. If you can't say where some piece of state lives, that's the first thing to fix.

And if you'd like to see both apps running, each has a demo on my apps page: spin a dish with Ăn Gì, shake a wish out of Wishjar.

What did you think?

Frequently asked questions

What is the C4 model?
C4 is a way to draw software architecture at four zoom levels, created by Simon Brown: system context, containers, components and code. Each level answers one question, from who uses the system down to how one container is built inside.
Do side projects really need architecture diagrams?
Not to run, but they help you see where state lives, which calls cost money and which step would run twice with two servers. Drawing levels 1 and 2 on paper takes about half an hour and usually surfaces the first thing worth fixing.
What makes Ăn Gì and Wishjar ready to scale?
The web containers keep almost no state of their own (the Ăn Gì Next cache and chat limits are the exceptions), every paid API has a ceiling in code, outside requests pass one gate, caches know when to refresh, and as much work as possible happens at build time, at the edge or on the device.
What would break first if traffic grew a lot?
For Ăn Gì, the data layer that loads every place into memory and migrations that run on startup. For Wishjar, rate limits and caches kept in memory, which only work with one server. The post lists each weak spot with the planned fix.