All posts
Tutorial · November 28, 2026 · 45 min read

Build a Google Keep clone with Grit: the complete beginner's tutorial

Every command and every line, in the order you type them. A note-taking SaaS with teams, invitations and Stripe billing you do not write, plus a note grid, reminders, archive and trash that are entirely yours. Nothing is elided: copy each file as it appears and you end up with the app in the screenshots.

By Muke JohnBaptist
Build a Google Keep clone with Grit: the complete beginner's tutorial

This is a tutorial, not a tour. Every command is here, every file is here in full, and after each step there is a checkpoint telling you what you should be looking at. If you have never used Grit before, start at the top and type everything. It takes an evening.

What we are building is Google Keep: a grid of coloured note cards you can pin, remind yourself about, archive and throw away. And because a real product is not only its one good screen, it also has teams, invitations, roles, a plan and a card, all of which Grit writes.

The point of the build is the line between those two halves, and where to draw it.

What you will have at the end

ScreenWho writes it
Sign in, register, forgot password, account, profileGrit, from --saas
Organisation: members, invitations, rolesthe multitenant plugin
Billing: plan, renewal, cancel, cardthe Stripe plugin
Labels: list, create, editgenerated from the resource
Notes, reminders, archive, trashyou, in eight files

One of those rows is the product. The other four are furniture that every SaaS has and nobody is paying you to design differently.

Before you start

You need three things installed:

ThingVersionCheck with
Go1.26 or newergo version
Node20 or newernode -v
pnpm10 or newerpnpm -v

No database and no Docker. We are using SQLite and the local disk, which is what the flags below do, so there is nothing to start and nothing to configure.

Then install Grit:

go install github.com/MUKE-coder/grit/v3/cmd/grit@latest
grit version

That must print 3.593.0 or newer. If it prints something older, run grit update. The Stripe step near the end needs 3.593.0 specifically, and I will say so again when we get there.

Step 1: make the project

One command:

grit new keep --triple --next --db sqlite --storage local \
--saas --saas-organizations --saas-billing

Taking those apart, because you will want to choose differently for your own app:

FlagWhat it means
--tripleThree apps: the Go API, a customer-facing Next.js site, a separate Next.js admin
--nextNext.js rather than the Vite and TanStack Router option
--db sqliteA file on disk instead of a Postgres server
--storage localUploads go in a folder instead of a bucket
--saasThe app has customers, not only operators. Adds the signed-in customer area
--saas-organizationsCustomers belong to organisations. Installs the multitenant plugin
--saas-billingYou charge them. Installs the Stripe plugin

Drop the three --saas flags and it asks you instead:

Does this app have customers? > Yes, customers sign in
Do customers belong to organizations? > Yes, organizations
Do you charge them? > Yes, take payments

Either way is the same project. --saas is not a separate scaffolder: it writes "saas": true into grit.json and then runs three things that already existed, grit add web-auth for the signed-in area, grit plugin add multitenant for organisations, and grit plugin add stripe for payments. What the flag adds is being asked once, at the point where you know the answer, instead of discovering three commands separately over a fortnight.

The order they run in matters. The organisation screen and the billing screen are pages inside the customer area, so the customer area has to exist before either plugin looks for it. Installed the other way round, both land outside the shell with no sidebar, no header and no link from anywhere. That was a real bug, fixed in v3.584.0, and it is why --saas runs them for you rather than leaving you to remember.

The command finishes by running pnpm install for you, after the plugins have added their own packages. You do not need to run it yourself. (--no-install skips it, for a script that wants to install later.)

Now set up the database:

cd keep
grit migrate
grit seed

grit migrate creates every table from the Go models. grit seed puts an admin user in, which we will not use for the customer side but which gets you into the admin panel later.

Checkpoint. ls should show apps/, packages/, grit.json and a docker-compose.yml you are not going to need. It should also show app.db, the SQLite file grit migrate just created. .env names it as SQLITE_PATH=./app.db, relative to the project root.

Step 2: run it, and sign up

grit start

That starts all three: the API on localhost:8080, the web app on localhost:3000, the admin on localhost:3001.

Open localhost:3000/register and make an account. Use a real-looking email, it does not have to receive mail.

The first thing that happened to me here was the app refusing the password I tried to use:

{"error":{"code":"VALIDATION_ERROR",
"message":"Your password cannot contain your name or your email address."}}

I had typed keep-password-123 for ada@keep.test. That check was already there. It is the sort of thing you would get round to in month three.

Once you are in, you land on the organisation screen, which is where a multi-tenant app sends a new customer first:

The organisation onboarding screen inside the customer shell: a sidebar with Notes, Overview, Profile, Organization, Billing and Labels, and a single Organization name fieldThe organisation onboarding screen inside the customer shell: a sidebar with Notes, Overview, Profile, Organization, Billing and Labels, and a single Organization name field

Type a name and create the organisation now. Do not skip this. The next step depends on it, and the reason is worth understanding, so there is a section about it below.

Note the sidebar while you are here. Overview and Profile came from the customer area, Organization from the multitenant plugin, Billing from Stripe. None of those entries were typed by hand.

Checkpoint. You are signed in, you belong to an organisation, and /organization shows you as its owner with an invite form.

Step 3: generate the two resources

Stop the dev servers (Ctrl-C) and run these four commands:

grit generate resource Note \
--fields "title:string,body:text,colour:select:yellow|green|blue|pink,pinned:bool,archived:bool" \
--tenant-owned --portal headless
grit generate resource Label \
--fields "name:string,colour:select:yellow|green|blue|pink" \
--tenant-owned
grit generate field Note remind_at:datetime
grit generate field Note trashed_at:datetime
grit migrate

Quote the --fields string. A | outside quotes is a pipe, and the field arrives with one colour and no error message.

Those last two generator lines are worth pausing on. grit generate field puts the column in the Go model, the create and update Zod schemas, the TypeScript type, the handler, the service's writable and filterable lists, the CSV importer, the admin form and table, and the portal descriptor. One command, nine places. grit migrate then adds the column, because the model is the source of truth and no migration file is written.

Two flags are doing the real work here.

--tenant-owned

A note belongs to the organisation, not to the person who typed it.

That is a product decision with teeth. Every query is scoped by a GORM callback, so a forgotten WHERE org_id cannot leak another workspace's notes, and you cannot opt out by accident. The alternative is --owned-by user, which is right for a single-player product and wrong here, because the whole point of inviting your team is that they can read what you wrote.

Get this one wrong and the fix touches every query, every handler and every test. It is worth five minutes before you type the command.

--portal headless

In a --saas project, a resource that belongs to somebody gets a customer-facing screen as well as an admin one. There are three levels:

LevelWhat you get
screensA list, a create page, a detail page, a form, and an entry in the customer sidebar. The default
headlessThe resource as data, plus the hooks. No JSX
offThe hook alone

The rule I would give anybody: the furniture is the same in every SaaS and the product is not.

Labels are furniture. A list, a name, a colour, an edit form. Nobody is going to redesign that, so Label got the default, and here it is, generated, including the empty state:

The generated Labels screen: a heading, a New button, and an empty state reading "No labels yet, when you create one it will show up here" with a Create the first one buttonThe generated Labels screen: a heading, a New button, and an empty state reading "No labels yet, when you create one it will show up here" with a Create the first one button

Notes are the product. A generated list of notes would be a table of titles, and Keep is not a table of titles, it is a ragged grid of coloured cards you can pin. So Note got --portal headless: Grit writes the API, the hooks and a descriptor, and stops.

Checkpoint. Run grit start again and visit localhost:3000/labels. You should see the screen in the picture above, and creating a label should work. localhost:3000/notes is a 404, because nothing has written it yet. That is the next five steps.

What headless left behind

Open apps/web/lib/portal/notes.ts. This is the whole of it, generated:

import type { PortalField } from "./types";
export const notePortal = {
resource: "notes",
label: "Notes",
path: "/notes",
api: "/api/notes",
scope: "organization",
display: "title",
subtitle: "body",
fields: [
{ name: "title", label: "Title", kind: "text", required: true },
{ name: "body", label: "Body", kind: "textarea" },
{ name: "colour", label: "Colour", kind: "select", required: true, options: ["yellow", "green", "blue", "pink"] },
{ name: "pinned", label: "Pinned", kind: "checkbox" },
{ name: "archived", label: "Archived", kind: "checkbox" },
{ name: "remind_at", label: "Remind at", kind: "datetime" },
{ name: "trashed_at", label: "Trashed at", kind: "datetime" },
] satisfies PortalField[],
} as const;
export type NotePortalField = (typeof notePortal)["fields"][number];

You do not edit that file. It is rewritten whenever the model changes.

It is not much, and the little it is buys one specific thing: the colours in our picker will come from here rather than from a list typed into a component, so adding purple to the Go model adds it to the picker with no frontend edit. Hard-code the four colours in JSX and you have made a second source of truth that will be wrong by March.

Two things the descriptor is not. It is not a permission check: the API scopes every read and write by the active organisation, and a filter living in a page is a check an API client walks straight past. And it does not include the owner column, so a customer cannot hand their row to another workspace by editing a form.

Grit also wrote apps/web/hooks/use-notes.ts, which is where useNotes, useCreateNote, useUpdateNote and useDeleteNote come from. Open it if you are curious; you do not need to change it.

Step 4: the search box, which has to cross the layout

Now the part that is ours. Eight files. Create them in this order, because each one uses the one before it.

Create apps/web/components/keep/search-context.tsx:

"use client";
import { createContext, useContext, useState } from "react";
import type { ReactNode } from "react";
// The search box lives in the top bar and the results live in four pages, so
// the term has to cross the layout. Context rather than a query parameter:
// Keep's search does not change the URL, and a page refresh should land you
// on the view rather than on a filtered one you have forgotten about.
const SearchValue = createContext("");
const SearchSetter = createContext<(value: string) => void>(() => {});
export function KeepSearchProvider({ children }: { children: ReactNode }) {
const [term, setTerm] = useState("");
return (
<SearchValue.Provider value={term}>
<SearchSetter.Provider value={setTerm}>{children}</SearchSetter.Provider>
</SearchValue.Provider>
);
}
export function useKeepSearch(): string {
return useContext(SearchValue);
}
export function useSetKeepSearch(): (value: string) => void {
return useContext(SearchSetter);
}

Nothing renders yet. Next file.

Step 5: one note, and the bits of layout every view shares

This is the biggest file and the only one with any real styling in it. Everything about how a note looks lives here, which is what makes the four view pages a filter and a heading each.

Create apps/web/components/keep/note-card.tsx:

"use client";
import { Pin, PinOff, Archive, ArchiveRestore, Trash2, RotateCcw, Bell, BellOff } from "lucide-react";
import type { Note } from "@repo/shared/types";
export const SWATCH: Record<string, string> = {
yellow: "bg-[#fff8c4] border-[#f7eda0] dark:bg-amber-500/10 dark:border-amber-500/20",
green: "bg-[#e2f6d3] border-[#cdebb8] dark:bg-emerald-500/10 dark:border-emerald-500/20",
blue: "bg-[#d3e3fd] border-[#bcd4f7] dark:bg-sky-500/10 dark:border-sky-500/20",
pink: "bg-[#f9d8d8] border-[#f2c3c3] dark:bg-pink-500/10 dark:border-pink-500/20",
};
/** A reminder reads as a date when it is far off and a time when it is today. */
export function reminderLabel(value?: string | null): string {
if (!value) return "";
const at = new Date(value);
if (Number.isNaN(at.getTime())) return "";
const today = new Date();
const sameDay =
at.getDate() === today.getDate() &&
at.getMonth() === today.getMonth() &&
at.getFullYear() === today.getFullYear();
return sameDay
? at.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })
: at.toLocaleDateString([], { day: "numeric", month: "short" });
}
export function isOverdue(value?: string | null): boolean {
if (!value) return false;
const at = new Date(value);
return !Number.isNaN(at.getTime()) && at.getTime() < Date.now();
}
export interface NoteActions {
pin?: () => void;
archive?: () => void;
unarchive?: () => void;
trash?: () => void;
restore?: () => void;
deleteForever?: () => void;
remind?: () => void;
clearReminder?: () => void;
}
export function NoteCard({ note, actions }: { note: Note; actions: NoteActions }) {
const colour = SWATCH[note.colour ?? "yellow"] ?? SWATCH.yellow;
return (
<article
className={
"group mb-4 break-inside-avoid rounded-xl border p-4 transition-shadow duration-200 " +
"hover:shadow-[0_1px_2px_0_rgba(60,64,67,.3),0_2px_6px_2px_rgba(60,64,67,.15)] " +
colour
}
>
{note.title ? (
<h3 className="pr-6 font-medium leading-snug text-foreground">{note.title}</h3>
) : null}
{note.body ? (
<p className="mt-2 whitespace-pre-wrap text-sm leading-relaxed text-foreground/80">
{note.body}
</p>
) : null}
{note.remind_at ? (
<span
className={
"mt-3 inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs " +
(isOverdue(note.remind_at)
? "bg-black/10 text-danger dark:bg-white/10"
: "bg-black/5 text-foreground/70 dark:bg-white/10")
}
>
<Bell className="h-3 w-3" />
{reminderLabel(note.remind_at)}
</span>
) : null}
<div className="mt-3 flex flex-wrap items-center gap-0.5 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100">
{actions.remind ? (
<Action label="Remind me" onClick={actions.remind}>
<Bell className="h-4 w-4" />
</Action>
) : null}
{actions.clearReminder ? (
<Action label="Remove reminder" onClick={actions.clearReminder}>
<BellOff className="h-4 w-4" />
</Action>
) : null}
{actions.pin ? (
<Action label={note.pinned ? "Unpin" : "Pin"} onClick={actions.pin}>
{note.pinned ? <PinOff className="h-4 w-4" /> : <Pin className="h-4 w-4" />}
</Action>
) : null}
{actions.archive ? (
<Action label="Archive" onClick={actions.archive}>
<Archive className="h-4 w-4" />
</Action>
) : null}
{actions.unarchive ? (
<Action label="Unarchive" onClick={actions.unarchive}>
<ArchiveRestore className="h-4 w-4" />
</Action>
) : null}
{actions.restore ? (
<Action label="Restore" onClick={actions.restore}>
<RotateCcw className="h-4 w-4" />
</Action>
) : null}
{actions.trash ? (
<Action label="Move to trash" onClick={actions.trash}>
<Trash2 className="h-4 w-4" />
</Action>
) : null}
{actions.deleteForever ? (
<Action label="Delete for ever" onClick={actions.deleteForever}>
<Trash2 className="h-4 w-4" />
</Action>
) : null}
</div>
</article>
);
}
function Action({
label,
onClick,
children,
}: {
label: string;
onClick: () => void;
children: React.ReactNode;
}) {
return (
<button
type="button"
onClick={onClick}
aria-label={label}
title={label}
className="rounded-full p-2 text-foreground/60 transition-colors hover:bg-black/10 hover:text-foreground dark:hover:bg-white/10"
>
{children}
</button>
);
}
/** The ragged columns Keep uses. A grid would line the cards up, which is the look it avoids. */
export function NoteColumns({ children }: { children: React.ReactNode }) {
return <div className="columns-1 gap-4 sm:columns-2 lg:columns-3 xl:columns-4">{children}</div>;
}
export function SectionLabel({ children }: { children: React.ReactNode }) {
return (
<h2 className="mb-3 px-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-text-secondary">
{children}
</h2>
);
}
export function EmptyState({ icon: Icon, title, hint }: { icon: typeof Bell; title: string; hint: string }) {
return (
<div className="flex flex-col items-center justify-center py-24 text-center">
<Icon className="h-20 w-20 text-text-secondary/30" strokeWidth={1} />
<p className="mt-6 text-lg text-text-secondary">{title}</p>
<p className="mt-1 max-w-sm text-sm text-text-secondary/80">{hint}</p>
</div>
);
}

Three details in there that are the difference between this looking like Keep and looking like a dashboard:

  • columns-1 sm:columns-2 lg:columns-3, not a grid. CSS columns leave the cards ragged, which is Keep's look. A grid lines them up in rows and immediately reads as a table of boxes. break-inside-avoid on the card is what stops a note being split across two columns.
  • The action row is opacity-0 until group-hover, so a wall of notes is a wall of notes rather than a wall of buttons. focus-within:opacity-100 is there so somebody tabbing through can still see what they have landed on.
  • An aria-label on every icon button. A button whose only content is an SVG is a button with no name, and a screen reader reads it as "button".

The class names like text-foreground, text-text-secondary and bg-bg-hover are the project's own palette tokens, defined for you in apps/web/app/globals.css. Use those rather than raw Tailwind colours and the app follows its theme, including dark mode. The four swatch hex codes are Keep's actual note colours, which is the one place a literal is the right answer.

Step 6: the four views, from one query

Create apps/web/hooks/use-keep.ts:

"use client";
import type { Note } from "@repo/shared/types";
import type { UpdateNoteInput } from "@repo/shared/schemas";
import { useNotes, useUpdateNote, useDeleteNote } from "@/hooks/use-notes";
// Keep's Notes, Reminders, Archive and Trash are the same rows under four
// filters, so this asks for them once and divides them here. One request, one
// cache entry, and switching views costs nothing.
export interface KeepViews {
active: Note[];
pinned: Note[];
others: Note[];
reminders: Note[];
archived: Note[];
trashed: Note[];
isLoading: boolean;
error: unknown;
}
export function useKeepViews(search = ""): KeepViews {
const { data, isLoading, error } = useNotes({ pageSize: 200, sortBy: "created_at" });
const term = search.trim().toLowerCase();
const all = (data?.data ?? []).filter((note) => {
if (!term) return true;
return (
(note.title ?? "").toLowerCase().includes(term) ||
(note.body ?? "").toLowerCase().includes(term)
);
});
const live = all.filter((n) => !n.trashed_at);
const active = live.filter((n) => !n.archived);
return {
active,
pinned: active.filter((n) => n.pinned),
others: active.filter((n) => !n.pinned),
reminders: live.filter((n) => Boolean(n.remind_at)),
archived: live.filter((n) => n.archived),
trashed: all.filter((n) => Boolean(n.trashed_at)),
isLoading,
error,
};
}
/** Every write a note can take, with the version the row was loaded at. */
export function useNoteActions() {
const update = useUpdateNote();
const remove = useDeleteNote();
// version goes out as If-Match. Two tabs editing the same note get a 409
// instead of one silently overwriting the other, and the generated hook
// makes the argument required so a call site cannot forget it.
function patch(note: Note, changes: Record<string, unknown>) {
update.mutate({
id: note.id,
version: note.version,
...changes,
} as { id: string; version: number } & UpdateNoteInput);
}
return {
pin: (note: Note) => patch(note, { pinned: !note.pinned }),
archive: (note: Note) => patch(note, { archived: true }),
unarchive: (note: Note) => patch(note, { archived: false }),
// Trash is a column, not a DELETE. Keep's own trash holds a note and lets
// you put it back, and a row that has really been deleted cannot be.
trash: (note: Note) => patch(note, { trashed_at: new Date().toISOString() }),
restore: (note: Note) => patch(note, { trashed_at: null }),
remind: (note: Note, at: string) => patch(note, { remind_at: at }),
clearReminder: (note: Note) => patch(note, { remind_at: null }),
// The one real delete, from the Trash view only.
deleteForever: (note: Note) => remove.mutate(note.id),
isSaving: update.isPending || remove.isPending,
};
}
/** Tomorrow at nine, which is what "Remind me" means when nobody picks a time. */
export function tomorrowMorning(): string {
const at = new Date();
at.setDate(at.getDate() + 1);
at.setHours(9, 0, 0, 0);
return at.toISOString();
}

Two things in that file are worth more than the rest of the tutorial.

version, and why the compiler makes you send it

update.mutate({
id: note.id,
version: note.version, // <- this
...changes,
});

version goes out as an If-Match header. Two tabs editing the same note do not silently overwrite each other: the second one gets a 409 with the current version. The generated hook makes that argument required, so a call site that forgets it does not compile. That is deliberate. Optional, and every call site would have gone on sending nothing.

Trash is a column, not a soft delete

This is the decision I would defend hardest in the whole build.

Grit has a Trash. It is good: soft-deleted rows, a restore endpoint, a nightly purge past the retention window, and an admin screen at /admin/trash. It is also an operator tool, mounted behind RequireRole("ADMIN"), and the thing Keep calls Trash is a product feature a customer uses every day.

So the note carries a trashed_at column, and the customer's four actions are four ordinary writes. Only the Trash view can really delete, and that calls useDeleteNote, which is the soft delete, which puts the row in the operator's trash. Two layers, each answering its own question: the customer's "can I get it back", and the operator's "what was deleted from this account and when".

The division is in the client, and when it should not be

One request, one cache entry, and switching views costs nothing. That is right for Keep, because these are small personal collections. A workspace with ten thousand notes would want the filter in the query instead, and the generated hook takes one:

useNotes({ pageSize: 50, filters: { archived: true } })

filters takes the same column names the API filters on, as strings, numbers or booleans, and they go out as query parameters.

Step 7: the shell

The customer area came with a sidebar. We are replacing it with Keep's: a search bar in the header that all four views read, and a rail of pill-shaped links.

Replace apps/web/app/(app)/layout.tsx with this. The file already exists; overwrite it.

