Skip to content

Schema Keys

Schema keys are hierarchical identifiers that classify every piece of knowledge in Contox. They follow a path-based naming convention (root/category/subcategory) and serve as the organizational backbone for the brain document, memory items, and contexts.

Naming Convention

Schema keys use forward-slash-separated segments, always starting with root/:

root/category
root/category/subcategory
  • All segments are lowercase
  • Use hyphens for multi-word segments (e.g., backend/api)
  • Maximum depth is typically 2--3 levels
  • The root prefix is always present

Full Taxonomy

Contox defines 30 canonical schema keys, organized into three categories: domain keys (where in the project), package keys (which package), and type keys (what kind of knowledge).

Domain Keys

These classify knowledge by its location in the project architecture:

Schema KeyDescription
root/stackDependencies, frameworks, configs, package.json
root/dataDatabase schema, Prisma, migrations, seed data
root/perfIndexes, caching, query optimization
root/authAuthentication, sessions, tokens (cross-cutting)
root/securityCORS, CSP, rate limiting, RBAC, encryption
root/infraCI/CD, Docker, deployment scripts, .github
root/testingTests, mocks, fixtures, e2e
root/docsREADME, guides, documentation
root/otherMiscellaneous / unclassifiable

Backend Keys

Schema KeyDescription
root/backend/apiAPI endpoints, controllers, route handlers
root/backend/servicesBusiness logic, server-side libraries

Frontend Keys

Schema KeyDescription
root/frontend/authFrontend auth flows, login/signup
root/frontend/uiGeneral UI, styling, theming
root/frontend/componentsReusable components
root/frontend/routesPages, routes, layouts
root/frontend/stateRedux, Zustand, Context, stores
root/frontend/hooksCustom React hooks
root/frontend/libFrontend utilities, helpers
root/frontend/storesDedicated store files
root/frontend/typesTypeScript types, interfaces

Package Keys

Schema KeyDescription
root/cliCLI package
root/mcpMCP server package
root/vscodeVS Code extension package

Type Keys

Used when no clear domain applies -- these classify by knowledge type:

Schema KeyDescription
root/decisionsArchitectural decisions
root/conventionsCoding conventions, style rules
root/architectureArchitecture notes, design patterns
root/journalImplementation journal entries
root/bugsBug fixes, workarounds
root/todoPending tasks, known issues
root/codemapCodebase structure from scan

Extended Hierarchy (Brain Schema)

The brain schema defines additional keys for engineering layers beyond the core 29 enrichment keys. These are used in the static brain schema for organizing the knowledge graph:

root/
  cortex
  stack/
    database, environment, deployment
  api/
    auth, core, integrations
  frontend/
    ui, pages, hooks, design, components, routes, state, lib, stores, types
  backend/
    auth, logic, integrations, api, services
  packages/
    mcp, cli, plugin, vscode
  conventions
  decisions
  todo
  bugs
  journal
  sessions
  contracts/
    auth, brain-endpoint, entries, populate, search, links, compaction
  runbooks/
    brain-5xx, populate-stuck, search-low-recall, drafts-never-approved, audit-mismatch, appwrite-throttling
  ops
  security
  governance
  quality
  performance
  patterns
  flows
  schema
  adrs

Schema Key Resolution

Schema keys are assigned through two mechanisms depending on the event type:

LLM-Based Resolution (Primary)

For mcp_save and vscode_capture events, the LLM (Mistral) picks from the canonical enum of 30 schema keys during enrichment. The system prompt includes the full taxonomy with descriptions, and the JSON schema enforces that only valid keys are emitted.

Deterministic Resolution (Fallback)

For auto_save and scan events (or when the LLM output is invalid), schema keys are inferred from file paths using prefix-matching rules:

typescript
// Path prefix → schema key (first match wins)
'src/app/api/'           → 'root/backend/api'
'src/components/'        → 'root/frontend/components'
'src/hooks/'             → 'root/frontend/hooks'
'src/stores/'            → 'root/frontend/stores'
'packages/cli/'          → 'root/cli'
'packages/mcp-server/'   → 'root/mcp'
'.github/'               → 'root/infra'
'package.json'           → 'root/stack'

When file-based resolution fails, the system falls back to a type-based mapping:

Item TypeFallback Schema Key
Decisionroot/decisions
Conventionroot/conventions
BugFixroot/bugs
Todoroot/todo
ArchitectureNoteroot/architecture
ImplementationFactroot/journal
CodeMapNoderoot/codemap

Normalization

LLM-generated schema keys are validated and normalized before storage. The normalizer handles:

  • Exact matches against the canonical set
  • Case normalization (lowercasing)
  • Missing root/ prefix (auto-prepended)
  • Over-deep keys (truncated to 2 or 3 levels)
  • Complete fallback to root/other if nothing matches

Tiers and Brain Layers

Schema keys interact with the tier system to control brain inclusion:

TierBrain LayerStrategy
Tier 1Layer 1 (Active Knowledge)Always loaded. For critical, recent, high-importance items.
Tier 2Layer 2 (Reference Knowledge)Loaded on demand. For stable, high-confidence knowledge.
Tier 3Layer 3 (Archive)Excluded from brain. Available via search.

Note that tier assignment is not solely based on the schema key -- it also considers the item's recency, importance, confidence, and status. See Brain Assembly for the full classification logic.

Section Ordering in Brain

When the brain document is assembled, Layer 2 items are grouped by their schema key prefix (first two segments) and displayed in a fixed order:

  1. Decisions
  2. Conventions
  3. Architecture
  4. Stack
  5. Data Layer
  6. Authentication
  7. Security
  8. Backend
  9. Frontend
  10. Performance
  11. Implementation Journal
  12. Bug Fixes
  13. Todo / Pending
  14. CLI
  15. MCP Server
  16. VS Code Extension
  17. Infrastructure
  18. Testing
  19. Documentation
  20. Code Map
  21. Other