Phil Warner
All projects

NotWordle

In progress

A Wordle-style game where the server owns the answer, so it can't be found in DevTools. A simple game, rebuilt with a Postgres database, server-side game logic and hand-built authentication.

Role
Solo: design, code, tests, deployment
Timeline
Since September 2026, ongoing
Stack
Next.js 16 (App Router), React 19, TypeScript, Neon Postgres, Zod, Jest + Testing Library, Vercel
Tests
192 passing

Why I rebuilt it

I thought Wordle would be an interesting app to rebuild: simple on the surface, with real problems underneath. My first version worked, but the answer lived in the browser: anyone could open DevTools and read it. I wanted to fix that properly and use the project to learn the parts of full-stack work I hadn't done end to end.

  • The answer never reaches the browser

    Until the game is over.

  • Games are saved in a real database

    So a refresh doesn't lose progress.

  • Accounts I build myself

    Not a hosted auth product, so I'd understand sessions, hashing and cookies.

  • Raw SQL, no ORM

    So I'd learn what the database is actually doing.

The first version (board, keyboard, tile colors, accessibility and tests) took a single day. Everything after that is the rebuild.

How it's built

The browser only sends letters and receives colors. The server picks the word, checks guesses and stores every game in Postgres.

Browser

Sends letters, gets colors back. A guest's game id lives in an HttpOnly cookie that scripts can't read.

Server Functions

startGame submitGuess getGame score guesses; toGameState hides the answer.

Neon Postgres

games, users and sessions tables

  • Server Functions, not API routes. The browser calls startGame, submitGuess and getGame directly, like ordinary functions. Functions in each feature's actions.ts are the only server code it can reach.
  • Colors are derived, not stored. The database keeps just the answer and the guesses. Win, loss and tile colors are calculated on every request, so they can't fall out of sync.
  • The answer is hidden until the game ends. One function, toGameState, decides what the browser sees.
  • Raw SQL through Neon's serverless driver. The games table has five columns.
  • Server-only code is fenced off. Word lists and database access live under lib/server/ and import server-only, so the build fails if any of it reaches the browser bundle.
  • One public file per feature. Every export from a 'use server' file is a public endpoint, so those files hold only the actions, and helpers live elsewhere.
  • Refresh-safe. On load the server finds the current game, the newest unfinished game from the last 24 hours, and sends it with the page. It works across devices.

Problems I solved

Repeated letters

With the answer REACT, the guess EERIE gives only one colored E. I count each letter in the answer, mark greens first and use up their count, then hand out yellows only while letters remain. Two linear passes, no nested loops.

Answer R E A C T
Guess E E R I E
REACT has one E. The green uses it up, so the other two E's stay gray.

Two guesses at once

Two requests for the same game could both pass a "fewer than 6 guesses" check and push the game to 7. I moved the rule into the database: the UPDATE only runs if the game still has room and isn't already won. If no row comes back, another request finished first, so the server returns the latest state instead of an error. Checked in production: a 7th guess from a stale second tab is rejected, and that tab catches up to the real game.

Errors the player can act on

Next.js hides thrown error messages in production, so a player would only see "Something went wrong." My rule: if a normal player can cause it and act on it ("Not in word list"), return it as data. If only a bug or tampering can cause it, throw.

  • Real words only

    12,972 allowed guesses, 2,315 of which can be answers, kept on the server in a Set for instant checks.

  • Slow networks

    A wave on the active row that waits 300 ms to appear and stays at least 600 ms once shown, so it never flickers. A fade with Reduce motion on.

  • Accessibility

    Rows are named groups and tiles are announced as "R, present", so results never rely on color alone.

A hydration error for returning guests

When a guest came back, React showed a hydration error. The page is drawn twice, first on the server and then in the browser, and React expects both to match. They didn't. The guest's game id was saved in localStorage, which only the browser can see. So the server thought every visitor was new and drew the sign-in box, while the browser found the saved game and didn't.

The fix was to save the game id in a cookie instead. The browser sends cookies to the server with every request, so the server now knows who you are and draws the right page the first time. The cookie is HttpOnly, so scripts can't read it, and localStorage is gone from the app.

The keyboard below the screen on phones

Measured in Safari Web Inspector, the keyboard spilled 65px below the screen on iPhones. The board now shrinks to fit the space left, using a CSS size container: container-type: size and cqh units. Short phones get tighter spacing, and the keys never shrink. Working on localhost, not live yet.

Designing accounts from scratch

In progress

I designed authentication before writing any of it, like a design review: reason through each decision and draw every flow (sign up, sign in, signed-out guess, signed-in guess, sign out) as a sequence diagram.

Accounts work; sliding sessions are next

8 of 9
8 of 9 steps done
  • Database tables for users and sessions
  • Email normalizing and sign-up validation
  • Password hashing and checking
  • Sessions and secure cookies
  • Sign-up on the server, claiming a guest game
  • Sign in and sign out
  • Ownership checks on every guess
  • Sign-up and sign-in forms
  • Sliding session expiry

The decisions behind it. Sliding sessions are the only one not built yet.

