SOHAM

Starting SOHAM

Engineering notes

How SOHAM is built

Most product pages describe what a thing does. This one describes how it is made — the stack and why each piece earned its place, the order the work actually happened in, and the failures that changed the code. The failures are included deliberately: a build log with no mistakes in it is not a build log.

Pages
54
API routes
31
Build steps
9
Logged failures
9

Reviewed November 18, 2026 · counts read from the repository

The stack, and why each piece is here

A dependency list is easy to produce and tells you nothing. What follows groups the stack by the job it does, and states the reason each piece is present — including what it would cost to remove.

Framework and rendering

One Next.js app serves the pages, the API routes and the streaming proxy.

Next.js 14 (App Router)

Pages, API routes, middleware

Server routes and React pages in one deployable unit. The chat needs both: a page that streams tokens and a route that proxies the backend without exposing it to the browser.

React 18

UI runtime

Concurrent rendering and Suspense, which is what keeps a token stream from blocking the rest of the page.

TypeScript

Language

The backend contract is a set of loosely-typed JSON events. Types are what catch a misspelled field in an SSE payload before a user does.

Interface

A component layer that can be composed into real screens instead of one-off markup.

Tailwind CSS

Styling

Utility classes keep the responsive rules next to the markup they apply to. The chat is layout-sensitive at four breakpoints; hunting those in a stylesheet is slower.

shadcn/ui + Radix primitives

Accessible components

Dialogs, popovers and menus that already handle focus trapping, escape keys and screen-reader wiring. Rebuilding those by hand is where accessibility usually breaks.

lucide-react

Icons

Tree-shakeable SVG icons with no icon-font request.

Content and data

Markdown in the chat, PDFs out, a local database for history.

react-markdown + remark-gfm + remark-math

Rendering replies

Model replies are Markdown with tables, task lists and LaTeX. Each extension adds a syntax the model can safely use.

KaTeX

Math

Rendered maths instead of raw LaTeX. Students reading a solved equation should see an equation.

react-syntax-highlighter (Prism)

Code blocks

Tokenised code with a language label and a copy button, rather than a grey box.

IndexedDB

Chat history

History lives in the browser. It works offline and the server does not need to hold every conversation to show a sidebar.

Firebase Auth

Accounts

Google and email sign-in, plus the identity the backend uses to scope memory.

pdf-lib / PDF pipeline

PDF Analyzer and chat export

Reading documents in, and getting a conversation out as a file someone can keep.

Motion and data display

Used sparingly, and switched off when the reader asks for less motion.

Recharts

Charts

Charts the model asks for are data, not images: they stay crisp and can be read by a screen reader.

Framer Motion

Transitions

Only where a change of state would otherwise be a jump — overlays and panel transitions.

Three.js / react-three-fiber

Landing visuals

Confined to the marketing pages. The chat itself has no WebGL dependency.

Infrastructure

Two hosts, split along a line that turned out to matter.

Vercel

Frontend hosting

Next.js deploys natively, previews per branch, and the edge middleware runs the security headers before a request reaches a page.

Render

Backend

The model calls, tool calls and memory live here, behind a secret key. The browser never sees a provider key or a backend URL it could call directly.

Upstash Vector

Memory search

Embeddings for recalling relevant past context without loading an entire history into every prompt.

@ducanh2912/next-pwa

Installable app

A service worker and manifest, so SOHAM can be added to a home screen and reopen offline with its shell intact.

How it was built, in order

