Skip to content
codemancersPublic

About

One stop shop for sales

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Zuko

A multi-tenant CRM backend and web app: runtime-defined objects and fields, links between records that hold one record or many, role and team based record access, a full audit trail, and an MCP server so AI clients can work with the same data under the user's own permissions.

Getting started

cp .env.example .env            # set DATABASE_URL, BETTER_AUTH_SECRET, BACKEND_URL, FRONTEND_URL
createdb zuko && pnpm install
(cd apps/backend && npx prisma migrate deploy)
npx nx serve @zuko/backend      # http://localhost:3000
npx nx dev @zuko/app            # http://localhost:4200

See docs/data-model.md for the tests, including the database one.

AI development tooling

The repository includes 13 skills for Codex and Claude Code, selected for Zuko's stack and recurring development work:

Area Skills
React and Next.js vercel-react-best-practices, vercel-composition-patterns
Backend nestjs-best-practices
Authentication better-auth-best-practices, better-auth-security-best-practices, email-and-password-best-practices, organization-best-practices
Agent harness eve
Interactive UI verification agent-browser
Nx nx-workspace, nx-generate, nx-run-tasks, link-workspace-packages

Skills live in .agents/skills/; .claude/skills/ links to the same files. skills-lock.json pins their source commits and hashes. Select a skill by name, or let the agent select one for the task. Use the existing TypeScript Playwright suite in apps/app-e2e for repeatable browser tests.

Install or update only the selected skills:

npx skills add vercel-labs/agent-skills --skill vercel-react-best-practices vercel-composition-patterns -a codex claude-code -y
npx skills add kadajett/agent-nestjs-skills --skill nestjs-best-practices -a codex claude-code -y
npx skills add better-auth/skills --skill better-auth-best-practices better-auth-security-best-practices email-and-password-best-practices organization-best-practices -a codex claude-code -y
npx skills add vercel/eve --skill eve -a codex claude-code -y
npx skills add vercel-labs/agent-browser --skill agent-browser -a codex claude-code -y
npx skills add nrwl/nx-ai-agents-config --skill nx-workspace nx-generate nx-run-tasks link-workspace-packages -a codex claude-code -y
npx skills update -p -y

Review upstream changes and the lockfile before committing updates. Personal style and discovery skills, auth scaffolding, 2FA, duplicate browser-testing guidance, and Nx Cloud/import/plugin-discovery workflows are excluded. Add one only when a project task needs it. Personal skills can be installed separately at user scope.

Nx MCP is configured directly in .codex/config.toml and .mcp.json. Both launch npx nx mcp from this workspace. Claude Code uses the selected skill links without the broad Nx plugin. Merge any machine-local MCP servers into .mcp.json before checking out this setup. Avoid nx configure-ai-agents here: it restores the full bundle. Restart agents after changing MCP configuration; Claude Code asks you to approve this project MCP server on first use.

Caveman progress (2026-11-25): the initial CLI evaluation analyzed four local Zuko Codex sessions and produced estimates, with no measured token savings. Caveman voice is excluded from the curated project skills; output compression remains an optional personal experiment. Keep local reports under ignored tmp/caveman/.


✨ Your new, shiny Nx workspace is ready ✨.

Learn more about this workspace setup and its capabilities or run npx nx graph to visually explore what was created. Now, let's get you up to speed!

Run tasks

To run the dev server for your app, use:

npx nx serve backend

To create a production bundle:

npx nx build backend

To see all available targets to run for a project, run:

npx nx show project backend

These targets are either inferred automatically or defined in the project.json or package.json files.

More about running tasks in the docs »

Add new projects

While you could add new projects to your workspace manually, you might want to leverage Nx plugins and their code generation feature.

Use the plugin's generator to create new projects.

To generate a new application, use:

npx nx g @nx/node:app demo

To generate a new library, use:

npx nx g @nx/node:lib mylib

You can use npx nx list to get a list of installed plugins. Then, run npx nx list <plugin-name> to learn about more specific capabilities of a particular plugin. Alternatively, install Nx Console to browse plugins and generators in your IDE.

Learn more about Nx plugins » | Browse the plugin registry »

Set up CI!

Step 1

To connect to Nx Cloud, run the following command:

npx nx connect

Connecting to Nx Cloud ensures a fast and scalable CI pipeline. It includes features such as:

Step 2

Use the following command to configure a CI workflow for your workspace:

npx nx g ci-workflow

Learn more about Nx on CI

Install Nx Console

Nx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ.

Install Nx Console »

Useful links

Learn more:

And join the Nx community:

Workflow runtime

The backend uses the official @workflow/nest module with @workflow/world-postgres. Before starting it, bootstrap the SDK storage with the same environment:

node --env-file-if-exists=.env node_modules/@workflow/world-postgres/bin/setup.js
pnpm nx build @zuko/backend
pnpm nx serve @zuko/backend

