Domain services and contracts
The core package provides shared business rules for Gauzy applications, workers, desktop clients, and plugins. The contracts, configuration, constant, and utility libraries give these callers one common boundary for identity, tenant scope, data shape, runtime settings, and work that continues after a request. See Backend platform, API application lifecycle, Identity and access control, Embedded client access, Account deletion, Plugin architecture, Background jobs and scheduling, and Subscription billing for related systems.
Core domain services
The core service layer owns business actions that must have the same meaning across REST, GraphQL, background work, desktop clients, and plugins. Host applications provide transport and runtime context. Core services apply that context before they read data, change state, or create downstream work.
Capability boundary
The public core surface groups business capabilities behind services, commands, queries, events, entities, and shared kernel services. It covers tenant and organization work, people, projects, tasks, time, finance, integrations, commerce, search, notifications, documents, collaboration, files, approvals, embedded timer access, saved reports, and durable operations.
The entity registry and shared kernel keep one domain shape across host applications. A host can mount a smaller surface, but it must load the module that provides each capability it uses. Core entities and plugin entities are combined before the database connection starts, and name conflicts are refused.
References: packages/…/index.ts• L4-40 packages/…/index.ts• L91-180 packages/…/app.module.ts• L200-220 packages/…/app.module.ts• L580-665 packages/…/index.ts• L225-446 packages/…/internal.ts• L177-215
Context and scope boundary
The request context is the shared view of the active caller and operation. It carries the caller, tenant, selected organization, employee, role, permissions, language, and correlation identity. Core services use this context to scope reads and writes instead of trusting tenant, organization, employee, or ownership identifiers supplied by a caller.
The same rule applies outside HTTP. WebSocket work and other operations can open a fresh context when they need the same identity and scope checks. Isolated work can use a child context so concurrent GraphQL fields or related tasks do not change each other's state. Background work that uses MikroORM must also run inside a short-lived ORM context. This gives each job unit a fresh data view and prevents repository calls from using the global entity manager outside a request. TypeORM and test wiring without a MikroORM instance keep their existing behavior.
Organization access has two levels:
- Tenant administrators can reach all organizations in their tenant.
- Other callers are confined to the organization in their current token and to the permissions granted to them.
- Approved cross-organization actions perform their own checks before they leave the normal boundary.
References: packages/…/request-context.ts• L121-203 packages/…/request-context.ts• L259-485 packages/…/types.ts• L14-48 packages/…/mikro-orm-context.ts• L4-27 packages/…/organization-boundary.ts• L7-108
Authentication and authorization context
Authentication builds a current authorization context from the account and current database state. Token validation checks that the account, role, employee, and organization membership are still valid, so deactivation, role changes, and membership changes can take effect before token expiry.
The access-token boundary also marks narrower sessions. OAuth application tokens keep the scopes approved by the user. Embedded timer tokens keep the credential, member, origin, and optional client or site grant that created them. Guards intersect these grants with the caller's current role permissions, so a token cannot use the wider rights of its member.
The shared boundary also covers registration, invitations, password reset, OAuth clients, personal API tokens, two-factor authentication, and signed-in sessions. A token or OAuth application does not bypass current role, membership, permission, or approved-scope checks. First-party-only actions such as enabling a saved report link or allowing an embedded site reject API-token and third-party application sessions.
References: packages/…/auth.service.ts• L368-581 packages/…/auth.service.ts• L752-784 packages/…/jwt.strategy.ts• L100-147 packages/…/jwt.strategy.ts• L302-452 packages/…/type.token.ts• L11-65 packages/…/permission.guard.ts• L47-83 packages/…/tenant-permission.guard.ts• L73-114 packages/…/auth.model.ts• L21-30 packages/…/two-factor.model.ts• L3-101
Embedded timer boundary
Embedded timer access lets another product place Gauzy's timer in its own site without exposing the member's wider workspace. An organization administrator creates a credential for a host backend, and the backend exchanges that credential for a short-lived token for one active member.
The boundary has three related controls:
- A credential is shown with its secret only at creation. It may cover the whole organization or one client. An optional setting lets an exchange add a new employee.
- An allowed origin names the site that may host the timer. The exchanged token is bound to that origin and to the credential's client when one exists.
- A site grant lets a signed-in person approve an allowed site directly. It gives the site a timer token and a one-use renewal token. Renewal rotates the token and revocation ends the grant family.
An embed token can read the signed-in member and the teams needed by the widget. It can list only trackable projects and start or stop the timer. Client-limited tokens accept starts only for that client's projects. The boundary refuses backdated timer fields, foreign tenant or organization values, unsafe query fields, and routes outside the timer surface.
The credential exchange and site renewal use the same member checks. The member must have an account, an active organization membership, and time tracking enabled. Revocation, origin changes, role changes, membership changes, and account changes therefore narrow or stop access without giving the embedded site a separate authorization model.
References: packages/…/embed-credential.model.ts• L3-173 packages/…/embed.controller.ts• L59-105 packages/…/embed.controller.ts• L107-215 packages/…/embed.controller.ts• L218-357 packages/…/embed-session.ts• L78-139 packages/…/embed-session.ts• L324-417 packages/…/embed-credential.service.ts• L176-204 packages/…/embed-credential.service.ts• L279-359 packages/…/embed-site-grant.service.ts• L146-255 packages/…/embed-member-token.ts• L36-99 packages/…/embed-client.service.ts• L165-233
Employee and membership boundary
An employee is the organization engagement behind an account. A human employee contributes to headcount and working-member views. An agent employee represents an integration actor and does not sign in or count as a person. A placeholder employee represents a member without an account and can hold work until the person claims it or an administrator merges it into an account-backed member.
Ending work makes an employee inactive and archived. Core hides that employee from working lists, task and time views, and project counts while keeping membership rows so a later return restores the same relationships. Management rights require active membership in the current tenant and organization. A manager role and the wider isManager right are separate signals.
Invitation acceptance now treats account identity and membership as separate decisions. An ordinary invitation for an address with an active account must be accepted from that account's signed-in session; the invitation credential alone cannot open it. A claim invitation for a placeholder creates a new account and transfers the placeholder's work, while an ended employee record blocks acceptance until an administrator restores it.
Acceptance claims the invitation before it creates an account or membership. If the later work fails, the invitation is released and a newly created claim account is retired when possible. This makes one invitation single-use under concurrent requests without leaving a failed acceptance permanently consumed. Invitations that name teams also create the employee relationship needed for that team, even for non-employee roles.
References: packages/…/employee.model.ts• L54-151 packages/…/employee-placeholder.model.ts• L5-83 packages/…/invite.model.ts• L56-65 packages/…/invite-accept.handler.ts• L38-171 packages/…/invite.accept-employee.handler.ts• L102-193 packages/…/invite.accept-user.handler.ts• L31-187 packages/…/invite.service.ts• L1968-2058 packages/…/invited-employee.ts• L5-59
Archive and privacy boundary
Archiving is a business state, not deletion. An archived project or team keeps its members, history, tasks, and time records. It remains readable by its id, while normal lists show active rows unless the caller asks for archived rows.
An organization can also keep private projects private from callers who do not have access. Core removes those projects from normal reads and masks their identity in related answers. Totals and historical time remain intact, but a hidden project is represented only by its id and a projectHidden marker. History removes old project names too, because a former project name can expose the same private record.
References: packages/…/archived-scope.ts• L4-90 packages/…/organization-project.service.ts• L603-843 packages/…/hidden-projects.ts• L128-275 packages/…/hidden-projects.interceptor.ts• L18-59 packages/…/time-log-history.service.ts• L120-169
Comment and reaction boundary
Comments on governed records follow the access rules of the record they describe. A parent policy supplies the scoped record lookup and permissions, so the shared comment API cannot become a side door into a protected record.
Reactions are shared by several domains, but chat-message reactions belong to the chat access model. The generic reaction service leaves them out and the chat service checks conversation membership. Other reactions remain personal writes scoped by employee and tenant.
References: packages/…/comment-parent-access.service.ts• L23-157 packages/…/organization-contact-comment-access.policy.ts• L7-46 packages/…/reaction-chat-scope.ts• L4-42 packages/…/reaction.service.ts• L31-71
Query and response safety boundary
Core protects sensitive data at two points. Query rules reject filters, sorts, selects, and relation paths that could reach credentials or protected rates. Response rules remove credentials and employee pay rates unless the route is the approved pay-rate response.
The same boundary handles relation input as a string, list, or nested object. It refuses unsafe names and excessive depth. Domain-built queries must apply the same rule when they do not use the generic CRUD path. Pipeline deal reads are one example: they validate requested relations before loading data through a second repository.
References: packages/…/crud.service.ts• L154-210 packages/…/crud.service.ts• L275-347 packages/…/caller-restricted-columns.helper.ts• L39-90 packages/…/user-credential-scrub.ts• L81-121 packages/…/employee-pay-rate-scrub.ts• L9-45 packages/…/pipeline.service.ts• L43-89
State and concurrency boundary
Core keeps related records and business state aligned when one action affects more than one record. Narrow actions protect server-owned state. Partial updates preserve omitted values. Conditional writes reject a stale view instead of silently replacing a newer edit.
Invoices use the last-read updatedAt as an optional precondition for field, line, action, estimate, and delete writes. The invoice and its lines can be saved as one unit. Time logs use the same contract for edits and tag changes. A conflict is a 409 with the current record when it is still readable, so a client can reload the state and try again.
Pipeline updates use the same state boundary for a pipeline and its stages. A request that sends stages replaces that stage set in one transaction. A request that omits stages keeps them, so a rename or archive cannot remove deals from their stages. Nested stages must remain in the pipeline's tenant and organization.
Tracking switches use the same idea with the boolean state shown by the caller's screen. The switch is checked and changed in one transaction. A stale screen gets TRACKING_SWITCH_CHANGED, and a caller without a higher role cannot change another person's switch.
References: packages/…/invoice-precondition.ts• L12-24 packages/…/invoice-precondition.ts• L155-180 packages/…/invoice.update-with-items.handler.ts• L20-32 packages/…/time-log-precondition.ts• L11-21 packages/…/time-log-tags.ts• L174-242 packages/…/tracking-switch-as-seen.ts• L64-136 packages/…/pipeline.service.ts• L92-192
Task and time boundary
Tasks, time logs, timesheets, and invoices form one work record. A task move keeps old task references resolvable while assigning a number in the destination project. Approved or billed time stays under the project that already signed off or invoiced it.
Time entry follows organization policy. Required team and project values can come from the task, the team's default project, or the employee's only active team. A missing required value produces one stable refusal that names the fields still missing. Breaks are a separate time-log type: they can be listed and charted, but they do not count as worked, billable, or invoiced time. A break must not overlap work, and work must not be recorded over a break.
Time logs can carry their own work tags. Tag writes accept only live tags from the same tenant and from the log's organization or the whole tenant. A caller can ask a start or manual entry to derive billability from its project. The project is the named project or the task's project, and a missing or foreign project leaves the caller's explicit billability in control. Stored billing and client rates let reports preserve the rate that priced historical time. Client rates are returned only to an administrator or a manager of every requested project. Pay-rate data remains more restricted.
Time-log commands keep the log, time slots, timesheets, worked-hour totals, history, and downstream facts aligned. A create or stop records the right lifecycle fact. An edit or delete updates the related slots and totals. A split creates the later part before cutting the first part and takes it back when the cut cannot pass its version or billing checks. The fact is placed with the write when the database can share the transaction; otherwise it is recorded after the write without making the person's time action fail.
Splitting is a domain action rather than a free edit. A running, approved, or invoiced log cannot be split. A split must leave at least one minute in each part. Tracked slots split only at a slot boundary, while manual time and breaks can split at any minute. Organization policy can also require a reason.
Time reports use the same tenant, organization, employee, team, project, and date rules as time entry. They group by one resolved time zone and keep empty days in chart and limit results. Dashboard task and member views narrow employee ids through management rights before they aggregate durations, so a requested employee never becomes a wider read by omission.
References: packages/…/timesheet.model.ts• L19-145 packages/…/timesheet.model.ts• L161-238 packages/…/timesheet.model.ts• L280-335 packages/…/timesheet.model.ts• L463-589 packages/…/time-log.service.ts• L219-245 packages/…/time-log.service.ts• L732-817 packages/…/time-log.service.ts• L2425-2621 packages/…/organization-tracking-requirements.ts• L7-129 packages/…/project-billable.ts• L5-33 packages/…/statistic.service.ts• L2090-2180 packages/…/statistic.service.ts• L2344-2399 packages/…/time-log-split-rule.ts• L152-247 packages/…/time-log-facts.service.ts• L11-69
Timer boundary
The timer is the live entry point for tracked time. It reads the caller's current or latest log and turns starts, stops, toggles, start moves, and discards into the same time-log and timesheet rules used by manual entry.
A timer start fills a missing team from the employee's only active team and a missing project from the task or team default when policy requires it. Ever Teams, mobile, and embedded starts also respect per-team tracking switches and can use the project's billable setting. A stop never closes a different run than the one the caller saw, and concurrent starts and stops are ordered per employee so one operation does not create or close another operation's run.
The timer reports duration in seconds and does not count breaks as running work. Turning tracking off stops future starts for the affected scope but still permits an already running timer to stop. A tracking-off event carries tenant, organization, employee, and optional team scope so consumers can stop only the affected timer.
References: packages/…/timesheet.model.ts• L433-509 packages/…/start-timer.dto.ts• L7-50 packages/…/timer.service.ts• L512-662 packages/…/timer.service.ts• L766-796 packages/…/timer.service.ts• L799-937 packages/…/timer.service.ts• L1831-1909 packages/…/tracking-turned-off.event.ts• L4-17 packages/…/timer.type.gql• L26-180
Saved report boundary
Saved reports let a signed-in member store a time report definition and reopen it later. The definition keeps the report kind, a moving period rule or fixed dates, filters, grouping, time zone, and whether amounts are included.
The author owns the saved report. Normal reads and writes are scoped to that author and organization. Sharing replaces the stored link digest and returns the clear token once. A public link is computed when opened rather than storing a report snapshot. It rebuilds the author's current account, membership, employee, role, tracked-data access, time data, labels, clients, and rates. If the author or access is no longer valid, the link answers the same not-found result as an unknown or expired link.
The public shape contains report fields only. It omits notes and private account data. Amounts appear only when the author chose them and remain separate by currency. Label grouping exposes only labels from the report's tenant and organization scope.
References: packages/…/saved-report.model.ts• L1-97 packages/…/saved-report.model.ts• L99-225 packages/…/saved-report.service.ts• L24-37 packages/…/saved-report.service.ts• L165-212 packages/…/saved-report-public.service.ts• L61-126 packages/…/saved-report-public.service.ts• L142-197 packages/…/saved-report-public.ts• L327-387 packages/…/saved-report.dto.ts• L57-124
Integration and durable-work boundary
An integration tenant is the organization-scoped connection between Gauzy and an external provider. Core keeps its settings and entity-sync rules under that scope. Task synchronization compares the last agreed value with the platform and provider values, then records a conflict when both sides changed a field differently.
Core separates a business result from work that another process must complete. Idempotency claims protect retried requests. Outbox events record facts with state changes. Operations, jobs, webhooks, subscriptions, and integration maps make later work visible and recoverable. Time-log facts use this boundary to tell downstream webhook and subscription consumers about timer starts, stops, creates, updates, and deletes.
References: packages/…/integration-tenant.service.ts• L49-216 packages/…/integration-sync-fields.ts• L4-153 packages/…/event-outbox.service.ts• L121-252 packages/…/event-outbox-dispatch.worker.ts• L46-80 packages/…/time-log-facts.service.ts• L60-105 packages/…/event-outbox.model.ts• L95-238
Notification and billing delivery boundary
Employee notifications are personal records that feed the in-app bell and Inbox. The receiver's employee identity scopes reads and state changes. In-app delivery is always saved. Email and push settings control only those extra channels.
Invoice email records distinguish an attempt from a confirmed hand-off to the mail transport. sentAt is empty when the row records an attempt that may have stopped before delivery. Scheduled billing recovery uses that state to decide whether an unsent draft needs another delivery attempt.
References: packages/…/employee-notification.model.ts• L55-145 packages/…/employee-notification-setting.model.ts• L18-83 packages/…/estimate-email.model.ts• L3-22 packages/…/estimate-email.service.ts• L1-220 packages/…/invoice.service.ts• L1-220
Shared contract library
The contracts package is the shared vocabulary between applications, core services, workers, clients, and plugins. It defines record shapes, action inputs, response shapes, identifiers, relationships, states, permissions, feature switches, and event envelopes without selecting REST, GraphQL, or another transport.
Record and action contracts
Base contracts give records common identity, tenant, organization, lifecycle, time, archive, deletion, and actor meaning. Domain contracts build on that base for people, work, time, finance, integrations, commerce, approvals, inbox work, chat, documents, reports, and desktop tracking.
Create inputs, update inputs, and narrow action inputs express different ownership of data. Caller-owned fields can be changed through an update. Server-owned state and derived values require a dedicated business action. Optional fields preserve stored values when a caller does not state a replacement.
References: packages/…/index.ts• L4-85 packages/…/index.ts• L124-213 packages/…/base-entity.model.ts• L24-87 packages/…/timesheet.model.ts• L44-155
Identity and membership contracts
User, employee, organization, team, and project contracts describe the workspace relationship that core services protect. They separate account identity from organization membership and carry policy such as time tracking, billing rates, privacy, and organization-level work rules.
The vocabulary also supports members without accounts. Placeholder inputs create or import a member. Claim inputs hand that member to an invitation. Merge results describe the work that moves to an account-backed employee.
References: packages/…/user.model.ts• L131-214 packages/…/employee.model.ts• L54-135 packages/…/organization.model.ts• L62-164 packages/…/employee-placeholder.model.ts• L17-83 packages/…/invite.model.ts• L38-65
Task, time, and timesheet contracts
Task contracts define the platform's common unit of work and its project, organization, member, team, status, priority, time, view, reminder, and integration meaning. Time contracts connect logs, slots, timesheets, tags, stored rates, reports, and timer actions.
Timesheet contracts also define project-change requests. A request names both the project that currently owns the affected time and the project that should receive it. This prevents approval from moving unrelated logs on a timesheet that contains time for several projects. The same vocabulary carries denial reasons, review notes, tag filters, client-rate reads, split inputs, saved-report filters, break entries, and project-derived billability across API surfaces.
References: packages/…/task.model.ts• L24-58 packages/…/task-view.model.ts• L53-167 packages/…/timesheet.model.ts• L80-155 packages/…/timesheet.model.ts• L161-238 packages/…/timesheet.model.ts• L280-335 packages/…/timesheet.model.ts• L463-589 packages/…/saved-report.model.ts• L49-70
Document contracts
Document contracts describe a shared workspace for folders, authored pages, and uploaded files. They also define visibility spaces for organizations, teams, and private pages; share levels; content versions; search and AI knowledge states; links to business records; inbound mail addresses; and import progress and reports. These states let document applications and plugins agree on ownership, review, indexing, and long-running import results.
The contract keeps secrets and server-owned values narrow. An inbound webhook secret is returned only when an address is created or rotated. A custom domain must reach a verified state before mail is accepted. Import reports retain item outcomes and stable reasons so a caller can show partial success without treating the whole archive as one opaque result.
References: packages/…/document.model.ts• L8-127 packages/…/document.model.ts• L135-212 packages/…/document.model.ts• L231-317 packages/…/document.model.ts• L365-475 packages/…/document.model.ts• L478-580
Finance and billing contracts
Invoice contracts represent estimates, invoices, lines, payments, reminders, and the time that bills a line. Invoice schedules add a repeatable client billing plan with one recorded run per period and a visible outcome.
Estimate email contracts carry the invoice link and language used for later reminders. Their delivery time is separate from the attempt row, so billing recovery can tell an unconfirmed hand-off from a completed one.
References: packages/…/invoice.model.ts• L17-55 packages/…/invoice-item.model.ts• L9-53 packages/…/invoice-schedule.model.ts• L1-137 packages/…/estimate-email.model.ts• L3-22
Permission and feature vocabulary
Permission names, role groups, and feature codes are wire contracts. They are stored, sent through APIs, checked by guards, and used by clients and plugins. A changed permission can affect role defaults, invitations, UI access, OAuth scopes, plugin routes, documents, time tracking, embedded timer routes, and real-time subscriptions.
API error codes are also a shared vocabulary. Clients can branch on a stable code while messages remain human-facing. Concurrency, stale tracking switches, hidden records, invalid tags, refused time splits, required tracking fields, billability choices, break overlap, and embed refusals must keep their codes aligned across REST, GraphQL, and background callers.
References: packages/…/role-permission.model.ts• L267-295 packages/…/role-permission.model.ts• L389-548 packages/…/default-role-permissions.ts• L1-80 packages/…/role-permission.service.ts• L44-64 packages/…/permission.guard.ts• L52-73 packages/…/api-error-codes.ts• L1-168 packages/…/organization-tracking-requirements.ts• L7-129
Durable and real-time contracts
Durable-work contracts describe idempotency claims, event envelopes, consumer delivery, job attempts, dead letters, operations, and webhooks. One idempotency key claims one result. An outbox event can be delivered at least once. A consumer record prevents one consumer from applying one event twice.
Real-time contracts separate durable change hints from ephemeral signals. Clients refetch durable changes through the owning API, so normal access rules still decide what they may see. Presence and typing signals are live-only. Catch-up cursors repair gaps after disconnects or a shared transport outage.
References: packages/…/idempotency.model.ts• L1-126 packages/…/event-outbox.model.ts• L95-238 packages/…/job-execution.model.ts• L15-89 packages/…/realtime.model.ts• L4-114 packages/…/realtime.model.ts• L184-270
Runtime libraries
The configuration, common, constants, and utility packages turn deployment inputs and shared policy into stable services. They keep applications and plugins from inventing different defaults, feature rules, query rules, or safety checks.
Runtime configuration
The configuration package maps environment values and defaults into one runtime view. It covers host URLs, authentication, storage, databases, integrations, feature switches, throttling, queues, cache, and deployment behavior.
Integration settings stay behind typed boundaries. Public settings can report capability or credential presence without returning stored secrets. Tenant-specific storage endpoints are checked before a provider connects to them. Embed enablement and token lifetime are also runtime choices, while the contract and core services keep the access rules fixed.
References: packages/…/ienvironment.ts• L29-168 packages/…/IActivepiecesConfig.ts• L3-47 packages/…/storage-endpoint-policy.ts• L20-77 packages/…/embed.utils.ts• L1-80
Database portability and startup
The database boundary keeps the same domain meaning across TypeORM, MikroORM, and supported database engines. Shared rules cover tenant and organization scope, soft deletion, relations, null values, dates, transactions, raw statements, and migrations.
Background work has a special startup boundary under MikroORM: each unit must obtain its own request context instead of using the global entity manager. Migrations must also preserve the contract on every supported database. The embed tables and origin, client, member-add, and site-grant settings are added as one business capability across the supported database paths.
The application boot process registers core and plugin entities, subscribers, and migrations before it creates the database connection. It also mounts request and MikroORM context for GraphQL, where the endpoint is outside the normal REST prefix. This keeps REST, GraphQL, plugins, and workers on the same domain boundary.
References: packages/…/database.ts• L25-60 packages/…/index.ts• L87-145 packages/…/index.ts• L324-395 packages/…/index.ts• L633-679 packages/…/1791000019400-CreateEmbedCredentialTable.ts• L1-80 packages/…/1791000019500-CreateEmbedAllowedOriginTable.ts• L1-80 packages/…/1791000019860-CreateEmbedSiteGrantTable.ts• L1-80 packages/…/mikro-orm-context.ts• L4-27 packages/…/crud.service.ts• L275-347
Shared policy and error libraries
The common package supplies decorators, guards, interfaces, and DTO helpers. Constants name stable product values. Utilities provide shared behavior for passwords, URL safety, dates, query conversion, configuration merging, exports, and other trust boundaries.
The core error catalogue gives all callers stable refusal categories for validation, permissions, concurrency, feature state, durable work, domain ledgers, embed access, tracking policy, and provider failures. This lets clients recover from a known condition without parsing a message.
References: packages/…/index.ts• L1-10 packages/…/index.ts• L1-9 packages/…/index.ts• L14-42 packages/…/api-error-codes.ts• L1-30 packages/…/api-error-codes.ts• L407-464 packages/…/embed.controller.ts• L56-57 packages/…/embed-site-grant.service.ts• L41-84 packages/…/existing-account-sign-in-required.ts• L3-15 packages/…/invited-employee.ts• L5-29
File storage boundary
File storage gives local and object-storage providers one business interface for upload, read, URL, and deletion. Cleanup records ownership before it removes database rows and deletes only keys under the owning tenant. Shared image keys remain while another record still uses them.
References: packages/…/provider.ts• L5-65 packages/…/storage-endpoint-policy.ts• L20-77 packages/…/account-deletion-files.ts• L7-118
List and pagination contract
The shared list boundary gives REST and GraphQL one meaning for filters, sorting, totals, and page movement. It rejects undeclared fields, unsupported operators, invalid cursors, and mixed cursor and offset styles. Dates, nulls, wildcards, and relation paths stay bounded so list results remain predictable and safe.
References: packages/…/graphql-connection.ts• L7-27 packages/…/graphql-connection.ts• L811-890 packages/…/utils.ts• L686-869 packages/…/schema.graphql• L1014-1047 packages/…/saved-report.dto.ts• L203-224
Domain request flow
An application, desktop client, worker, or plugin starts with a shared contract and supplies request or job context. A core capability validates that context, applies domain rules, stores the result, and returns a contract result or records durable work for another consumer.
This diagram shows how typed input becomes scoped domain state and then reaches later consumers.
sequenceDiagram
participant Caller as Application, client, worker, or plugin
participant Contract as Contract library
participant Core as Core service
participant Store as Database or provider
participant Durable as Event, job, or subscription system
Caller->>Contract: Create typed input
Caller->>Core: Request domain action
Core->>Core: Resolve identity, scope, and permissions
Core->>Store: Read or write business state
Core->>Durable: Record later work when needed
Store-->>Core: Return domain state
Core-->>Caller: Return shared result
The same flow covers registration policy, organization settings, task views, time tracking, billing, account deletion, integration synchronization, embedded timer access, saved reports, custom tracking, and notifications. Each path keeps identity and scope at the point where it can affect the result, then records durable facts when another process must continue the work.
References: packages/…/index.ts• L141-180 packages/…/index.ts• L4-30 packages/…/request-context.ts• L164-203 packages/…/invoice.update-with-items.handler.ts• L20-32 packages/…/embed-credential.service.ts• L477-506 packages/…/saved-report-public.service.ts• L93-197 packages/…/time-log-facts.service.ts• L97-164
Change checklist
When these files or sections are changed, remember to consider these:
- When a contract field, enum, permission, feature code, error code, event name, or refusal code changes, check every API, client, worker, plugin, stored value, and serialized payload that uses it.
- When context resolution changes, check request middleware, GraphQL and WebSocket work, queue workers, in-process timers, plugin calls, and MikroORM work outside HTTP.
- When token claims or grant narrowing changes, check JWT validation, permission and tenant guards, role-permission responses, OAuth scopes, API-token sessions, embed routes, origin checks, and session revocation.
- When embed access changes, check credential secret handling, client limits, member addition, allowed origins, CORS answers, site-grant renewal, token expiry, project scope, and the database migrations for both ORM paths.
- When a generic read or response field changes, check caller-supplied relations, credential scrubbing, pay-rate scrubbing, hidden-project masking, and history descriptions.
- When employee or membership rules change, check managed-member reads, custom tracking sessions and slots, team and project manager rights, invitations, embed members, and the distinction between a role and
isManager. - When invitation acceptance changes, check the active-account session rule, placeholder transfer, ended-employee refusal, early invite claiming, release after failure, and team-created employee memberships across REST and GraphQL.
- When private-project rules change, check direct project reads, related project fields, project lists, reports, time-log history, saved reports, embed client projects, and the
projectHiddenresponse shape. - When invoice fields or lines change, check all conditional write routes, the
updatedAtprecondition, line ownership, final billing state, estimate-email attempts, and ORM transaction paths. - When time-log contracts or commands change, check tags, stored rates, breaks, split rules, required team and project context, project-derived billability, time zones, reports, timesheet project-change requests, history, timer actions, outbox facts, and subscription names.
- When timer behavior changes, check source-specific project and team rules, break handling, stale stop and discard ids, employee ordering, tracking-off events, and the REST and GraphQL status shapes.
- When saved-report fields or public links change, check period rules, author revalidation, report permissions, client and label filters, amount and currency output, token hashing, expiry, and first-party-only sharing.
- When document states or inbound-address contracts change, check document visibility and share rules, AI review and indexing consumers, secret rotation, domain verification, import progress, plugin schemas, and stored serialized reports.
- When a database or ORM rule changes, check tenant and organization predicates, soft deletion, null values, dates, locks, migrations, background context setup, and every supported database path.
- When an idempotency, outbox, operation, job, webhook, subscription, or provisioning contract changes, check claim ownership, replay behavior, delivery records, ordering, retry limits, worker paths, and terminal reports.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A background MikroORM job uses the global entity manager | Repository work fails outside a request or shares stale state between job units | Wrap each unit in runInMikroOrmContext; keep the TypeORM path unchanged |
| A core read or write omits tenant or organization scope | One caller can reach another tenant's or organization's data | Resolve scope from the current context and stored relationships before custom or bulk queries |
| An embed token reaches a route outside its declared timer surface | A host can use a narrow timer credential to read workspace data or backdate time | Keep route, query, body, header, today-window, and client-project checks in the embed boundary |
| An embed token is accepted after its member, origin, credential, or site grant is no longer valid | A revoked or changed integration keeps access longer than its business rule | Revalidate account, membership, employee, origin, grant, and credential state when the token is judged or renewed |
| An embed credential secret or site renewal token is stored or returned in clear form | A database reader or log can reuse the integration session | Return each secret once and store only its digest |
| A credential limited to one client starts a timer on another project | Client time is filed outside the contract's billing and reporting boundary | Check the client and task relationship before the timer start and list only allowed projects |
| A public saved-report link uses the author's old access | A link continues to expose a report after the author leaves or loses permission | Rebuild the author's account, membership, employee, role, and tracked-data access at every open |
| A public saved report returns rates, notes, or labels outside its scope | A link exposes private business or personal data | Build the public response from an allow-list and filter rates and labels by the report's current scope |
| A pipeline update saves stages without the pipeline's tenant or organization | Deals can point to a stage owned by another workspace | Validate the nested graph and save the pipeline and stage changes in one tenant-scoped transaction |
| A time-log fact is written before its business write commits | A webhook or subscription consumer acts on a change that later rolls back | Append the fact in the write transaction when possible; otherwise append it only after the write succeeds |
| A time-log split or edit ignores a stale version or billing state | Approved, billed, or newer time is cut or replaced | Lock the log, compare updatedAt, check its timesheet, and compensate a failed split |
| An invite is marked accepted after account or membership creation | Two concurrent acceptances can create duplicate accounts or memberships | Claim the invite with the pending status in the write condition before downstream creation; release it when the acceptance fails |
| An invitation credential opens an already active account | A person who knows a mailed credential can enter another person's account | Require that account's signed-in session; return ExistingAccountSignInRequiredException without writing |
| A claim creates an account beside an existing account or ended employee | Placeholder work can attach to the wrong identity or an unusable membership | Refuse existing accounts and ended employees; transfer only after the new employee is active |
| A time entry omits a required team or project | Reports and work records lack the organization-required context | Derive the sole active team or task and team project, then return TRACKING_FIELD_REQUIRED when still missing |
| A break is counted as work or overlaps a work entry | Worked, billable, invoiced, or budget totals become too high | Keep BREAK out of totals and reject break/work overlap in the time-log rules |
| Project billability is resolved from an unscoped task or project | A caller can use another organization's project setting to price time | Read the task and project inside the employee's tenant and organization; fall back to explicit isBillable when absent |
| A stop or discard names a stale time-log id | A newer run can be closed or removed by an old client view | Compare the named id with the current running log and refuse without changing the current run |
| Two timer starts or stops run at once | One employee can have duplicate runs or a stop can close a newer run | Take the shared employee timer turn and stop or create only while the turn remains held |
| Turning tracking off rejects the stop of an existing run | A timer remains open and keeps counting after policy disables tracking | Refuse new starts but allow the already running timer to stop |
| A generic read returns stored pay or client rates | Sensitive salary or project pricing data reaches an unauthorized caller | Keep protected columns out of generic reads and require the specific rate permission |
| A time-log tag comes from another tenant or organization | A log is filed under an invalid tag or exposes cross-organization data | Validate every tag against tenant and organization scope before writing or filtering |
An invoice or time-log write uses a stale updatedAt | A newer edit is silently overwritten | Lock and compare the precondition in the write transaction; return CONCURRENT_MODIFICATION |
| Invoice lines change without moving the invoice's update marker | A later conditional save accepts an old invoice view | Touch the invoice in the same transaction as line changes |
| An estimate-email row is treated as proof of delivery | Recovery skips an email that may never have reached the mail transport | Treat sentAt as confirmed hand-off and an empty value as an unconfirmed attempt |
| A tracking switch changes after the caller read it | A stale screen undoes another administrator's change | Compare the expected switch and write it in one transaction; return TRACKING_SWITCH_CHANGED |
| TypeORM and MikroORM translate a condition differently | One deployment reads or changes a different set of rows | Translate supported operators explicitly and test both ORM paths against the same stored result |
| A contract or permission changes in only one consumer | Clients, plugins, workers, or stored payloads misread the boundary | Treat contracts, constants, error codes, and migrations as cross-application changes |
Key files
| File | Why to read it |
|---|---|
| packages/…/index.ts | Shows the public core boundary for applications and plugins. |
| packages/…/app.module.ts | Shows how the main host composes domain and kernel capabilities. |
| packages/…/index.ts | Shows how configuration, entities, migrations, request scope, CORS, and ORM startup are joined. |
| packages/…/request-context.ts | Shows the identity, scope, permission, OAuth, and correlation context. |
| packages/…/mikro-orm-context.ts | Shows how background work gets an isolated MikroORM context. |
| packages/…/crud.service.ts | Shows the shared read and write boundary across supported ORMs. |
| packages/…/jwt.strategy.ts | Shows current database validation and narrowing for ordinary, OAuth, and embed tokens. |
| packages/…/permission.guard.ts | Shows how route permissions are narrowed for OAuth and embed grants. |
| packages/…/embed.controller.ts | Shows the public embed, origin, credential, and site-grant interfaces. |
| packages/…/embed-credential.service.ts | Shows credential exchange, client limits, member addition, revocation, and failure classes. |
| packages/…/embed-site-grant.service.ts | Shows site authorization, one-use renewal, and whole-grant revocation. |
| packages/…/embed-session.ts | Shows the narrow timer route and request-scope contract. |
| packages/…/embed-client.service.ts | Shows project and report scope for client-limited timer access. |
| packages/…/invite-accept.handler.ts | Shows the shared invitation gate for account identity, role, tenant, and two-factor state. |
| packages/…/invite.accept-employee.handler.ts | Shows ordinary, claim, membership, and failure-recovery acceptance paths. |
| packages/…/invite.accept-user.handler.ts | Shows account and team handling for non-employee invitations. |
| packages/…/invite.service.ts | Shows single-use invitation claiming, rejection, and release. |
| packages/…/invited-employee.ts | Shows active employee creation and ended-employee refusal. |
| packages/…/hidden-projects.ts | Shows how private project identities are withheld without changing totals. |
| packages/…/managed-employee.service.ts | Shows the common meaning of own, managed, and organization-wide employee access. |
| packages/…/invoice-precondition.ts | Shows conditional invoice writes and conflict responses. |
| packages/…/invoice.update-with-items.handler.ts | Shows atomic invoice-and-line updates. |
| packages/…/time-log.service.ts | Shows time-log reads, reports, pricing, required context, breaks, tags, and domain actions. |
| packages/…/organization-tracking-requirements.ts | Shows how organization rules fill or refuse team and project context. |
| packages/…/project-billable.ts | Shows project-derived billability and its tenant boundary. |
| packages/…/time-log-create.handler.ts | Shows timer creation, scope checks, slots, totals, and lifecycle facts. |
| packages/…/time-log-update.handler.ts | Shows conditional edits, slot changes, history, and lifecycle facts. |
| packages/…/delete-time-span.handler.ts | Shows safe cuts, splits, compensation, and version checks. |
| packages/…/time-log-facts.service.ts | Shows the durable time-log event contract and transaction choice. |
| packages/…/time-log-tags.ts | Shows tag scope, filtering, and concurrent tag replacement. |
| packages/…/time-log-split-rule.ts | Shows the business rules for splitting time. |
| packages/…/timer.service.ts | Shows live timer state, source-specific policy, employee ordering, and safe starts and stops. |
| packages/…/tracking-turned-off.event.ts | Shows the scope carried when tracking is disabled. |
| packages/…/statistic.service.ts | Shows permission-aware dashboard and task aggregation. |
| packages/…/saved-report.service.ts | Shows author-owned report storage and one-time link sharing. |
| packages/…/saved-report-public.service.ts | Shows public-link revalidation and report generation under current author access. |
| packages/…/saved-report-public.ts | Shows the allow-listed public report shape and amount handling. |
| packages/…/index.ts | Shows the contract vocabulary exported to all consumers. |
| packages/…/base-entity.model.ts | Shows common identity, tenant, organization, lifecycle, archive, and actor fields. |
| packages/…/embed-credential.model.ts | Shows credential, origin, site-grant, timer, and client-report contracts. |
| packages/…/document.model.ts | Shows document tree, visibility, AI, inbound mail, and import contracts. |
| packages/…/saved-report.model.ts | Shows saved-report definitions, filters, sharing, and public results. |
| packages/…/employee.model.ts | Shows account-backed, agent, placeholder, presence, and work policy fields. |
| packages/…/timesheet.model.ts | Shows timesheet, time-log, tag, rate, report, timer, break, and project-change contracts. |
| packages/…/invoice-schedule.model.ts | Shows repeat billing periods, run outcomes, and recovery reasons. |
| packages/…/estimate-email.model.ts | Shows the distinction between an email attempt and confirmed hand-off. |
| packages/…/role-permission.model.ts | Shows the shared permission catalogue and role groups. |
| packages/…/event-outbox.model.ts | Shows durable event and consumer delivery meaning. |
| packages/…/ienvironment.ts | Shows the typed runtime settings boundary. |
| packages/…/1791000019400-CreateEmbedCredentialTable.ts | Shows the stored boundary for host credentials. |
| packages/…/1791000019500-CreateEmbedAllowedOriginTable.ts | Shows the stored boundary for site origin policy. |
| packages/…/1791000019860-CreateEmbedSiteGrantTable.ts | Shows the stored boundary for one-use site renewal. |