The order matters as much as the steps. Almost every one of these was built before the thing that depended on it, which is why later features did not require a rewrite. Each step also names the part that was genuinely hard.

  1. 01

    Decide the split: browser, frontend server, backend

    Three places code can run, and each answer moves security. Model provider keys cannot ship to the browser, so every model call goes through a server. The backend holds those keys and the memory; the frontend proxies to it and never exposes its URL or key to the page.

  2. 02

    Build the chat shell before the chat

    Header, sidebar, scrolling list, docked composer. Getting the layout right first meant every later feature — citations, video cards, error states — had a place to go that did not need the shell rebuilt.

    The hard part: A chat screen must fill exactly one viewport: the composer pinned, the list scrolling, nothing else moving. Wrong height rules here produce a page that scrolls as a whole, which feels broken.

  3. 03

    Stream tokens, and keep them smooth

    Replies arrive as server-sent events. A reader pulls them from the response body, parses each `data:` line, and hands text to a small typewriter so the answer appears at a readable pace rather than in lumps.

    The hard part: The stream can also carry a video result, an image or a failed tool call, in any order. The parser had to be tolerant: an unknown event is skipped, never fatal.

  4. 04

    Make the contract explicit

    Every event has a documented shape: `status`, `token`, `image`, `play`, `sources`, `tools`, `done`, `error`. The frontend treats the backend as untrusted input and re-validates anything that becomes a link or renders markup.

    The hard part: Backward compatibility. An older backend emits none of the newer events, and the UI must degrade to something sensible instead of rendering empty shells.

  5. 05

    Add the surfaces a real conversation needs

    Citations under answers, a source list that survives reloads, per-message tools and latency, a dim warning when live data fails, and an error bubble that keeps its place with a working Retry — not a toast that vanishes before it can be read.

  6. 06

    Persist history in the browser

    Chats are stored in IndexedDB, which keeps the server from needing a copy of every conversation and keeps history working offline. Stored records are re-validated on the way back out, because data on disk is a different trust boundary from data on the wire.

  7. 07

    Harden, then verify the hardening

    Debug endpoints return 403 in production, the demo route 404s, the health route redacts backend details and reports degraded honestly, and security headers are set once, in one place.

    The hard part: The verification is the work. It is easy to believe a gate exists because a route returns early somewhere; proving it required running a production build and curling each route for its real status code.

  8. 08

    Make it deployable, which is not the same as making it build

    A clean production build on the developer machine says nothing about platform validation. Two deploy failures later, the lesson was written down next to the config file.

  9. 09

    Polish for phone, tablet and desktop

    Touch targets at 44px, safe-area padding for notched screens, a sidebar that becomes a drawer before it crowds the conversation, and a composer aligned to the same measure as the messages it sits under.

What went wrong, and what fixed it

Every entry below is a real problem this codebase hit. Each one lists the symptom as it appeared, the actual cause, the fix, and the part worth remembering on a different project entirely.

1

The deploy failed on a timezone variable

Symptom

The Vercel build stopped with "The following environment variables can not be configured: TZ". Nothing was wrong with the code.

Cause

`TZ` was set inside `vercel.json`. Vercel reserves that name and rejects the whole configuration rather than ignoring the key.

Fix

Removed the block. The app never needed it: the clock and exported chats set `timeZone: 'Asia/Kolkata'` explicitly, and the content dates are formatted in UTC, so nothing depends on what the host process happens to be set to.

A platform config file is not a place for optimism. Verify every key against the platform's own rules, and prefer making the app correct independent of the environment over configuring the environment to suit it.

2

The very next deploy failed again — on regions

Symptom

After the timezone fix, the build failed a second time: "Deploying Serverless Functions to multiple regions is restricted to the Pro and Enterprise plans."

Cause

`regions` listed two entries. The project is on the Hobby plan, which allows exactly one function region.

Fix

Reduced to a single region. The constraint is now documented next to the file so it cannot be quietly re-added.

Fixing one platform constraint often reveals the next, because validation runs in order and stops at the first error. Expect to fix several unknown constraints in sequence, not one.

3

A modal was anchored to the message box

Symptom

The "Analyze Image" dialog dimmed only the bottom strip of the screen and squeezed itself into it, instead of covering the viewport.

Cause

`position: fixed` resolves against the nearest ancestor that establishes a containing block, not always the viewport. Two ancestors did: the input bar uses `backdrop-blur`, and the page transition wrapper carried `will-change: transform`.

Fix

Portalled the dialog to `document.body` so it leaves the blurred subtree, and removed the permanent `will-change` from the page transition — which had been silently breaking every other full-screen overlay in the app too.

