image
Akan.js
English
DocsConventionsReferencesCheatsheet
image
Akan.js
Akan.js v2 docs are now available.View the v1 docs
DocsConventionsReferencesCheatsheet
Released under the MIT License
Official Akan.js Consulting onAkansoft
Copyright © 2026 Akan.js All rights reserved.
System managed bybassman
Workspace Convention
• Structure
• Format & Lint
App & Library Convention
• Assets (public/ private/)
• Components (ui/)
• Server Utils (srvkit/)
• Web Utils (webkit/)
• Common Utils (common/)
• akan.config.ts
Domain Convention
• Overview
• model.constant.ts
• model.dictionary.ts
• model.document.ts
• model.service.ts
• model.signal.ts
• model.store.ts
• Model.Template.tsx
• Model.Unit.tsx
• Model.Util.tsx
• Model.View.tsx
• Model.Zone.tsx
Scalar Convention
• Overview
• scalar.constant.ts
• scalar.dictionary.ts
• scalar.document.ts
• Scalar.Template.tsx
• Scalar.Unit.tsx
Service Convention
• Overview
• service.dictionary.ts
• service.service.ts
• service.signal.ts
• service.store.ts
• Service.Util.tsx
• Service.Zone.tsx
Workspace Convention
• Structure
• Format & Lint
App & Library Convention
• Assets (public/ private/)
• Components (ui/)
• Server Utils (srvkit/)
• Web Utils (webkit/)
• Common Utils (common/)
• akan.config.ts
Domain Convention
• Overview
• model.constant.ts
• model.dictionary.ts
• model.document.ts
• model.service.ts
• model.signal.ts
• model.store.ts
• Model.Template.tsx
• Model.Unit.tsx
• Model.Util.tsx
• Model.View.tsx
• Model.Zone.tsx
Scalar Convention
• Overview
• scalar.constant.ts
• scalar.dictionary.ts
• scalar.document.ts
• Scalar.Template.tsx
• Scalar.Unit.tsx
Service Convention
• Overview
• service.dictionary.ts
• service.service.ts
• service.signal.ts
• service.store.ts
• Service.Util.tsx
• Service.Zone.tsx
Previous
model.dictionary.ts
Next
model.service.ts

model.document.ts

A document file defines the database behavior of a module. The constant file describes the data shape, while the document file explains how to query, mutate, load, index, and operate on stored documents.
A normal document file usually contains search conditions, document-level behavior, and database model helpers used by services.

Standard Document Shape

Use this shape for normal collection-backed models. Business documents usually define query rules, one-document behavior, and model-level helpers together.
Filter
Reusable list, lookup, and sort conditions.
Document
Behavior of one loaded document.
Model
Model-level helpers used by services.
ticket.document.ts

Query, Sort, And Generated Methods

Define frequently used list and lookup conditions once, then use the generated methods in services or signals. For example, a query named inProject becomes methods like listInProject, countInProject, and existsInProject.
The framework already provides all-document and latest/oldest ordering behavior, so only add business-specific search and sort rules.
story.document.ts
arg()
Required input for the query. Required args must come before optional args.
opt()
Optional input. Build the query conditionally when the value exists.
q helper
Use helpers like all, any, not, oneOf, notOneOf, between, gte, lte, contains, exists, and empty.
CRUD helpers
get, load, loadMany, create, update, remove, searchDocs, searchCount
Query helpers
list, listIds, find, findId, pick, pickId, exists, count, insight, query
ticket.service.ts | ticket.document.ts
ticket.service.ts | ticket.document.ts

Document Instance Behavior

Put small state transitions and document-level checks on the loaded document class. Methods usually mutate this, use this.set(...) when several fields change together, and return this for chaining.
Because each method returns the same document, service code can chain several document methods and save the final result once.
ticket.document.ts
ticket.service.ts

Model-Level Helpers

Put collection-level operations on the model class. Service files usually call these helpers when they need direct database updates, batch operations, counters, or document generation.
story.document.ts

Extending Generated Documents

Generated or app-template domains can provide existing filter, document, and model behavior. Keep those generated refs in the class declarations, then add only the local app-specific methods you need.
user.document.ts

Loaders And Custom Lookups

Declare loaders for lookup shapes that are used often and should stay consistent. Use a single-field loader for lookups like product by seller, and a multi-field loader for stable combinations like order by shop and order number.
product.document.ts
order.document.ts

Schema Hooks And Indexes

Use _onSchema when the storage schema needs indexes or lightweight save hooks. Keep heavy business workflows in service or model methods, and keep schema hooks focused on persistence concerns.
story.document.ts
user.document.ts

Practical Rules

Use Filter, Document, and Model class names that match the constant model name.
Put reusable list and lookup conditions in the filter section instead of repeating them in service methods.
Put single-document state transitions on the document class, and collection-level operations on the model class.
Use generated extension spreads when a template domain provides filters, docs, or models.
Use loaders for common stable lookups, and schema hooks only for persistence-level indexes or small save hooks.
Keep scalar document files small; a simple document class is usually enough.
model.document.ts
Standard Document Shape
Query, Sort, And Generated Methods
Document Instance Behavior
Model-Level Helpers
Extending Generated Documents
Loaders And Custom Lookups
Schema Hooks And Indexes
Practical Rules