Polymorphic AI classification — job queue + result store keyed by (entity_type, entity_id)
| Tier | domain |
| Role | unclassified (baselined) |
| Path | crates/domain/classify |
| Edition | 2021 |
| Targets | domain_classify |
| Public items | 25 across 0 modules |
| Tests | 11 |
What it is for
Polymorphic AI classification library crate (Sprint 0.6).
Any entity can be classified by an AI model. This crate provides:
Classification— the result of one classification (immutable
per (tenant_id, entity_type, entity_id, classification_type) tuple; re-classify replaces).
ClassifyJob/ClassifyJobStatus— the work queue.ClassifyService— the orchestration trait that workers
implement (enqueue → next_pending → mark_running → complete | fail).
InMemoryClassifyService— a test-only impl that downstream
crates can use in their own unit tests without standing up Postgres.
Polymorphic via (entity_type: String, entity_id: Uuid) — no hard FK to the target entity. Same shape used by domain-taxonomy.taggings, content-assets.attachments, operations-approval-workflow.
Gate 1.5 Q4: greenfield crate; rust-cms-engine becomes the first downstream consumer (wiring entity_type="catalog_item"); the existing rust-inventory-ai classify worker stays on its legacy classify_status columns until a later sprint ports it.
Capabilities
Classification
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub struct Classification |
Classification :: fn id(& self) -> Uuid |
Classification :: fn created_at(& self) -> DateTime <Utc> |
Classification :: fn updated_at(& self) -> DateTime <Utc> |
Classification :: fn deleted_at(& self) -> Option <DateTime <Utc>> |
ClassifyError
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub enum ClassifyError |
ClassifyJob
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub struct ClassifyJob |
ClassifyJob :: fn id(& self) -> Uuid |
ClassifyJob :: fn created_at(& self) -> DateTime <Utc> |
ClassifyJob :: fn updated_at(& self) -> DateTime <Utc> |
ClassifyJobStatus
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub enum ClassifyJobStatus |
ClassifyJobStatus :: fn is_terminal(& self) -> bool |
ClassifyJobStatus :: fn as_str(& self) -> & 'static str |
ClassifyJobStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
ClassifyService
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub trait ClassifyService |
EnqueueRequest
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub struct EnqueueRequest |
InMemoryClassifyService
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub struct InMemoryClassifyService |
InMemoryClassifyService :: fn new() -> Self |
InMemoryClassifyService :: async fn enqueue(& self, req : EnqueueRequest) -> Result <ClassifyJob> |
InMemoryClassifyService :: async fn next_pending(& self, handler_key : & str, limit : usize) -> Result <Vec <ClassifyJob>> |
InMemoryClassifyService :: async fn mark_running(& self, job_id : Uuid) -> Result <()> |
InMemoryClassifyService :: async fn complete(& self, job_id : Uuid, result : serde_json::Value, confidence : Option <f32>, source_prompt_template_id : Option <Uuid>, source_prompt_version_id : Option <Uuid>,) -> Result <Classification> |
InMemoryClassifyService :: async fn fail(& self, job_id : Uuid, error : & str) -> Result <()> |
InMemoryClassifyService :: async fn latest_for(& self, tenant_id : Uuid, entity_type : & str, entity_id : Uuid, classification_type : & str,) -> Result <Option <Classification>> |
Result
Polymorphic AI classification library crate (Sprint 0.6).
| Item |
|---|
pub type Result<T>: std::result::Result <T, ClassifyError> |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum ClassifyError | Errors that can occur in classify operations. |
pub type Result<T>: std::result::Result <T, ClassifyError> | Result type for classify operations. |
pub enum ClassifyJobStatus | Lifecycle status of a classification job. |
ClassifyJobStatus :: fn is_terminal(& self) -> bool | Returns true if the status is terminal (no further transitions). |
ClassifyJobStatus :: fn as_str(& self) -> & 'static str | Canonical string form (matches the DB CHECK constraint). |
ClassifyJobStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub struct Classification | A classification result for one (tenant, entity_type, entity_id, classification_type) tuple |
Classification :: fn id(& self) -> Uuid | — |
Classification :: fn created_at(& self) -> DateTime <Utc> | — |
Classification :: fn updated_at(& self) -> DateTime <Utc> | — |
Classification :: fn deleted_at(& self) -> Option <DateTime <Utc>> | — |
pub struct ClassifyJob | A pending / running / terminal classification job. |
ClassifyJob :: fn id(& self) -> Uuid | — |
ClassifyJob :: fn created_at(& self) -> DateTime <Utc> | — |
ClassifyJob :: fn updated_at(& self) -> DateTime <Utc> | — |
pub struct EnqueueRequest | Input to ClassifyService::enqueue. |
pub trait ClassifyService | Orchestrates classification jobs |
pub struct InMemoryClassifyService | In-memory implementation of ClassifyService for unit tests in downstream crates |
InMemoryClassifyService :: fn new() -> Self | Creates a new empty in-memory classify service. |
InMemoryClassifyService :: async fn enqueue(& self, req : EnqueueRequest) -> Result <ClassifyJob> | — |
InMemoryClassifyService :: async fn next_pending(& self, handler_key : & str, limit : usize) -> Result <Vec <ClassifyJob>> | — |
InMemoryClassifyService :: async fn mark_running(& self, job_id : Uuid) -> Result <()> | — |
InMemoryClassifyService :: async fn complete(& self, job_id : Uuid, result : serde_json::Value, confidence : Option <f32>, source_prompt_template_id : Option <Uuid>, source_prompt_version_id : Option <Uuid>,) -> Result <Classification> | — |
InMemoryClassifyService :: async fn fail(& self, job_id : Uuid, error : & str) -> Result <()> | — |
InMemoryClassifyService :: async fn latest_for(& self, tenant_id : Uuid, entity_type : & str, entity_id : Uuid, classification_type : & str,) -> Result <Option <Classification>> | — |
No pub use re-exports: every item above is declared in this crate.
Boundary
Reaches into foundation, infrastructure.
Shares tier domain with 41 other crates: domain-agreements, domain-ai-report, domain-billing, domain-catalog, domain-comments, domain-competitive-intel, domain-contact, domain-conversation-engine, … (41 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | domain |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/domain/classify |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_domain["domain"] --> n_foundation["foundation"] n_domain["domain"] --> n_infrastructure["infrastructure"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-basemodels` | foundation | no | always |
| `infrastructure-prompts` | infrastructure | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
chrono | ^0.4 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
thiserror | ^2 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1 | full | no | always |
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. Nothing in this workspace.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR SELF["domain-classify"] SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"] SELF -->|runtime| n_infrastructure_prompts["infrastructure-prompts"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | domain_classify | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
ClassifyError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | yes |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
No workspace crate depends on this one.
Verification
| Kind | Count |
|---|---|
| Unit tests | 11 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 8 | 0 | 0 |
What the tests establish, by name:
test_cannot_complete_pending_job—src/lib.rstest_cannot_fail_succeeded_job—src/lib.rstest_enqueue_is_idempotent_for_pending_job—src/lib.rstest_failure_path_marks_job_failed—src/lib.rstest_happy_path—src/lib.rstest_mark_running_unknown_job—src/lib.rstest_polymorphic_two_entity_types_same_handler—src/lib.rstest_reclassify_replaces_prior—src/lib.rstest_status_default_is_pending—src/lib.rstest_status_is_terminal—src/lib.rstest_status_serde_roundtrip—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 11 | 25 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 11
"No rustdoc detected" : 14
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 838 |
| Code lines | 627 |
| Public API items | 25 |
| Public modules | 0 |
| Tests | 11 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 8 |
| Workspace reverse dependencies | 0 |
pie showData
title Public API by kind
"enum" : 2
"method" : 17
"struct" : 4
"trait" : 1
"type alias" : 1
pie showData
title Rust source composition
"Code" : 627
"Blank or comment" : 211
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.