A CSS property that looks decorative can change layout semantics for its descendants. When a fixed element misbehaves, walk its ancestors looking for transform, filter, backdrop-filter, will-change or contain.

4

The thinking animation promised work that was not happening

Symptom

While waiting for a reply, the UI displayed the pipeline stage — including "Searching the web" — even for questions that needed no search.

Cause

The indicator echoed the backend's status events verbatim, so it narrated internal tool use as if it were a promise to the user.

Fix

Replaced the stage text with neutral placeholder lines, and stopped storing the stage names in state at all so they cannot reappear.

An interface that reports internal machinery is making a claim it cannot keep. Status text should describe the experience the user is having, not the internal steps you happen to know about.

5

A reopened chat claimed the video was not found

Symptom

Opening an older conversation showed "Couldn't find a video for ──" with empty quotes, directly under a reply that had described the video correctly.

Cause

The failure card was rendered whenever no playable candidate was stored, so absence of data was treated as a failed search. The empty quotes were the tell.

Fix

The card now follows what is actually stored — a hit renders the player, a recorded failure renders the failure — and a failure is only persisted when there is a real query to retry.

Punctuation in an error message is evidence. Two empty quote marks pointed at a missing value, and finding the missing value was faster than reading the component.

6

A class name silently did nothing

Symptom

Tap targets were set to `min-h-11` and looked right in the source. On a phone they stayed 20px tall.

Cause

`min-h-11` is not in Tailwind's default `min-h` scale, which has only `0`, `full` and `screen`. Tailwind generated no rule at all, and an unknown class fails silently by design.

Fix

Used an arbitrary value, `min-h-[44px]`, then grepped the compiled CSS to confirm `min-height:44px` was actually emitted.

Never trust a utility class because it looks plausible. Check the built stylesheet, not the source.

7

The chat could overflow sideways on desktop

Symptom

A horizontal scrollbar could appear on a long message, only on desktop.

Cause

Message rows capped at `calc(100vw - 5rem)`. `100vw` includes the width of the scrollbar, so the cap was wider than the actual content box.

Fix

Removed the viewport-based cap; percentage caps already did the job correctly.

`vw` units include the scrollbar. For anything that must fit inside the page, percentages or container queries are the safe measure.

8

The sidebar squeezed tablets

Symptom

On a 900px tablet the conversation was noticeably cramped while a 280px sidebar stayed permanently open.

Cause

The sidebar's collapse breakpoint was 768px, which is a phone breakpoint. A tablet is wide enough to feel like a desktop but not wide enough to afford a docked rail.

Fix

Gave the sidebar its own 1024px threshold, separate from the shared mobile breakpoint used elsewhere in the app.

One breakpoint for a whole app is a compromise. A component that consumes a lot of width deserves its own.

9

Two security headers disagreed, and the stricter one won

Symptom

Clickjacking protection was in the middleware, but the setting that reached the browser was different from the one written there.

Cause

`vercel.json` also sent `X-Frame-Options: DENY` on every route while the middleware sent `SAMEORIGIN`. A browser honours the stricter of duplicate values, so the file quietly overrode the code.

Fix

Removed the duplicate. Security headers now have exactly one source, and the middleware is it.

Two places setting the same header is not redundancy, it is a conflict with an implicit winner. Grep for a header before assuming your code controls it.

How changes are checked

Before a change is considered finished it has to survive the same sequence: type-check, lint, and a full production build with no local environment file, so the build runs under the same conditions as the host. Feature behaviour is then exercised against a running production server — real status codes for real routes, not a reading of the code.

Two limits are stated plainly rather than hidden. Some behaviour cannot be checked from a build log — a dialog that looks wrong, a tap target that is too small — so it is inspected in a browser instead. And a clean build on a developer machine says nothing about platform configuration, which is exactly how two consecutive deploy failures reached production.

See what it actually does

The features page covers what SOHAM can do, the blog tracks what changed, and the documentation explains how to use it.