The Object Model (Proposal)¶
Status: Agreed (Andrew, 6 November 2026; DEC-109 to DEC-114, answering Q-58 to Q-63). Built, 8 November 2026 (RM-49; plans plans/2026-11-06-audit-log-and-object-model-step-1.md and plans/2026-11-07-object-model-the-rest.md), with DEC-122 to DEC-126. Still to come from this design: the field index (§ 2.2) when a field needs it, masking contacts' names in prompts with Cliniko (§ 3.4), and the field sets published with RM-35 (§ 5). For what's built, the code and the records win.
Applies to: every table people or integrations put work into. It extends the module architecture's object types (module-architecture-proposal.md § 3, DEC-25) and the work model proposal's fields and links (work-model-and-ia-proposal.md § 4 and § 5.3), and replaces the March 2026 type system (archive/old-numbering/32-core-data-structures-tasks-contacts-items-v01.md).
For the docs rewrite (plan docs/plans/2026-11-05-architecture-docs.md): this folds into 04 (the data model) and 08 (the work model).
1. Why now¶
- Tasks carry two half-built designs. March's:
task_typesand a free-formmetadata. October's: custom fields per space, typed links, milestones. Neither is in use: no code setstaskTypeId,task_listsis unread (tech debt D1), andmetadataholds only the Notion import's reference. - Integrations will rely on the shape. They get access later (RM-2, RM-35, RM-41), and the capability registry fixes each capability's input from the object's validators (DEC-89). A shape that changes after outsiders build on it costs them a migration as well as us.
- It's free now. On production (checked 6 November 2026),
contacts,contact_interactions,items,item_types,notes,note_types,tags,entity_tags,task_typesandtask_listshave no rows. All 98 tasks are in a space, have the oldscope"account", and none uses a type, a task list or a source item. - Lists already have a working field system (
lib/fieldDefs.ts): 13 field types, views, filters, sorts and the Notion import's mapping. Using it everywhere costs least and gives people one way of doing things.
2. The design¶
Every work object has a fixed core and is extended in four ways only: fields, links, sources and templates. Nothing else extends an object: no type tables, and no free-form data that people or integrations depend on.
2.1 The core¶
The fields Thinklio's own behaviour depends on: a task's status, assignee and due date; a contact's name and addresses. They're typed in the schema, indexed where queries need them, and their meaning never changes. A core field is added only when Thinklio itself acts on it.
2.2 Fields: one field system¶
- One definition for every object type:
fieldDefinitionfromlib/fieldDefs.ts, with its types, choices, stable IDs and archiving. - Field sets say where fields are defined:
| Object type | Its fields come from |
|---|---|
| List entries | the list (collections.fields, as now) |
| Tasks | the space (each space's task fields) |
| Contacts | the organisation (its contact fields) |
| Any type | an integration's registered fields (§ 5) |
A new table field_sets holds every field set except a list's: the account, the object type, the owner (a space, the organisation or an integration with its version) and the fields, at most 100 as for lists.
- Values live on the object, keyed by field ID, as list entries keep them (values). Tasks and contacts gain an optional values, which adds without a migration.
- The same code serves every type: the field editors, the table's columns, filters, sorts, board grouping, import mapping, history's wording ("changed Budget"), and the validators the capability registry publishes.
- Additions to the definition, each optional, so stored fields never need migrating:
- key: a stable name an integration or template uses for the field in the API (bill_id), beside its ID;
- readOnly: people see it but can't change it (an integration's fields, usually);
- sensitive: masked in model prompts by default (ADR-036's patient names);
- indexed: kept in a field index (below);
- the field types already planned: relation (to any object type, held as links, § 2.3), rollup, formula and file.
- Indexing. Convex can't index inside values, so filtering and sorting by a field happen after an indexed range: a list's entries, a space's tasks. That suits hundreds to a few thousand objects. A field that must be found across many (a Cliniko patient number across 20,000 contacts) is marked indexed, and the write path keeps a field_values row (account, object type, field ID, normalised value, object) with an index on the value. Designed in now; built when the first field needs it.
2.3 Links: one table between any two objects¶
As the work model proposal § 5.3 designed it, for every object type:
- One
linkstable: account, from (type and ID), to (type and ID), kind, the field ID for a relation field's link, who made it (a person, an agent or an integration) and when. Indexed from both ends. - Kinds:
about(this concerns that),blocks(one holds up another),relates_to,duplicates, andfield(the value of a relation field). - Containment isn't a link. A sub-task's task, a task's list entry or project, and a file's place stay the object's own
parentorfile_links, because they drive queries and rollups. - Links cross spaces, and a link never grants access. If you can't see the other end, you see that a linked object exists, and nothing about it.
- Backlinks everywhere: every object shows what links to it ("2 open tasks about this order").
- Writes go through a links write path that records the change on the object it's from, so history and undo work as for any field.
- This is what makes lists relational, and tasks and contacts relational the same way.
2.4 Sources: one table for each object's IDs elsewhere¶
- One
object_sourcestable: account, object (type and ID), the system (notion,cliniko,xero,github,telegram, an integration's name), its external ID, a URL, the mode (mirror, import or link: module architecture § 4.1), when it was last synced, and the source's version where it has one. Indexed by system and external ID, and by object. - It replaces today's scattered references:
metadata.importRefon tasks,importRefoncollections,filesandpages, andsourceRefon contacts and items. - It ends a scan. To match an import's rows,
bundles/apply.tsapplyTasksreads up to 5,000 tasks per status and parses each one'smetadata. A source is one indexed read. - A mirrored object is read-only for its source's fields, and undo is off for the source's changes (module architecture § 3); the marker comes from here.
- An object can have several sources: a contact from both Cliniko and Google, a task from Notion and later Linear.
2.5 Templates and kinds¶
- No per-type type tables. A kind (a request, a bug, a meeting note, a support ticket) is a select field.
- Templates carry the opinion: a space or list template brings its fields, views, task blueprints with dates relative to a field, and rules (work model proposal § 4.4 to § 4.6). An organisation picks templates and rarely builds from scratch.
2.6 What every object type shares¶
Through the object registry (objects/registry.ts), every work object type also gets, without per-type code elsewhere:
- the write path, with a
changesrow in the same transaction, history and undo; - tags (§ 3.7), files (
file_links) and comments (a chat on the object); - search through the content index (RM-38);
- capabilities from the registry (RM-35), checked by the policy engine (RM-36) and recorded in the audit log (RM-34).
The registry today has task, record and page; contact and file join them.
2.7 What metadata is for¶
Tasks, contacts and items carry metadata: v.any() today. It goes from tasks and contacts. Where a table keeps one, it holds only Thinklio's own bookkeeping, which nothing outside reads and no screen shows. People's data goes in fields; an integration's goes in its fields and sources.
3. Each kind of object¶
3.1 Which tables take it¶
| Tables | Take |
|---|---|
| Work objects: tasks, list entries, contacts, docs, files | Links and sources. Fields for tasks, entries and contacts. Docs could take a space's doc fields later. Files keep DEC-87's small record, whose summary and keywords are its fields |
| Communication: chats, messages, notifications | Sources only: a Telegram message ID, an email's Message-ID (DEC-95). Their shape is fixed by how chat works (doc 16) |
| System: organisations, members, teams, spaces, agents, policies, keys, audit, usage, models | None. Their shape is Thinklio's. Settings live in data, but not as fields. A space's owner follows DEC-84 |
3.2 Tasks¶
- Core: title, description (Markdown), status (to do, in progress, in review, done, cancelled), priority, due date and time, assignee, space, parent (a task or a list entry), milestone, recurrence, completed at, created by (a person or an agent).
- The assignee is a person or an agent:
assignedTo(a person) stays andassignedAgentIdjoins it, at most one of them set. The field comes now; assigning to an agent starts a run with RM-40 and RM-30 (work model proposal § 5.4). - A team's queue is the team's space (DEC-84), with its unassigned tasks; tasks have no team assignee.
- Milestones replace
task_lists: amilestonestable (account, space, an optional parent project entry, name, position, an optional due date, archived), andtasks.milestoneIdreplacestasks.listId.task_listsis empty on production, so nothing moves. Projects (RM-27) use them, with progress as a rollup. - Fields: the space's task fields, in the task panel and as the task table's columns, on the web and in the app, with the lists' editors.
- Kinds: a select field, when a space's template wants one.
- Goes:
taskTypeId,scopeandscopeId(a task's access is its space; every production task has "account", and one line reads it, intasksCrud.ts's recurrence),nextOccurrence(D1),sourceItemId(anaboutlink instead),listId(tomilestoneId) andmetadata(to sources; the import'simportAssigneebecomes a typed optional field untilimports:assignImportedhas run). Removing the requiredscopeandscopeIdfrom 98 rows is a widen, migrate, narrow change with the migrations component.
3.3 List entries¶
- Unchanged core: title (the primary field),
values, notes (the entry's Markdown body), position, archived. - Relation fields become
fieldlinks, so an entry can point at another list's entries, tasks, contacts or docs, and rollups can follow them. - Sources:
collections.importRefmoves toobject_sourcesfor the list, and each imported entry gets its own. A repo list'skey(its row ID in the file, such as B53) andsourceLinestay on the entry: they're the entry's identity in its file, not a reference into another system. - The Notion import brought relation and rollup columns in as text ("3 linked"), so those links are lost in Thinklio today (tech debt D12). Once relation fields exist, they're imported again as links, before Notion is cancelled (RM-1).
3.4 Contacts¶
People and organisations outside the organisation's members: clients, suppliers, patients, senders.
- Why a type of its own, not a list: contacts are shared across spaces, matched against email and Telegram senders (RM-42), synced with Cliniko, Google and Xero, linked from tasks, entries and chats, and remembered (RM-39, memory about people outside). A list belongs to one space and can do none of that.
- Core: kind (person or organisation), name, the organisation a person belongs to (another contact), addresses, owner, archived, and the member they became if they join (
userId). - Owner and who sees it, as for spaces (DEC-84): the organisation (every member), a team (its members) or a person (only them). It replaces
visibility,scopeandscopeId. - Addresses (emails, phones, Telegram handles) are rows in
contact_addresses(contact, kind, label, normalised value), indexed by value, so a channel finds the sender in one read. - Fields: the organisation's contact fields and an integration's fields.
- Interactions:
contact_interactionsstays as the contact's timeline (a call, a meeting, an email logged), with its kind as a select. Later a channel's messages with the contact show there too. - Sensitive data: a field marked
sensitive, and the name of a contact whose source is Cliniko, are masked in model prompts by default (ADR-036). - Duplicates: a
duplicateslink, then a merge that keeps both sources. - In use now: a Contacts page for the organisation, a contact's panel, and links to contacts from tasks and entries, on the web and in the app. Integrations follow later (§ 5).
3.5 Items become tasks¶
- Requests, support tickets, bugs and inquiries are tasks with a kind field and an
aboutlink to the contact who asked. A help desk is a space whose template brings the kind, its statuses as a select field if the five aren't enough, and its views. - Approvals are the policy engine's confirm level, in the Inbox, through
pending_approvals(RM-36). - Goes:
itemsanditem_types, both empty on production. The agents' item tools become task tools. (The ingest spec's "items" is a list format, not this table, and is unaffected.)
3.6 Notes become docs, comments or memory¶
- A person's own notes are docs in their personal space.
- A note on a thing is a comment on it (its chat), or a doc with an
aboutlink to it. - What an agent learns is memory (RM-39, DEC-88).
- Goes:
notesandnote_types, both empty on production. The agents' note tools become doc and memory tools. (A list entry's notes, its Markdown body, are a different thing and stay.)
3.7 Tags¶
- They stay, on any work object, as the organisation's set, because "everything tagged Q3" is found across types, which values inside
valuescan't be. entity_tagsbecomesobject_tags(object type and ID), named likelinksandobject_sources; it's empty on production.
3.8 Docs and files¶
- Docs take links and sources (their
importRefmoves). A space's doc fields can come later through a field set, if wanted. - Files keep DEC-87's record. They take sources (a Drive file's ID) and links (a contract
abouta client);file_linkskeeps saying where a file appears.
3.9 The type tables go¶
task_types, item_types and note_types are dropped. Their seeds in coreDataSeed.ts go too; production has no rows in any of them.
4. The stability rules¶
- IDs are never renamed or reused: an object type's name, a core field's name, a field's ID, a link kind, a source's system name.
- Changes only add. A new core field is optional or has a default. A field type, link kind or field option is added, never changed.
- A removal goes through a version. The published schema (§ 5) marks it deprecated in one version and removes it in a later one, never in the same change.
- Every write goes through the type's write path, whoever makes it, so
changes, the audit log and the policy engine see it. - People's and integrations' data live in fields and sources, never in
metadata.
5. Integrations¶
- What they can rely on: each object type's core and its field sets, published from the capability registry in
/metaand the OpenAPI file, versioned like the ingest spec (DEC-89, RM-35). - What they can add: their own field set (with
keys, usually read-only to people, under the integration's name), sources and links. Never a change to a core field's meaning. - How they get in: later, through RM-2's organisation and team keys, each a principal under the policy engine (DEC-93), recorded in the audit log by name. Services in thinklio-services come through the service registry (RM-41).
- Removing an integration archives its field set. Values and sources stay until someone deletes them.
5.1 An integration's own data (DEC-114)¶
An integration never owns work objects of its own. Every task, entry, contact, doc and file has a home people can see: a space, or for contacts an owner (the organisation, a team or a person). Owners stay those three; there's no fourth kind for integrations.
- The work it creates goes where only the right people see it.
- Its tasks and entries go in a space whose owner gives the right audience: a team's space (DEC-84), such as a Clinic space for a Cliniko integration, or a person's personal space.
- Its contacts are owned by that team or person.
- They're ordinary objects, with history, search, links and the shared fields.
- Its key reaches only that place. The integration's key (RM-2, DEC-93) is limited by the policy engine (RM-36) to the spaces and owners it serves, so it can't read or write anything else.
- Work to be checked first is a draft, waiting for a person's review: the policy engine's draft level (DEC-90).
- Its own workings stay out of the work tables. Sync cursors, ID mappings, raw payloads, queues and caches aren't work objects. They live in the integration's own storage:
- a Convex component's tables, isolated from the app's (module architecture § 7);
- or its Go service's database in thinklio-services (DEC-94).
What ties its records to Thinklio's objects is object_sources (§ 2.4), so nothing is hidden inside an object.
- A new kind of thing (invoices, say) starts as a list with the integration's field set. If it becomes central, it becomes an object type of its own, registered like the others (§ 2.6) and living in a space people can see.
- Why there are no hidden objects:
- An organisation's admins can always see, export and delete everything in their organisation. Novansa's account-deletion standard and the audit log (DEC-92) depend on that.
- Links to objects nobody can see would show only that a linked item exists, everywhere.
- A fourth kind of owner would join every access check.
6. The order of work (RM-49)¶
Each step is a plan of its own. Steps 1 to 3 come before RM-35, so the capabilities publish the final shape; they can run alongside RM-34.
- The shared pieces:
field_sets,valueson tasks, the space's task fields in the task panel and table on the web and in the app;linkswith backlinks; relation fields in lists;object_sources, with everyimportRefmoved into it and the importer's scan replaced;object_tags. - Tasks' core: the agent assignee field, milestones in place of task lists, and the old fields removed (a migration for
scopeandscopeId). - Contacts: the new shape,
contact_addresses, the owner, the organisation's contact fields, and a Contacts page and panel, on the web and in the app; links to contacts from tasks and entries. - The retired tables go:
items,item_types,notes,note_types,task_types,task_lists; the agents' tools move to tasks, docs, contacts and memory. - The registry:
contactandfilejointask,recordandpage; field sets published with RM-35.
Then: the Notion relations imported again as links (D12) before the cutover (RM-1); projects (RM-27) on milestones and rollups; integrations through RM-2, RM-35 and RM-41; the field index when the first indexed field needs it.
7. Decisions¶
| ID | Decision |
|---|---|
| DEC-109 | The object model: every work object has a fixed core and is extended only through one field system (the lists' field definitions), one links table, one sources table and templates; kinds are fields; the three type tables go (Q-58) |
| DEC-110 | Contacts are a first-class object type, owned like spaces (the organisation, a team or a person), with the organisation's contact fields (Q-59) |
| DEC-111 | Items become tasks with a kind and an about link to the requester; approvals are the policy engine's confirm (Q-60) |
| DEC-112 | Notes become docs, comments or memory, and the notes table goes (Q-61) |
| DEC-113 | RM-49, the object model, goes in Stage 3 alongside RM-34 and before RM-35 (Q-62) |
| DEC-114 | An integration owns no work objects: what it creates lives in a space or under an owner people can see, its key is limited to those places, work for review is a draft, and its own workings (cursors, mappings, payloads, caches) live in its own storage (Q-63) |