Repository navigation
Description
Summary
The portal (dfinity/portal) had a best-practices section under building-apps/best-practices/ and building-apps/security/. Most of that content has been ported. This issue tracks the remaining gaps identified by a full cross-reference audit on 2026-05-12.
Source files are at .sources/portal/docs/building-apps/best-practices/ (read-only submodule).
Gap 1: Canister-per-user architectural pattern
Source: .sources/portal/docs/building-apps/best-practices/application-architectures.mdx
Target: docs/concepts/app-architecture.md (extend existing page)
Effort: Small
Our concept page covers three of four patterns (single canister, canister-per-service, canister-per-subnet). The canister-per-user pattern is missing entirely.
Content to add:
- The canister-per-user model: each user gets their own canister they control
- Why the main canister must be written to handle potentially malicious user canisters
- Honest note that canister-per-user has no successful end-to-end implementation yet
- Correct the common misconception that per-user is the most scalable (per-subnet is more performant)
Gap 2: Canister trust guide (user perspective)
Source: .sources/portal/docs/building-apps/best-practices/trust-in-canisters.mdx
Target: New page docs/guides/canister-management/trust-in-canisters.md
Effort: Medium
Our docs currently split this content: canister-control.md covers governance and reproducible-builds.md covers hash verification. What is missing is the cohesive framing of: "you want to interact with a canister you didn't write — how do you assess whether it is safe to do so?"
Content to include:
- The two trust questions: does it do what it claims, and will it stay that way?
- Code inspection + reproducible build hash comparison as the verification path
- The canister history feature: how to track Wasm hash changes over time using canister history
- Controller verification via
icp canister statusandread_state - The trust spectrum: developer-controlled → multi-sig (Orbit) → SNS/DAO → black-holed
- The black hole canister (
e3mmv-5qaaa-aaaah-aadma-cai): what it provides, its trade-offs - Important caveat: even a self-controlling canister can be dangerous if it can reinstall itself — code inspection is necessary
Cross-link from reproducible-builds.md and canister-control.md.
Gap 3: Practical data storage recommendations
Source: .sources/portal/docs/building-apps/best-practices/storage.mdx
Target: Extend docs/guides/backends/data-persistence.mdx OR new docs/guides/canister-management/storage-best-practices.md
Effort: Medium
docs/concepts/orthogonal-persistence.md covers the conceptual distinction between heap and stable memory well. What is missing is the actionable guidance layer.
Content to include:
- Explicit decision rule: use stable structures directly; avoid pre/post upgrade hooks for data that matters
- When to choose heap (small, frequently accessed, ephemeral) vs. stable (large, infrequently accessed, must persist)
- Motoko data structure recommendations (updated to
mo:coreequivalents):- Use
Map(formerlyHashMap/TrieMap) — avoids automatic resizing overhead - Use
List(formerlyBuffer) for dynamic sequences - Use
Blobover[Nat8]for binary data (4x more compact, less GC pressure) - Store large
Blobs in stable memory - Consider
compacting-gcfor append-only workloads
- Use
- Rust data structure recommendations:
- Caution with
Vec<u8>andStringin state serialization (instruction cost on encode/decode) - Reference the effective Rust canisters resource
- Caution with
- State backup strategies: why to implement backup mechanisms, reference Distrikt's approach
- Transaction history: dedicated services vs. inline storage, trade-offs
Note: Motoko recommendations must use mo:core names (not mo:base). Verify against .sources/motoko-core before writing.
Gap 4: Query result pagination
Source: .sources/portal/docs/building-apps/best-practices/general.mdx (pagination item)
Target: New section in docs/guides/canister-calls/inter-canister-calls.mdx or new docs/guides/canister-calls/pagination.md
Effort: Small
No guide covers how to paginate query results correctly. The specific edge case — where offset-based pagination returns duplicates when items are added or removed between pages — is a common source of bugs.
Content to include:
- Why simple offset/limit pagination is unreliable for mutable datasets
- Cursor/token-based pagination pattern: pass the last-seen item identifier rather than an offset
- Considerations for sort order stability
- Handling the case where a cursor item has been deleted
Gap 5: Troubleshooting guide
Source: .sources/portal/docs/building-apps/best-practices/troubleshooting.mdx
Target: New docs/guides/canister-management/troubleshooting.md
Effort: Large (needs full rewrite, not a port)
We have no troubleshooting guide. The portal version is heavily dfx-centric and not portable as-is, but the underlying content is useful.
Content to extract and rewrite (using icp CLI throughout):
- Query vs. update call latency: when query calls are appropriate and the certified query alternative
- Compute allocation as a remedy for noisy-neighbor latency spikes
- How to identify your canister's subnet and compare load on the dashboard
- Retrieving boundary node address and request ID for support escalation
- Frontend CSP violations: symptoms and fix (reinstall the asset canister)
- Security policy warnings in
.ic-assets.json5 - Invalid Wasm import sections in Rust (crates assuming unavailable functions)
Do NOT port: anything referencing cycles wallets, dfxvm, dfx identity deploy-wallet, or WSL troubleshooting. Those are dfx-era topics.
What was audited and confirmed NOT missing
The following portal files are fully covered by existing pages — no action needed:
| Portal file | Covered by |
|---|---|
reproducible-builds.mdx |
guides/canister-management/reproducible-builds.md |
idempotency.mdx |
guides/canister-calls/idempotency.md |
general.mdx (cycles, freezing threshold) |
guides/canister-management/cycles-management.mdx |
general.mdx (DoS, unbounded processing) |
guides/security/dos-prevention.md |
general.mdx (certified variables) |
guides/backends/certified-variables.md |
security/decentralization.mdx |
guides/security/canister-control.md |
security/resources.mdx |
guides/security/overview.md (Further reading) |
security/overview.mdx |
Navigational only, no content to port |
application-architectures.mdx (3 of 4 patterns) |
concepts/app-architecture.md |
Notes for implementers
- Load
technical-documentation+icp-brand-voiceskills before writing - Load the
canister-securityicskill for Gap 2 - All code examples must use
icpCLI, neverdfx - All Motoko examples must use
mo:core, nevermo:base - Every new page needs an
<!-- Upstream: -->comment citing.sources/portal/... - Record the new page in
.docs-plan/decisions.md - Add the new page to
sidebar.mjs(confirm location with maintainer before adding)
Activity