gradation.ai.
A retro-terminal-styled web calculator for construction aggregate blends. It validates the target and aggregate gradations, sends them to an external blending service and shows the blend percentages, a deviation score and charts. Anonymous visitors get 3 calculations, and signed-in users keep their inputs.
- Year
- 2025
- Built for a client
- My part
- Sole developer
- Website
- gradation.ai/calculator
My role
I built the whole app alone, from the input model and validation to accounts and saving. The blend itself is calculated by an external blending service that the app calls.
Capabilities
Inputs
- Target gradation on 10 sieves in two modes: exact values or minimum and maximum ranges
- Auto-range button that builds ranges around the exact values with a chosen tolerance
- Any number of aggregates, each with its own gradation and an on/off switch
- Maximum number of aggregates in the blend, following the enabled count
Validation and results
- Sieve-order checks with cell-level messages that name the previous sieve and value
- Blend percentage per aggregate and the combined gradation per sieve
- Deviation score that counts a value inside a range as zero error
- Charts for exact and range targets, finest to coarsest sieve
Accounts and saving
- Passwordless login with an email and a 6-digit code
- 3 free calculations for anonymous visitors, then a login prompt
- Inputs kept in local storage and, for signed-in users, saved to the database
- First-login migration of local inputs into the account
Patterns and decisions
- I built the whole app alone. The blending itself is done by an external service that the app calls, so the work was everything around it: the input model, validation, scoring, charts, accounts and saving.
- It is a Next.js app with server components for the pages and client components for the calculator and the login forms. The calculator page loads the signed-in user and the user's saved inputs in parallel on the server, and the user lookup is cached so one request asks Supabase once.
- One Zod schema file drives the types, the form resolver, the server action input, the parse of data read from the database and from local storage, and the shape of the service answer.
- Server actions go through next-safe-action. A base client turns thrown errors into readable messages, and an authenticated client refuses a call without a session.
- The aggregate list is a React Hook Form field array. Drizzle ORM keeps one row of inputs per user in PostgreSQL, written as a single upsert.
- Environment variables are validated at startup with T3 Env and loaded with dotenvx. The project runs on Vercel with React Compiler, strict TypeScript, ESLint, Prettier and a GitHub Actions workflow that type-checks and lints every push.
Cases
One input model for two kinds of target. A mix designer sometimes has exact numbers per sieve and sometimes a specification band, and the blending service wants a different request and a different endpoint for each. I made one schema that holds both target shapes plus the active mode, so switching the mode never wipes what was typed in the other one. The server action reads the mode and sends only the strict values to one endpoint, or only the minimum and maximum values to the other. Empty range cells become nulls, which means no limit, and strict cells become numbers. The chart and the score branch by mode too, so the user sees one form, two ways to describe the goal and one result screen. Because real specs allow a tolerance, a tolerance box and an apply button turn the strict values into minimum and maximum pairs in one click, clamped to the 0 to 100 range, rounded to three decimals and skipping empty sieves.
Validation that follows how a sieve analysis works. Percent passing can only fall or stay equal as sieves get finer, and a typo here sends nonsense to the service. Before any request, the form checks that every enabled aggregate, the strict target and both range columns never rise down the sieve list. It marks the exact cell with a message that names the previous sieve and its value. It also checks that a minimum does not exceed its maximum, that required cells are filled for enabled aggregates only, that names are unique and that at least one aggregate is on. One toast then points to the marked fields, and bad data never leaves the page.
A deviation score that understands ranges. The user needs one number that says how close a blend is to the target, in both modes. The score is the average percent error over the sieves that have a target. In strict mode it is the relative distance from the target value. In range mode a value inside the band counts as zero error, and a value outside is measured from the nearest violated bound relative to the middle of the band. Sieves with no bounds are skipped.
Work that survives login. The form holds dozens of numbers and visitors start anonymous, so an account must not mean retyping. Every change goes to local storage at once, and for a signed-in user it is also saved to the database after a half-second pause in typing. When someone signs in with no saved row but with local data, the data is validated with the schema, invalid data is dropped, and the rest is pushed to the database and loaded into the form. Sign-in is passwordless: an email, a terms checkbox and a 6-digit code. An anonymous visitor gets 3 free calculations before a toast asks for login.