Skip to Content
Build

Architecture

A Next.js app, a worker that alone holds the NEAR keys, Postgres, and NEAR underneath, in one pnpm workspace.

Tegata's parts: the web app, Postgres, the worker that alone holds the operator keys and relays to NEAR, and live quotes from NEAR Intents
The system.

The parts

PartWhat it does
apps/webNext.js 16: the landing page, sign-in, the app, the public invoice, pay and receipt pages, the app's API and the developer API, and /dev (every part of the design in every state)
apps/workerBackground jobs on pg-boss. The only process that holds Tegata's NEAR keys; the web server never does
apps/docsThese docs: Fumadocs, exported to static files
Postgres 17The books: users, businesses, accounts, requests, payments, receipts, invoices, customers, referrals, people, payroll runs, autopilot plans, relays, API keys, events and webhook deliveries, wallet sign-in requests

The worker's jobs

JobWhen
relay-sendEach signed action: send it to NEAR, exactly once. A Tegata-balance payment and a payroll batch settle here
account-setupA new sign-up: create the NEAR account and register it on USDC
payment-verifyA NEAR-wallet payment: read it from NEAR and settle it
test-dollarsA Sandbox grant: send 5 test USDC
invoice-emailAn invoice or reminder email, when email is on
invoice-repeatEvery 10 minutes: issue repeat invoices that are due
referral-sweepEvery 5 minutes, and once at start: qualify invites, pay rewards past their hold
destination-registerA person's NEAR account that can't hold USDC yet: Tegata's operator registers it
payroll-email"Added you to payroll" and "You've been paid", when email is on
autopilot-registerA business turning on autopilot: Tegata's operator pays its storage on the contract
autopilot-keeperEvery minute: call run on the contract for each plan whose payday has come, then record the run from its events
webhook-deliverOne signed webhook to one endpoint; a non-2xx is retried after 30 s, 2 min, 10 min, 1 h and 6 h
webhook-sweepEvery minute: queue any delivery whose retry is due

At start the worker also picks up any relay or payment it left halfway.

Built on

PieceWhat it does in TegataWhere
NEAR named accountsname.tegata.testnet for every business, created with the owner's own keypackages/core/src/near/accounts.ts, operator.ts
Meta transactions (NEP-366)The owner signs; the worker relays and pays the feepackages/core/src/near/delegate.ts, packages/services/src/relays.ts
USDC on NEAR (NEP-141)Every balance and settlement; "paid" is read from its transfer eventpackages/core/src/near/usdc.ts, transfers.ts
NEAR Intents (1Click)Live prices from other chainsapps/web/lib/server/oneclick.ts
NEAR ConnectCustomers pay from their own NEAR wallet; owners can sign in with one (NEP-413) and approve actions as delegate actions it signsapps/web/lib/client/near-wallet.ts, near-account.ts
PrivyEmail sign-in that gives each owner a NEAR keyapps/web/app/providers.tsx
NEP-413Signing in with a NEAR wallet: a signed message with a one-time nonce, checked against the account's full-access keyspackages/core/src/near/wallet.ts, packages/services/src/wallet-auth.ts
react-pdf, react-email, ResendThe invoice PDF, and the invoice and reminder emailspackages/documents
Standard WebhooksSigning every webhook, so a shop can verify it in one callpackages/services/src/developers.ts

The workspace

apps/web            Next.js: landing, sign-in, the app, public pages, API, /dev
apps/worker         background jobs; the only process that holds operator keys
apps/docs           these docs
packages/config     constants: networks, gas, limits, referral rules
packages/core       money, invoice and payroll maths, schedules, the people CSV; NEAR: accounts, USDC, delegate actions, the operator
packages/db         Postgres schema and migrations (Drizzle)
packages/documents  the invoice PDF and the emails
packages/env        the only reader of server environment variables
packages/jobs       queue definitions
packages/services   database-aware logic shared by the web app and the worker

USDC contracts: 3e2210e1184b45b64c8a434c0a7e7b23cc04ea7eb7a6c3c32520d03d4afcb8af on testnet, 17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1 on mainnet.

On this page