WORKFLOW_POSTGRES_URL defaults to DATABASE_URL. SDK-owned tables live in the workflow and graphile_worker schemas. Use a dedicated store per environment, or distinct WORKFLOW_QUEUE_NAMESPACE values when sharing one.

Author workflows under apps/backend/src/workflows/; Nx discovers and bundles this directory automatically. Rebuild and restart the backend after changes. The runtime registers private in-process delivery before starting workers and rejects public HTTP access to the SDK execution routes. Nest owns worker startup and shutdown. Organization setup uses this runtime as described below.

Set WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS=30 consistently across replicas and size WORKFLOW_POSTGRES_WORKER_CONCURRENCY for the database pool. Persist the SDK store across restarts. Runtime dependencies are packaged by nx prune for Docker. Keep SDK package versions coordinated when upgrading.

Use the SDK admin UI to inspect runs, with workers disabled in the admin process:

WORKFLOW_POSTGRES_SKIP_WORKERS=1 node --env-file-if-exists=.env node_modules/workflow/bin/run.js web --backend @workflow/world-postgres --webPort 4400

Organization setup

Better Auth creates the organization, then attaches a separate durable setup workflow. It provisions Contacts, Companies, Deals, fields, and relationships. The setup screen shows the organization name and streams a checklist timeline through Next.js; completion stays visible until the user chooses Go to dashboard. Other pages reuse a cached readiness snapshot checked when selecting an organization; incomplete setup shows a banner rather than replacing unrelated page content. Chat waits for readiness.

Apply the Prisma migrations before starting the backend. They add tenant-scoped setup state and queue existing organizations. A reconciler attaches runs to organizations missing a run reference after crashes. CRM HTTP, MCP, and Eve access wait for readiness; visiting a records page never creates schema.

Provisioning preserves existing standard objects and customizations. A custom object occupying a required CRM key fails the transaction without overwriting it. Transient provisioning errors receive five SDK retries with capped exponential backoff. Resolve permanent conflicts before using the SDK admin UI to re-run setup. Re-runs create a new SDK run for the same organization and update its server-owned setupRunId; refresh the setup page to follow that new run.

The authenticated Next.js route /api/organizations/:id/setup checks organization membership through Better Auth and reads that run's persisted stream without polling. Next.js needs the same workflow store as Nest and starts no workers. There is no status polling or application retry API. Eve's local development world remains separate.

Add future repeat-safe setup steps to apps/backend/src/workflows/organization-setup.ts before markReady. Earlier committed steps survive a later failure; organization creation is outside the workflow. Persist the SDK store and follow SDK versioning guidance when deploying changed workflow definitions with unfinished runs.

Files

Files attach to records through file fields, to comments, and to chat messages. Bytes go in as a streamed multipart upload (POST /api/v1/files), never inline in JSON, a message or a tool argument; everything after that refers to a file by id. A file is capped at 25 MB, its type is decided from its own bytes (a plain image or PDF opens in the browser, anything else downloads), and its metadata lives in Postgres under tenant row-level security.

The bytes live on local disk in FILES_DIR, an absolute path (default storage/files, gitignored). Persist that directory across restarts and deploys, for example with a volume; files outside it are lost with the container. Storage sits behind the FileStorage interface in apps/backend/src/files, so an S3 driver is a swap, not a rewrite. Nothing yet removes the bytes of deleted files or of deleted organizations.

A file has no access list of its own. It is readable by its uploader and by anyone who can read a live record or comment it is attached to, so attaching a file shares it with that record's readers. Only roles that can create or change records, or comment, may upload. MCP clients use the same scopes as the records and comments they touch: records:read to list and open files, records:write to upload and attach, comments:write to attach to a comment.

A client that cannot carry the user's token, such as Claude Code, uploads out of band. Call the request_file_upload tool for a signed link (one use, five minutes, bound to that user), then curl -F 'file=@sheet.xlsx' '<link>'; the reply holds the file's id, which get_file, update_record, add_comment and the agent (for example "open file 7") take. The link is a secret: use it at once.

The agent runs its bash, read_file, write_file and edit_file tools in a Docker container per session with no network (apps/harness/agent/sandbox). Docker must be running to build or run the harness (eve build prepares the container image). Files a person attaches to chat are staged there for the agent to read, and the agent can publish a file it made with save_file.

Frontend access

Next.js pages and API routes require a valid Better Auth session by default through apps/app/src/proxy.ts. Anonymous page requests redirect to login with their return path; API requests return 401. Cookie presence alone is not trusted. Backend session validation failures return 503 rather than allowing access.

The explicit public allowlist contains login, signup, consent and invitation landing pages, and application icons. Next.js static/image/HMR assets bypass the proxy. Eve's /eve/v1/ protocol routes retain their own bearer-token/callback authentication. Membership and permissions are still enforced by the backend.

While a setup run is not attached yet, the setup page stays pending and EventSource reconnects until reconciliation attaches it. Failed setup refreshes replay the SDK's persisted failure event, retaining the failed step and completed earlier steps.

About

One stop shop for sales

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages