Field report: a multitenant business suite built on Grit in ten days, and ten proposals to make feature work faster

Open
#179 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
go, next.js, postgresql, typescript

Research direction

Read the ten ranked proposals and the referenced implementation details, including module_guard.go, catalog.go, orgsecrets, and doc_templates.go, to understand the reported gaps. The issue proposes multiple independent changes across Grit’s routes, multitenancy, PDF, jobs, forms, mail, MCP, tests, and hooks, without selecting one task or naming target files and tests. A first contribution needs a single proposal with agreed scope and clear completion criteria.

Written by the indexing model from the issue text.

Description

What was built

Outpost is a multitenant business suite for small companies, built on Grit (triple, Next.js, multitenant plugin, Expo and desktop added) from 2026-10-27 to 2026-11-05: 105 commits, about 200 service files.

It has CRM, projects and time, quotes, invoices and online payments, expenses, payroll with Uganda's tax rules, a document center with expiry reminders, an email client, marketing forms, audiences and campaigns, social media tracking, a client portal, a password vault, API keys and webhooks, encrypted backups, and an assistant with an MCP server.

This is what building it taught us: what Grit made fast, what slowed us down, and ten proposals ranked by the time they would have saved.

What made it fast

  • The first resources were close to free. Contacts, companies, deals, tasks and interactions came from grit generate resource: model, service, handler, routes, Zod, types, hooks and admin, all in one go.
  • The pieces we never had to think about: the multitenant plugin, paginate (after #112, #121, #123), pdf, mail, sequence, workflow, crypto, testkit, sessions, 2FA, SSO, audit.
  • Tools an agent can lean on: grit docs search, grit routes, grit doctor, and the manifest's file ownership. They let an agent work without guessing.
  • Fast fixes. We filed about 45 issues from this project, and most were fixed within a day. All 26 we track in the project are now closed.

What slowed us down

The CRM resources were generated. Everything after them (invoices, payroll, documents, campaigns) went beyond create, read, update and delete, so it was written by hand. Most of the time went into the same few kinds of infrastructure, written once per module. Those are the proposals below.

Ten proposals, ranked by time saved

1. Declare the permission on a hand-written route, and refuse routes that declare none

Generated routes carry their permission. Hand-written ones carry nothing that grit routes can see, so we built a module catalog and a guard with 105 per-route overrides: module_guard.go is 364 lines and catalog.go is 429.

A route that was forgotten fails open.

The proposal is a declaration the route parser can read:

r.POST("/payslips/:id/email", perm("payroll.edit"), h.EmailOne)

Then grit routes (or grit doctor) fails on any route in the protected group that has no permission declared. That turns "somebody forgot" into a build error.

2. Per-tenant secrets in the multitenant plugin

Every workspace brings its own Resend key, payment gateway secret, webhook signing secret and backup bucket. We built orgsecrets, 430 lines:

  • a 32-byte data key per organisation, wrapped by FIELD_ENCRYPTION_KEY;
  • AES-GCM with the organisation id as additional data, so one tenant's ciphertext cannot be swapped into another's row;
  • a hint of the last four characters;
  • never returned by the API after it is saved.

Any multitenant SaaS needs this. The proposal is to ship it in the plugin:

tenant.Secrets(ctx).Put("resend", key)
tenant.Secrets(ctx).Get("resend")

Then mail and webhooks can take a per-tenant credential directly. This relates to #138.

3. A branded business-document layout in pdf

Invoices, receipts, quotes, credit notes, statements, payslips and contracts all share one shape:

  • a letterhead with a light and a dark logo, and the brand colour;
  • a parties block;
  • a table of lines with custom columns;
  • totals, a bank box and notes;
  • a signature;
  • a footer.

We wrote doc_templates.go (954 lines) with eight designs, plus a preview endpoint so settings can show each design before saving.

The proposal is pdf.Document{Brand, Parties, Columns, Lines, Totals, Signature}, with a small registry of layouts and a grit generate document <name> command. Most products built on Grit send at least an invoice.

4. Scheduled jobs that run for every tenant, and notifications that send only once

Our billing sweep (278 lines) does the same thing for each job it runs:

  • loop over the organisations;
  • set the tenant on the context;
  • do the work;
  • send the email at most once, through a dedup row (tellOnce).

It covers recurring invoices, overdue reminders, recurring expenses and the document expiry countdown.

The proposal is two helpers:

  • cron.EveryTenant(spec, fn), which runs fn with the tenant context set for each organisation;
  • notify.Once(ctx, key, fn), backed by a unique index.

Together they would remove most of that file. Getting the dedup wrong means emailing a customer the same reminder every 30 seconds, so it is worth getting right once in Grit.

5. Searchable selects in generated forms

Native <select> with 40 clients or 60 employees is unusable. We wrote a combobox following the WAI-ARIA pattern (407 lines):

  • a search box from 8 options;
  • portalled into dialogs;
  • fixed positioning that stays on screen.

Then we swapped it into 68 files.

The proposal: the form generator emits a combobox for every belongs_to field and for any enum with more than about 7 options, and the component ships in the scaffold.

6. A doctor check for bool with default:true

GORM treats false as the zero value. On Create it leaves the column out, the database fills in true, and GORM writes true back into the struct.

So a form that saves "unticked" stores "ticked", with no error. It bit us twice, on marketing consent and on a "sends email" flag.

The proposal: have grit doctor flag any bool field tagged default:true, and suggest a *bool or no default. The generator should never emit that pair.

7. Marketing mail in mail

campaign.go is 884 lines. Much of it is mechanics any campaign feature needs:

  • the List-Unsubscribe and List-Unsubscribe-Post headers (Gmail and Yahoo require them for bulk senders);
  • a per-recipient token;
  • rewriting links to tracked redirects;
  • an open pixel;
  • sending a few at a time;
  • checking consent again at each recipient's turn.

The proposal is mail.Bulk with those built in. The application would supply only the audience and the content.

8. MCP tools from resources

The assistant and the MCP server needed list, get and create tools per module, and permission checks on each. We wrote a tool catalogue by hand.

The resource generator already knows the fields, the validation and the permission keys. So grit generate resource --mcp, or a grit mcp server that exposes generated resources with the caller's permissions, would make "talk to your data from Claude" a flag.

9. Faster Postgres tests

SQLite in tests now enforces foreign keys, which catches most of what used to fail only on Postgres. The full suite on Postgres still takes about 13 minutes serially, and over 30 when dev servers share the machine.

The proposal is grit test --postgres. It would:

  • start a throwaway container;
  • give each package its own schema;
  • run the packages in parallel.

Postgres-only failures would then turn up in CI instead of being skipped locally because the suite is slow.

10. Generic hooks and one schema source (+1 to #146 and #145)

Every module's web hooks file was close to a copy of the last one. A typed useResourceHooks<T>, with Zod as the single source of a row's shape, would have cut each new module's frontend by a few hundred lines.

Smaller things

  • A secret key leaving the API. We found this class of bug twice (#156, and the API key scopes advisory filed today). A test kit helper that asserts no response body and no redirect URL contains a token would catch the next one.
  • Upgrades on a project that has added Expo or desktop. These cost real time until #125, #133, #134 and #135 were fixed. Running grit upgrade --dry-run in CI on example projects would catch regressions of that kind.

Filed alongside this report

Environment: grit 3.471.0 CLI, project on 3.437.0, triple, multitenant, Windows 11, go1.27.3.

Dominant language
Go
Stars
152
Forks
20
Avg merge
1d 49m
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MUKE-coder/grit

All issues in MUKE-coder/grit

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.