"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import {
Lightbulb,
Bell,
Tag,
Archive,
Trash2,
Building2,
CreditCard,
LayoutDashboard,
User as UserIcon,
LogOut,
Search,
X,
} from "lucide-react";
import { ProtectedWebRoute } from "@/components/ProtectedWebRoute";
import { useMe, useLogout } from "@/hooks/use-auth";
import { KeepSearchProvider, useKeepSearch, useSetKeepSearch } from "@/components/keep/search-context";
const PRODUCT = [
{ href: "/notes", label: "Notes", icon: Lightbulb },
{ href: "/reminders", label: "Reminders", icon: Bell },
{ href: "/labels", label: "Labels", icon: Tag },
{ href: "/archive", label: "Archive", icon: Archive },
{ href: "/trash", label: "Trash", icon: Trash2 },
// grit:nav
];
const ACCOUNT = [
{ href: "/organization", label: "Organisation", icon: Building2 },
{ href: "/billing", label: "Billing", icon: CreditCard },
{ href: "/account", label: "Overview", icon: LayoutDashboard },
{ href: "/account/profile", label: "Profile", icon: UserIcon },
];
function initials(first?: string | null, last?: string | null, email?: string | null) {
const a = (first ?? "").trim();
const b = (last ?? "").trim();
if (a || b) return ((a[0] ?? "") + (b[0] ?? "")).toUpperCase();
return (email ?? "?").slice(0, 2).toUpperCase();
}
export default function AppLayout({ children }: { children: React.ReactNode }) {
return (
<ProtectedWebRoute>
<KeepSearchProvider>
<Shell>{children}</Shell>
</KeepSearchProvider>
</ProtectedWebRoute>
);
}
function Shell({ children }: { children: React.ReactNode }) {
const pathname = usePathname() ?? "";
const { data: user } = useMe();
const logout = useLogout();
const term = useKeepSearch();
const setTerm = useSetKeepSearch();
const isActive = (href: string) =>
href === "/account" ? pathname === "/account" : pathname.startsWith(href);
const link = (item: { href: string; label: string; icon: typeof Bell }) => {
const Icon = item.icon;
const active = isActive(item.href);
return (
<Link
key={item.href}
href={item.href}
className={
// The pill is Keep's: full on the right, square on the left, so the
// active row reads as attached to the rail.
"flex items-center gap-4 rounded-r-full py-3 pl-6 pr-6 text-sm transition-colors " +
(active
? "bg-[#feefc3] font-medium text-foreground dark:bg-amber-500/15"
: "text-foreground/70 hover:bg-bg-hover")
}
>
<Icon className="h-5 w-5 shrink-0" strokeWidth={active ? 2 : 1.75} />
{item.label}
</Link>
);
};
return (
<div className="min-h-screen bg-bg-secondary">
<header className="sticky top-0 z-20 flex h-16 items-center gap-4 border-b border-border bg-background px-4">
<Link href="/notes" className="flex items-center gap-3 pr-4">
<span className="flex h-9 w-9 items-center justify-center rounded-full bg-[#feefc3] text-base dark:bg-amber-500/20">
<Lightbulb className="h-5 w-5 text-amber-500" />
</span>
<span className="hidden text-xl font-medium tracking-tight text-foreground sm:block">
Keep
</span>
</Link>
<div className="relative flex-1 md:max-w-2xl">
<Search className="pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-text-secondary" />
<input
value={term}
onChange={(e) => setTerm(e.target.value)}
placeholder="Search"
aria-label="Search notes"
className="w-full rounded-lg bg-bg-secondary py-2.5 pl-11 pr-10 text-sm text-foreground outline-none transition-colors placeholder:text-text-secondary focus:bg-background focus:shadow-[0_1px_1px_0_rgba(65,69,73,.3),0_1px_3px_1px_rgba(65,69,73,.15)]"
/>
{term ? (
<button
type="button"
onClick={() => setTerm("")}
aria-label="Clear search"
className="absolute right-3 top-1/2 -translate-y-1/2 rounded-full p-1 text-text-secondary hover:bg-bg-hover"
>
<X className="h-4 w-4" />
</button>
) : null}
</div>
<div className="ml-auto flex items-center gap-3">
<span className="hidden text-xs text-text-secondary lg:block">{user?.email}</span>
<span className="flex h-9 w-9 items-center justify-center rounded-full bg-accent/10 text-sm font-semibold text-accent">
{initials(user?.first_name, user?.last_name, user?.email)}
</span>
</div>
</header>
<div className="flex">
<aside className="sticky top-16 hidden h-[calc(100vh-4rem)] w-72 shrink-0 flex-col overflow-y-auto py-3 md:flex">
<nav className="flex flex-col gap-0.5 pr-3">{PRODUCT.map(link)}</nav>
<div className="my-3 mr-6 border-t border-border" />
<nav className="flex flex-col gap-0.5 pr-3">{ACCOUNT.map(link)}</nav>
<button
type="button"
onClick={() => logout.mutate()}
className="mt-auto flex items-center gap-4 rounded-r-full py-3 pl-6 pr-6 text-sm text-foreground/70 transition-colors hover:bg-bg-hover"
>
<LogOut className="h-5 w-5 shrink-0" strokeWidth={1.75} />
Sign out
</button>
</aside>
{/* On a phone the rail becomes a strip at the bottom. */}
<nav className="fixed bottom-0 left-0 right-0 z-20 flex gap-1 overflow-x-auto border-t border-border bg-background px-2 py-1.5 md:hidden">
{PRODUCT.map((item) => {
const Icon = item.icon;
return (
<Link
key={item.href}
href={item.href}
className={
"flex min-w-[72px] flex-col items-center gap-1 rounded-lg px-2 py-1.5 text-[11px] " +
(isActive(item.href) ? "text-accent" : "text-text-secondary")
}
>
<Icon className="h-5 w-5" />
{item.label}
</Link>
);
})}
</nav>
<main className="min-w-0 flex-1 px-4 pb-24 pt-6 md:pb-10 md:pr-8">{children}</main>
</div>
</div>
);
}

Two things in there came from the generated file and must survive any redesign of yours:

  • ProtectedWebRoute, which is the guard. Everything inside this route group is behind it. Delete it and /notes is public.
  • The // grit:nav comment. That is where grit generate resource --portal screens injects a sidebar entry. It is how Labels got into the rail without you typing it. Remove the comment and the next generator run has nowhere to put its link, and says so.

Checkpoint. grit start, then localhost:3000/labels. The page content is the generated Labels screen as before, but the shell around it is now Keep's: yellow lightbulb, search bar, pill rail. The search box does nothing yet.

Step 8: the notes page

Create apps/web/app/(app)/notes/page.tsx:

"use client";
import { useState } from "react";
import { Lightbulb, Plus, Check } from "lucide-react";
import type { CreateNoteInput } from "@repo/shared/schemas";
import { useCreateNote } from "@/hooks/use-notes";
import { useKeepViews, useNoteActions, tomorrowMorning } from "@/hooks/use-keep";
import { notePortal } from "@/lib/portal/notes";
import {
NoteCard,
NoteColumns,
SectionLabel,
EmptyState,
SWATCH,
} from "@/components/keep/note-card";
import { useKeepSearch } from "@/components/keep/search-context";
// The colours come from the generated descriptor rather than a list typed out
// here, so adding one to the Go model adds it to this picker with no edit.
const COLOURS = (notePortal.fields.find((f) => f.name === "colour")?.options ??
[]) as readonly string[];
export default function NotesPage() {
const search = useKeepSearch();
const { pinned, others, active, isLoading } = useKeepViews(search);
const actions = useNoteActions();
const create = useCreateNote();
const [open, setOpen] = useState(false);
const [title, setTitle] = useState("");
const [body, setBody] = useState("");
const [colour, setColour] = useState(COLOURS[0] ?? "yellow");
const [remind, setRemind] = useState(false);
function save() {
if (!title.trim() && !body.trim()) {
setOpen(false);
return;
}
create.mutate(
{
title: title.trim() || "Untitled",
body,
colour,
...(remind ? { remind_at: tomorrowMorning() } : {}),
} as CreateNoteInput,
{
onSuccess: () => {
setTitle("");
setBody("");
setRemind(false);
setOpen(false);
},
},
);
}
return (
<div className="space-y-8">
{/* Compose: one line that grows, the way Keep does it. */}
<div
className={
"mx-auto w-full max-w-[600px] rounded-lg border border-border bg-background " +
"shadow-[0_1px_2px_0_rgba(60,64,67,.3),0_1px_3px_1px_rgba(60,64,67,.15)] " +
(open ? "p-4" : "px-4 py-3")
}
>
{open ? (
<div className="space-y-3">
<input
autoFocus
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="Title"
className="w-full bg-transparent text-base font-medium text-foreground outline-none placeholder:text-text-secondary"
/>
<textarea
value={body}
onChange={(e) => setBody(e.target.value)}
placeholder="Take a note..."
rows={3}
className="w-full resize-none bg-transparent text-sm text-foreground outline-none placeholder:text-text-secondary"
/>
<div className="flex flex-wrap items-center justify-between gap-3">
<div className="flex items-center gap-1.5">
{COLOURS.map((c) => (
<button
key={c}
type="button"
aria-label={c}
onClick={() => setColour(c)}
className={
"flex h-7 w-7 items-center justify-center rounded-full border transition-transform hover:scale-110 " +
(SWATCH[c] ?? "") +
(colour === c ? " ring-2 ring-accent ring-offset-1" : "")
}
>
{colour === c ? <Check className="h-3.5 w-3.5 text-foreground/70" /> : null}
</button>
))}
<button
type="button"
onClick={() => setRemind((r) => !r)}
className={
"ml-2 rounded-full px-3 py-1 text-xs transition-colors " +
(remind
? "bg-accent/10 text-accent"
: "text-text-secondary hover:bg-bg-hover")
}
>
{remind ? "Reminder: tomorrow 9am" : "Remind me"}
</button>
</div>
<button
type="button"
onClick={save}
disabled={create.isPending}
className="rounded px-6 py-1.5 text-sm font-medium text-foreground transition-colors hover:bg-bg-hover disabled:opacity-60"
>
{create.isPending ? "Saving..." : "Close"}
</button>
</div>
</div>
) : (
<button
type="button"
onClick={() => setOpen(true)}
className="flex w-full items-center gap-3 text-left text-sm text-text-secondary"
>
<Plus className="h-4 w-4" />
Take a note...
</button>
)}
</div>
{isLoading ? (
<NoteColumns>
{Array.from({ length: 8 }).map((_, i) => (
<div
key={i}
className="mb-4 h-32 animate-pulse break-inside-avoid rounded-xl bg-bg-secondary"
/>
))}
</NoteColumns>
) : null}
{!isLoading && active.length === 0 ? (
<EmptyState
icon={Lightbulb}
title={search ? "No matching notes" : "Notes you add appear here"}
hint={
search
? "Try a different word."
: "Everyone in this organisation can see them."
}
/>
) : null}
{pinned.length > 0 ? (
<section>
<SectionLabel>Pinned</SectionLabel>
<NoteColumns>
{pinned.map((note) => (
<NoteCard
key={note.id}
note={note}
actions={{
pin: () => actions.pin(note),
archive: () => actions.archive(note),
trash: () => actions.trash(note),
remind: note.remind_at ? undefined : () => actions.remind(note, tomorrowMorning()),
clearReminder: note.remind_at ? () => actions.clearReminder(note) : undefined,
}}
/>
))}
</NoteColumns>
</section>
) : null}
{others.length > 0 ? (
<section>
{pinned.length > 0 ? <SectionLabel>Others</SectionLabel> : null}
<NoteColumns>
{others.map((note) => (
<NoteCard
key={note.id}
note={note}
actions={{
pin: () => actions.pin(note),
archive: () => actions.archive(note),
trash: () => actions.trash(note),
remind: note.remind_at ? undefined : () => actions.remind(note, tomorrowMorning()),
clearReminder: note.remind_at ? () => actions.clearReminder(note) : undefined,
}}
/>
))}
</NoteColumns>
</section>
) : null}
</div>
);
}

Checkpoint, and this is the big one. Visit localhost:3000/notes. You should see the compose box and an empty state. Click "Take a note...", type a title and some text, pick a colour, press Close. The card appears. Hover it and the pin, bell, archive and trash buttons fade in. Pin it and it jumps to a Pinned section. Type in the search box and the grid filters.

The Keep note grid: a rail of pill-shaped links down the left, a search bar across the top, a Pinned section with a yellow card and an Others section with pink, green and blue cards, one carrying a reminder chipThe Keep note grid: a rail of pill-shaped links down the left, a search bar across the top, a Pinned section with a yellow card and an Others section with pink, green and blue cards, one carrying a reminder chip

If you got 400 instead

[400] GET /api/v1/notes?page=1&page_size=200&sort_by=created_at&sort_order=desc

That means you skipped Step 2's organisation. --tenant-owned is doing its job: a note belongs to an organisation, you do not have one yet, so there is no scope to read within and the middleware refused rather than guessing. Go to /organization, create one, come back. 200.

It is worth sitting with that for a second, because the alternative is worse in a way that is hard to see. A framework that answered "no notes" to a request with no organisation would look friendlier and would be lying: the same query from a user who does belong somewhere would be scoped, and the one from a user who does not would quietly read the whole table the day somebody removed the filter. Refusing is the behaviour you want from the layer that stops one customer reading another's data.

Step 9: the other three views

Each is the same hook with a different filter. They are short because note-card.tsx holds everything about how a note looks.

Create apps/web/app/(app)/reminders/page.tsx:

"use client";
import { Bell } from "lucide-react";
import { useKeepViews, useNoteActions } from "@/hooks/use-keep";
import { useKeepSearch } from "@/components/keep/search-context";
import {
NoteCard,
NoteColumns,
SectionLabel,
EmptyState,
isOverdue,
} from "@/components/keep/note-card";
// Reminders: every live note that has one, overdue first.
export default function RemindersPage() {
const search = useKeepSearch();
const { reminders, isLoading } = useKeepViews(search);
const actions = useNoteActions();
const due = reminders.filter((n) => isOverdue(n.remind_at));
const upcoming = reminders
.filter((n) => !isOverdue(n.remind_at))
.sort((a, b) => (a.remind_at ?? "").localeCompare(b.remind_at ?? ""));
if (!isLoading && reminders.length === 0) {
return (
<EmptyState
icon={Bell}
title="Notes with upcoming reminders appear here"
hint="Set one from the bell on any note."
/>
);
}
return (
<div className="space-y-8">
{due.length > 0 ? (
<section>
<SectionLabel>Past</SectionLabel>
<NoteColumns>
{due.map((note) => (
<NoteCard
key={note.id}
note={note}
actions={{
clearReminder: () => actions.clearReminder(note),
archive: () => actions.archive(note),
trash: () => actions.trash(note),
}}
/>
))}
</NoteColumns>
</section>
) : null}
{upcoming.length > 0 ? (
<section>
{due.length > 0 ? <SectionLabel>Upcoming</SectionLabel> : null}
<NoteColumns>
{upcoming.map((note) => (
<NoteCard
key={note.id}
note={note}
actions={{
clearReminder: () => actions.clearReminder(note),
archive: () => actions.archive(note),
trash: () => actions.trash(note),
}}
/>
))}
</NoteColumns>
</section>
) : null}
</div>
);
}

The Reminders view: the same rail with Reminders active, showing the one note that has a reminder with its date chipThe Reminders view: the same rail with Reminders active, showing the one note that has a reminder with its date chip

Create apps/web/app/(app)/archive/page.tsx:

"use client";
import { Archive } from "lucide-react";
import { useKeepViews, useNoteActions } from "@/hooks/use-keep";
import { useKeepSearch } from "@/components/keep/search-context";
import { NoteCard, NoteColumns, EmptyState } from "@/components/keep/note-card";
// Archive: put away, not deleted. Still searchable, still restorable, and
// out of the way of the notes you are working with.
export default function ArchivePage() {
const search = useKeepSearch();
const { archived, isLoading } = useKeepViews(search);
const actions = useNoteActions();
if (!isLoading && archived.length === 0) {
return (
<EmptyState
icon={Archive}
title="Your archived notes appear here"
hint="Archiving keeps a note without keeping it in your way."
/>
);
}
return (
<NoteColumns>
{archived.map((note) => (
<NoteCard
key={note.id}
note={note}
actions={{
unarchive: () => actions.unarchive(note),
trash: () => actions.trash(note),
}}
/>
))}
</NoteColumns>
);
}

Create apps/web/app/(app)/trash/page.tsx:

"use client";
import { Trash2 } from "lucide-react";
import { useKeepViews, useNoteActions } from "@/hooks/use-keep";
import { useKeepSearch } from "@/components/keep/search-context";
import { NoteCard, NoteColumns, EmptyState } from "@/components/keep/note-card";
export default function TrashPage() {
const search = useKeepSearch();
const { trashed, isLoading } = useKeepViews(search);
const actions = useNoteActions();
if (!isLoading && trashed.length === 0) {
return (
<EmptyState
icon={Trash2}
title="No notes in the trash"
hint="Notes you delete wait here until you empty it."
/>
);
}
return (
<div className="space-y-5">
<p className="px-1 text-sm text-text-secondary">
Notes in the trash can be restored. Deleting one here is permanent.
</p>
<NoteColumns>
{trashed.map((note) => (
<NoteCard
key={note.id}
note={note}
actions={{
restore: () => actions.restore(note),
deleteForever: () => {
if (confirm("Delete this note for ever?")) actions.deleteForever(note);
},
}}
/>
))}
</NoteColumns>
</div>
);
}

The Trash view with one note in it, and a line saying notes in the trash can be restored while deleting one here is permanentThe Trash view with one note in it, and a line saying notes in the trash can be restored while deleting one here is permanent

Checkpoint. All five rail links work. Archive a note and it leaves Notes and appears in Archive. Trash it from there and it appears in Trash, where Restore brings it back to Notes. Set a reminder from a note's bell and it turns up in Reminders with a date chip.

That is the product finished. Eight files, about 850 lines, written against an API, a type, five hooks and a descriptor you did not write.

Step 10: Stripe, in full, with the keys

The old version of this post waved at this step, and it was the thing people got stuck on. Here is all of it.

You need Grit 3.593.0 or newer for this. Earlier versions had a bug where a subscription paid for without a webhook never got recorded, so the billing page told somebody who had just paid that they were not subscribed. grit update if grit version says less.

Where the keys go

All four go in the project's root .env. Not apps/web/.env.local, not apps/api/.env. One file. The API finds it by walking up the tree, and each frontend's next.config.ts hoists it into process.env before the build, which is what makes a NEXT_PUBLIC_ value there reach the browser bundle.

The Stripe install already put the four lines in that file, empty, each under a comment saying what it is. Open .env and you will find them. Fill them in:

# Stripe's test keys: dashboard.stripe.com/test/apikeys
STRIPE_SECRET_KEY=sk_test_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
# The plan the billing page sells: dashboard.stripe.com/test/products
NEXT_PUBLIC_STRIPE_PRICE_ID=price_...
# Optional, and genuinely optional. See below.
# STRIPE_WEBHOOK_SECRET=whsec_...

To get them:

  1. Sign in at dashboard.stripe.com and make sure the Test mode toggle is on. Everything below is test mode; no real card is ever charged.
  2. Developers, API keys. Copy the secret key into STRIPE_SECRET_KEY and the publishable key into NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY. They are a pair: sk_test_ and pk_test_.
  3. Products, Add product. Give it a name, set a recurring monthly price, save. Click the price and copy its id, which starts price_, into NEXT_PUBLIC_STRIPE_PRICE_ID.

Restart grit start after editing .env, because NEXT_PUBLIC_ values are compiled into the frontend at build time.

Without a secret key, the payment routes answer PAYMENTS_UNAVAILABLE rather than failing somewhere less obvious. Without the price id, the billing page says so rather than offering a button that cannot work:

The billing screen: You are not subscribed, and a line explaining that no plan is configured yet and to set NEXT_PUBLIC_STRIPE_PRICE_IDThe billing screen: You are not subscribed, and a line explaining that no plan is configured yet and to set NEXT_PUBLIC_STRIPE_PRICE_ID

