Backend/Data model

Data model

Every main record in Accordee, how they connect, and where each one lives today. Use it as the starting point for your own database.

The records

Field names are the ones in the code, in the types under src/lib/data. Customers use number IDs; everything else uses short text IDs such as CT-1013 for a contract or LD-1001 for a lead.

RecordWhat it isKey fields
WorkspaceYour customer's company account and its settingsname, slug, currency, paymentTerms, renewalWindow; settings for pipeline stages, tags, custom fields and agents sit alongside it
MembersPeople on the team who sign inname, email, role (owner, admin, member, guest), title, status (active, invited)
CustomersCompanies you work withname, location, founder, employees, website, tags, rating, owner; the profile adds legal, email, about and logo
ContactsPeople at a customercustomerId, name, role, email, phone, primary
People (Network)Everyone you work with, with how strong the relationship is. Worked out, not storedBuilt from contacts, lead contacts, contract signers and email. strength (strong, good, weak, cold) comes from meetings, emails, messages, notes and tasks in the last 90 days
LeadsA new company, or more business from a customerkind (new, upsell), customerId, contractId once won, stage, valueUsd, plan, seats, expectedClose, source, owner, its own contacts and a stage history
ContractsWhat a customer boughtcustomerId, plan (or a custom plan with its own price per seat), seats, valueUsd, billing (monthly, quarterly, annual), startDate, endDate, termMonths, autoRenew, status, owner, signerContactId
InvoicesBills for a contractcontractId, customerId, issueDate, dueDate, amountUsd, status (paid, open, overdue), paidDate. Invoices written in the editor add line items, tax, discount, currency and layout
TransactionsMoney in or out, always for an invoiceinvoiceId, contractId, customerId, type (payment, refund), status, method, brand, amountUsd
BalancesWhat each customer owes, by age. Worked out from invoices, not storedoutstanding, overdue, age buckets and the unpaid invoices
Documents and filesCompany documents, and files sent in messages and emailsDocuments: name, summary, customerId, uploadedBy, uploadedAt, size. Files: name, kind, size. Only these details are kept today, not the file itself
EmailsThreads from the connected mailboxsubject, folder, customerId, contactId, messages (from, to, cc, body, files); plus suggested contacts and companies found in email
MessagesConversations with customer contactscustomerId, contactId, subject, about (a contract or invoice), participants, teammates, messages with files, readUpTo, muted, closed
InboxNotifications for the signed-in personkind, category, title, body, at, and the records it's about. Today they're worked out from recent records
MeetingsCalls with a customer or a leadcustomerId or leadId, contactIds, team, date, start, minutes, app, agent, agenda
TasksTo-dos on one recordtitle, record (a customer, contract, invoice or lead), customerId, owner, dueDate, done
NotesWritten by your team or by an AI agentcustomerId or leadId, author, title, body, source (user, ai), links to a meeting, contract, transaction, message thread, task, app or workflow
WhiteboardsBoards for planning with a customername, customerId, contractId, templateId, owner, and the board's objects and connectors. Record cards on a board point to a customer, contact, contract or task
Workflows and runsAutomations that act across recordstrigger, schedule, conditions, actions, instructions, owner, and each run's time, source and results
Agents and chatsAI agents and conversations with themAgents: model, tone, instructions, access, skills, apps. Chats: a title and messages

How they connect

ownssignswonWorkspaceMembersWorkflows + runsAgents + chatsLeadsContactsPeople (Network)DocumentsWhiteboardsCustomersContractsInvoicesTransactionsBalancesMessagesEmailsMeetingsNotesTasks
Lines point from a record to the records that belong to it. Dashed boxes are worked out from other records, not stored. Workflows and agents work across all records.
FromToHow
WorkspaceMembersOne to many
MembersCustomers, leads, contracts, tasks, workflows, whiteboardsThe owner field
CustomerContacts, contracts, documentsOne to many, by customerId
CustomerLeadsAn upsell belongs to a customer; a won lead points to the customer it became
LeadContractA won lead points to its draft contract (contractId)
ContractContactThe signer (signerContactId)
ContractInvoicesOne to many
InvoiceTransactionsOne to many: payments and refunds
CustomerMessages, emails, meetings, notes, tasksBy customerId; messages and emails also name a contact, meetings list contacts
LeadMeetings, notes, tasksBefore a lead is a customer, by leadId
Message threadContract or invoiceWhat the conversation is about (about)
TaskCustomer, contract, invoice or leadExactly one (record)
NoteMeeting, contract, transaction, thread, task, app or workflowAny number (links)
WhiteboardCustomer, contractOptional links; record cards point to customers, contacts, contracts and tasks
Person (Network)Customers, contracts, leadsWorked out from contacts, lead contacts, signers and email
WorkflowRunsOne to many

Where they live today

Sample records live in src/lib/data. Each module's provider in src/components/providers starts from them and keeps changes in memory. To go live, a provider loads its records from your backend and sends its changes there; the screens stay as they are. Database shows how, one module at a time.

RecordsSample dataProvider
Workspace, members, settings, agent setupadmin.tsAdminProvider
Customers and contactscustomers.ts, records.tsCustomersProvider
People (Network)network.tsNetworkProvider
Leadsleads.tsLeadsProvider
Contractsrecords.tsContractsProvider
Invoices, transactions, balancesrecords.ts, billing.ts, invoice-docs.tsInvoicesProvider
Documentsdocuments.tsDocumentsProvider
Emailsemails.tsEmailsProvider
Messages, notes, taskscomms.tsCommsProvider
InboxWorked out from recordsInboxProvider
Meetings and meeting notesmeetings.tsMeetingsProvider
Whiteboardswhiteboards.tsWhiteboardsProvider
Workflows and runsworkflows.tsWorkflowsProvider
Agents and chatsagents.ts, admin.tsChatProvider

Before you design tables

  • Owners and authors are names today. Fields like owner, author and uploadedBy hold a member's name. In a database, store the member's ID.
  • Prospects have no customer yet. Notes, meetings and tasks on a lead that isn't a customer use customerId: -1 and a leadId. In a database, make the customer optional and move them across when the lead is won.
  • Some things are worked out, not stored. Network people and their strength, customer balances, invoice lists and dashboard numbers are calculated from other records. Store the records; calculate these, or use database views.
  • Runs and stage changes are lists inside a record. Workflow runs and a lead's stage history live inside the workflow and the lead. Give them their own tables.
  • One workspace in the demo. The demo keeps a single workspace in the browser. A real product usually has many, so add a workspace to every record.

Suggested tables

An outline for Postgres: table names, main columns and links (→). Columns marked + aren't in the demo; a real backend needs them. Adjust it to your product, then follow Database to create the tables and switch one module at a time.

Table outline
workspaces       id, name, slug, currency, payment_terms, renewal_window
members          id, workspace_id → workspaces +, name, email, role, title, status
customers        id, workspace_id +, name, location, founder, employees, website,
                 tags, rating, owner_id → members, legal_name, email, about, logo_path +
contacts         id, customer_id → customers, name, role, email, phone, is_primary
leads            id, workspace_id +, kind, name, domain, location, customer_id → customers,
                 contract_id → contracts, stage, probability, value_usd, plan, seats,
                 expected_close, source, owner_id → members, lost_reason, created_at,
                 last_activity_at, closed_at
lead_contacts    id, lead_id → leads, name, role, email, phone, is_primary
lead_stages      lead_id → leads, stage, changed_by → members, changed_at
contracts        id, customer_id → customers, title, plan, custom_plan_name,
                 custom_price_per_seat, seats, value_usd, billing, start_date, end_date,
                 term_months, auto_renew, status, owner_id → members,
                 signer_contact_id → contacts
invoices         id, contract_id → contracts, customer_id → customers, issue_date,
                 due_date, amount_usd, status, paid_date
invoice_drafts   id, contract_id → contracts, customer_id → customers, status, number,
                 title, issue_date, due_days, currency, lines, discount, tax, notes,
                 payment, style, updated_at
transactions     id, invoice_id → invoices, contract_id → contracts,
                 customer_id → customers, date, type, status, method, brand, last4,
                 amount_usd
documents        id, customer_id → customers, name, summary, uploaded_by → members,
                 uploaded_at, size, storage_path +
threads          id, customer_id → customers, contact_id → contacts, subject,
                 about_type, about_id, muted, closed
thread_messages  id, thread_id → threads, from_side, author, body, at
thread_people    thread_id → threads, contact_id → contacts or member_id → members
email_threads    id, customer_id → customers, contact_id → contacts, subject, folder,
                 starred, unread
email_messages   id, email_thread_id → email_threads, from, to, cc, body, at
files            id, thread_message_id or email_message_id, name, kind, size,
                 storage_path +
meetings         id, customer_id → customers, lead_id → leads, title, date, start,
                 minutes, app, agent, help, agenda
meeting_people   meeting_id → meetings, contact_id → contacts or member_id → members
tasks            id, title, record_type, record_id, customer_id → customers,
                 owner_id → members, due_date, done, created_at
notes            id, customer_id → customers, lead_id → leads, author_id → members,
                 title, body, source, created_at
note_links       note_id → notes, type, record_id
whiteboards      id, name, customer_id → customers, contract_id → contracts,
                 template_id, owner_id → members, content, created_at, updated_at
workflows        id, workspace_id +, name, description, enabled, owner_id → members,
                 trigger, schedule, conditions, actions, instructions
workflow_runs    id, workflow_id → workflows, at, source, matched, results
notifications    id, member_id → members +, kind, category, title, body, href,
                 records, created_at, read_at +
agents           id, workspace_id +, name, model, tone, instructions, access, skills,
                 context, apps, enabled
chats            id, member_id → members +, title, created_at
chat_messages    id, chat_id → chats, role, text, created_at

Lists such as tags, lines, conditions and a board's content can start as JSON columns. Split them into tables when you need to search or report on them.