RelateIQ.
A platform where members of an organization record the client relationships of the organization and take a weighted questionnaire. It gives scores, a test history and an action plan that an admin reviews. The hard parts were weights that depend on who is asking, a questionnaire per organization and a permission table for rows.
- Year
- 2024
- Built for a client
- My part
- Lead developer
- Website
- dev-relate-iq.vercel.app
My role
I led 1 other developer. I did the estimate and the architecture, ran the calls with the client, built the platform from the client's Figma design and supported it after release. The other developer built a few features.
Capabilities
Members
- Dashboard of client relationships with add, edit, delete, retake-test and test-history dialogs, and an onboarding dialog
- Sectioned questionnaire with 0 to 10 ratings that can be saved half done, with a leave-page guard and a progress bar
- Weighted scoring by job title and personal style, with a score per section and a colored total
- Relationship page with last scores, a bar chart of scores per test, the test history and a printable action plan
Admins and organizations
- Users list with pending invites, revoke invite, user editing and activate or deactivate for users, relationships and tests
- Action-plan review in a Markdown editor, with an optional notification email to the user
- Super admin pages to create organizations with a logo and an uploaded question set, and to see averages and relationships
- Bulk import of relationships and tests from JSON, validated in the browser and written in one transaction
Platform
- Magic-link sign-in with Clerk, organization-only access, an invite token table and a table of 48 role, resource and action permissions
- Question sets with 200+ weights, 20+ questions and 10+ job titles stored as JSON, one set per organization
- Branded emails built with React Email and sent through Resend after a verified Clerk webhook
- Help page with an FAQ and a feedback form, PostHog analytics behind a proxy path, 10+ pages, 20+ server actions and 30+ UI components
Patterns and decisions
- Relationship and test rows carry a user and an organization, so each read and write is scoped to a tenant. Prisma holds 4 models and 25+ migrations. Soft delete uses a deactivated-at column. Members do not see deactivated rows, and admins do.
- Test answers, question sets and weights are stored as JSON and checked with Zod. A test set can change without a migration. A rating is an optional integer from 0 to 10, so a test can be saved half done.
- Mutations go through next-safe-action. Three clients stack by privilege: public, signed in, admin. Each action has a Zod input schema, and Prisma errors become readable messages. There are 20+ actions.
- Access has three layers. Route middleware checks the role. The action client checks the privilege. A permission table checks each row.
- Each route has a server-only data layer that wraps the Next.js data cache and uses cache tags that the writes revalidate. Search and step state live in the URL through nuqs.
- Clerk email webhooks are verified with Svix signatures. The app then sends its own branded mail through Resend instead of the default Clerk mail.
- PostHog traffic goes through a rewrite on the app domain. Server events carry the user and relationship properties from the Clerk metadata.
- Env is checked with T3 Env, and React Compiler is on. The 10 Markdown files of docs are written for the next developer: one per integration, plus the import format.
Cases
Scores that depend on who is asking. The same answers had to weigh differently by the seniority of the user, the personal style of the user and the personal style of the client. A test set stores a weights matrix keyed by job title, user style, section and client style. The default set holds 200+ weights for 10+ job titles, and the four section weights of every combination add up to 100. A section score is the average of the rated answers, and blank answers are skipped. The total is the sum of section scores times weight divided by 100, rounded to one decimal. A missing weight throws an error and never counts as zero. A senior partner who leans personal, rating a client who leans analytical, puts 22.5 on "Knowing your client". An associate in the same pairing puts 37.5. One function feeds the dashboard cards, the relationship page, the test review and the organization averages.
A questionnaire for each organization, no deploy. Each organization needed its own questions, job titles and weights. A test set row holds the questions and weights as JSON and the job titles as a text array. The organization points to its row through Clerk metadata. A super admin creates an organization in two steps: name and logo, then a pick of an existing set or an upload of a JSON set. The browser checks the upload: every weight key must be a listed job title and every weighted section must exist in the questions. The set row and the Clerk organization are created in one transaction. Each new relationship and test copies the current set id, so an old test keeps the questions it was taken with. The form schema is built from the set at runtime.
One permission table. Route middleware already separates members, admins and super admins. That was not enough. A member must reach only owned rows, and an admin only the rows of the admin's organization. I wrote one table: 3 roles, 4 resources and 4 actions, which makes 48 cells. 30 are plain true, 9 are false and 9 are predicate functions. A member can create relationships and tests, and can view, update or delete only rows owned by that user. An admin has full access to relationships, tests and users, and may view and update only the home organization. Actions and loaders that touch a row check the table with the row owner before they read or write. The table is typed so that a missing resource or action does not compile. An unknown role, a missing organization or a predicate with no data returns false.