Webhooks are optional, and that is supported

Two keys are enough. You do not need stripe listen, you do not need a public URL, you do not need a tunnel. This is a supported way to run the plugin rather than a degraded one. The only difference is where the app learns what happened.

Without STRIPE_WEBHOOK_SECRETWith it
The page Stripe returns the customer to reads the result back with the secret key and records it. For a subscription that is useSettleCheckout() on the billing page, calling POST /subscriptions/refresh?session_id=.... For a one-off payment it is POST /payments/:id/refreshThe event arrives the moment it happens, with no page open
A subscription is re-read at the one moment it can change on its own: the end of the period Stripe last named. Before that nothing can have happened; after it, the renewal, the failed card or a cancellation made in Stripe's portal hasNone of that reading happens. The events are the better answer, so the row is never stale

So: skip the webhook secret while you are building, and set it before you take real money, because a deployment has somewhere for Stripe to send events and an event is always sooner than the next page load.

Either way, Stripe's word is what marks a payment paid, never the browser's. The redirect back to your site proves nothing, and nothing in the frontend is trusted to say a subscription is active.

When you do want webhooks locally, install the Stripe CLI and run:

stripe listen --forward-to localhost:8080/webhooks/stripe

It prints a whsec_.... Put that in STRIPE_WEBHOOK_SECRET and restart. Note the path: /webhooks/stripe, not under /api.

Take a payment

Go to /billing and press Subscribe. You land on Stripe's hosted checkout. Pay with Stripe's test card:

FieldValue
Card number4242 4242 4242 4242
Expiryany future date
CVCany three digits
Postcodeany

Stripe sends you back to /billing?session_id=cs_test_.... The page says "Confirming your payment with Stripe" for a moment, and then shows the plan, whether it is paid up, when it renews, and Cancel and Manage billing.

That moment is the whole of what v3.593.0 fixed. The hook reads the checkout session back with your secret key, writes the answer into the subscription query, and takes the session id out of the URL so a reload does not ask twice. On a page of your own, named in success_path, you call useSettleCheckout() there.

What the billing page deliberately does not have

An invoice table. Stripe's billing portal already lists every invoice, lets a customer download a PDF and lets them change the card, and it is the one place where that is always right. A second copy in your app is a copy that drifts. "Manage billing" opens it.

Billing belongs to the organisation

One detail that matters more than it looks: with the multitenant plugin installed, the organisation holds the plan, not the person. One Stripe customer per workspace. The plan survives whoever subscribed leaving, and another admin can change the card. Without the plugin nothing changes, because the organisation id is simply never set.

Checkpoint. /billing shows an active plan with a renewal date. In the Stripe dashboard, Customers shows one customer and one subscription.

Step 11: invite somebody

Go to /organization. Enter an email, pick a role, send.

The invitation is a row and a link, and the link arrives by email. We have not configured a mail provider, and in development that is fine: with no MAIL_MAILER and no RESEND_API_KEY, the mailer tries Mailhog over SMTP and falls back to writing the whole email to the log, so the accept link is in the API output in your terminal. Look for /invitations/accept?token=.

(That fallback matters more than it sounds. The invitation is revoked if the email cannot be sent, deliberately, so that nobody is left with a pending invite whose link never arrived. Without the log driver, an unconfigured project could not invite anybody at all.)

Open the link in a private window, register the second account, and it joins your organisation. Sign in as them and /notes shows your notes, because that is what --tenant-owned means.

Then try the thing worth trying: register a third account from /register, make it a new organisation, and look at /notes. Empty. Same endpoint, same query, no notes, because the scope is on the session and not in the page.

What Grit did and did not do

Grit wrote the Go model, the migration, the service, the handler, five API routes with organisation scoping, the Zod schemas, the TypeScript types, five React Query hooks, the portal descriptor, the whole admin screen for both resources, the customer-facing Labels screens, sign in, register, forgot password, the session handling, the account pages, organisations with memberships and invitations and roles, and billing.

You wrote the note grid, the compose box, the pinning, the reminder chips, the archive and trash flows, the four views and the rail. About 850 lines of TSX across eight files that nobody could have generated for you.

That is the split I want from a framework, and the three --portal levels exist to let you choose it per resource. Labels got screens and cost nothing. Notes got headless and cost an evening. Billing, members and invitations cost a flag.

If something went wrong

SymptomCause
400 on every /api/v1/notes requestNo organisation. Create one at /organization
/notes is a 404Step 8's file is not at apps/web/app/(app)/notes/page.tsx. The (app) brackets are part of the path
Cannot find module '@/hooks/use-keep'Step 6's file is at apps/web/hooks/use-keep.ts, not under app/
Cannot find module '@repo/shared/types'Run pnpm install at the project root
The colour picker is emptyThe --fields string was not quoted, so the shell ate the | and the select has one option
remind_at does not exist on Notegrit migrate after grit generate field
PAYMENTS_UNAVAILABLESTRIPE_SECRET_KEY is empty in the root .env
The billing page says no plan is configuredNEXT_PUBLIC_STRIPE_PRICE_ID is empty, or you did not restart after editing .env
You paid and it still says not subscribedGrit older than 3.593.0. grit update, then grit plugin update stripe
An edit answers 409Something else changed the row. Refetch and try again; that is optimistic locking working

Where to go next

Generate a resource of your own with --owned-by user, and look at /your-resource in the web app rather than only in the admin. If the screen that comes out is the one you wanted, keep it. If it is not, regenerate with --portal headless and write the one you wanted, with the data layer already there.

The reference for all of it is the customer portal, the Stripe plugin is documented at plugins/stripe, and every environment variable in the table above is explained at reference/environment.

JB, Creator of Grit
Written & published by
JB, Creator of Grit

Founder of Grit and author of The Daily Grit. A 5-minute morning read on building full-stack apps with Go + React.

Subscribe

Build it with Grit

Go + React, batteries included. Scaffold a production-ready app in one command.

Get started