Decision What I chose Why
Login method Email and password The best way to learn what's under the hood
Sessions Rows in a sessions table, not signed cookies; the cookie holds a random id Logging out or revoking a session takes effect instantly
Session length 7 days; sliding expiry is next Next, a guess with less than half the 7 days left will push the expiry forward, so an active player never gets logged out
Cookie HttpOnly Secure SameSite=Lax JavaScript can't read it, it's HTTPS only, other sites can't use it
Password hashing Node's built-in scrypt, a random salt per user, constant-time compare Built into Node, so there's no extra package to install. OWASP recommends it when Argon2id isn't available
Password rules At least 8 characters, no symbol rules Follows current NIST guidance
Sign-in errors "Incorrect email or password" for both cases. An unknown email still checks the password against a dummy hash, so both take the same time Doesn't reveal which emails have accounts
Guests Login is optional; a guest's game has no owner until sign-up or sign-in claims it Nobody loses a game in progress by creating an account
Duplicate emails ON CONFLICT DO NOTHING on a normalized email One query, and no race between "check" and "insert"
Ownership A game without an owner is open to anyone with its id, an unguessable uuid. An owned game only accepts guesses from its owner The check runs before any game data is sent back, so a stranger never sees a finished game's answer
Sign out logout() takes no arguments and only uses the caller's own session cookie An email argument would prove nothing about who is calling
Current game The newest unfinished game from the last 24 hours Works across devices. Older unfinished games are kept as "abandoned" for the planned results history
Game length One 24-hour value, shared by the SQL queries and the guest cookie's expiry Fixed a bug where the guest cookie had copied the 7-day session length

On an owned game, a signed-out caller gets "Log in to keep playing", and a different account gets "This game belongs to another account. Refresh to load yours."

Flowchart of the ownership check. A game with no owner is a guest game, so the guess goes through. If the game has an owner and the player isn't logged in, the result is the error 'Log in to keep playing'. If a different account is logged in, the result is the error 'This game belongs to another account. Refresh to load yours.' Only the owner's guess goes through.
What the server checks before it accepts a guess. See all the auth flows

The sign-in box

  • One box, two forms (sign in and sign up) and a "Play as guest" option. A game is only created after the player chooses, so page loads no longer create empty game rows.
  • Opened with show(), not showModal(). showModal() put the box above 1Password's autofill menu, which then couldn't be clicked.
  • Forms keep what was typed after an error. They submit through onSubmit and startTransition, because React's action={} clears every field, even on an error.
  • Small touches. Each password field has a show/hide button, and the signed-in email shows top right with a Sign out button.

Testing and workflow

  • 192 tests passing in 14 suites
  • 4 checks on every commit: tests, types, lint, build
  • 2 databases: a dev Neon branch keeps test users out of production
  • Component tests play whole games the way a player would: typing, warnings, winning, losing, starting again.
  • Server tests mock the database so each test controls exactly which rows come back. That's how the suite tests two guesses arriving at once.
  • Auth tests use a fake cookie jar, and ownership tests check who can guess on which game.
  • Timing tests use fake timers for the loading wave's delay and minimum display time.
  • Deploys go to production on every push to main, and I check each feature on the live site, not just localhost.

How I used AI

I used AI as a pairing partner, set up to teach rather than write code for me. I drove: I wrote most of the feature code and made the decisions. It explained terms plainly, went one small step at a time, and only offered code when I asked or got stuck. It asked questions, reviewed my work and filled gaps in areas I hadn't done end to end.

  • Auth design. I had some auth experience, but not enough to build it securely alone. I went through it with AI like a design review: it asked one question at a time, I reasoned out my answer first, then it filled gaps and explained the trade-offs. I drew every flow in Excalidraw myself as we went. It recommended; I chose.
  • Decisions that went against the easy path. I turned down Neon Auth and chose raw SQL over an ORM, so I'd learn what's underneath.
  • CSS I hadn't used in years. It walked me through keyframe animation for the loading wave and accessibility details like the reduced-motion fallback. It helped a lot, but I wrote most of the CSS.
  • Tests. AI wrote all 192 tests.
  • When it built too much. Once my wording sounded like "build it all", AI built the sign-in form and the page-load session lookup. I then went through each part interview-style until I could explain it myself. After that we agreed it checks with me before any non-trivial change.

What it caught, and what it missed

It noticed my local environment was writing to the production database, which led to a separate dev branch. It didn't catch a 'use server' file exporting a non-async helper; only the build did. The hydration bug came from code it wrote, and I caught it in the browser, not with tests. That's why no single tool, AI included, gets the last word.

What I learned

  1. 01

    Put the rule where the data is.

    A check in code can be raced; a condition in the SQL WHERE can't.

  2. 02

    Anything in the browser is public.

    Including the answer in memory and every exported Server Function, which anyone can call with any arguments.

  3. 03

    Store less, derive more.

    Saving only answers and guesses removed a whole class of out-of-sync bugs.

  4. 04

    Design before code.

    Drawing the auth flows first meant the code mostly followed the diagrams.

  5. 05

    Only hide what depends on secrets.

    "Password must be at least 8 characters" only describes what was typed, so it's safe to show. Sign-in uses "Incorrect email or password" for every failure, so it doesn't reveal which emails have accounts. Sign-up still reveals it, for now; that's a known gap I chose to leave.

  6. 06

    The first render has to match the server's.

    So data that only exists in the browser can only be read after hydration.

What's next

  • Sliding session expiry
  • Results history per player: won, lost or unfinished, worked out from the guesses and created_at, with no new column
  • Stats like win rate and streaks

Postponed on purpose: rate limiting sign-in attempts, storing a hash of the session id, and stronger scrypt settings plus a pepper (a secret mixed into every hash).

No email verification and no password reset, by choice. Both need a paid email service, which isn't worth it for a portfolio app. With real users I'd add them with a transactional email provider.

Next project RepoPulse