Forge classify module — AI classification job queue + worker + AI credential storage. Sprint 59.
| Tier | application |
| Role | unclassified (baselined) |
| Path | crates/application/classify |
| Edition | 2024 |
| Targets | application_classify, pg_forge_classify |
| Public items | 40 across 7 modules |
| Tests | 2 |
What it is for
application-classify — Layer 3 module. Sprint 59: services + worker extracted.
Capabilities
ClassifyModule
application-classify — Layer 3 module. Sprint 59: services + worker extracted.
| Item |
|---|
pub struct ClassifyModule |
ClassifyModule :: fn new() -> Self |
ClassifyModule :: fn name(& self) -> & 'static str |
ClassifyModule :: fn version(& self) -> & 'static str |
ClassifyModule :: fn migrations(& self) -> Vec <MigrationSet> |
ClassifyModule :: async fn migrate_pending(& self, pool : & PgPool) -> Result <u32, MigrationError> |
api (other)
HTTP API for application-classify (Sprint 65: extracted from rust-cms-engine).
| Item |
|---|
fn admin_router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, |
api::classify_admin (other)
Classify admin REST endpoints (Sprint 41 — Gate 1.5 Q4).
| Item |
|---|
fn router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, |
services::classify (other)
Classify service — polymorphic AI classification (Sprint 41).
| Item |
|---|
async fn enqueue(pool : & PgPool, req : EnqueueRequest) -> Result <ClassifyJob, ClassifyError> |
async fn get_job(pool : & PgPool, job_id : Uuid) -> Result <ClassifyJob, ClassifyError> |
async fn next_pending(pool : & PgPool, handler_key : & str, limit : i64,) -> Result <Vec <ClassifyJob>, ClassifyError> |
async fn complete(pool : & PgPool, job_id : Uuid, result : serde_json::Value, confidence : Option <f32>, source_prompt_template_id : Option <Uuid>, source_prompt_version_id : Option <Uuid>,) -> Result <Classification, ClassifyError> |
async fn latest_for(pool : & PgPool, tenant_id : Uuid, entity_type : & str, entity_id : Uuid, classification_type : & str,) -> Result <Option <Classification>, ClassifyError> |
async fn list_for_entity(pool : & PgPool, tenant_id : Uuid, entity_type : & str, entity_id : Uuid,) -> Result <Vec <Classification>, ClassifyError> |
async fn create_prompt_template(pool : & PgPool, input : CreatePromptTemplateInput,) -> Result <PromptTemplate, ClassifyError> |
async fn list_prompt_templates(pool : & PgPool, prompt_kind : Option <& str>,) -> Result <Vec <PromptTemplate>, ClassifyError> |
async fn get_prompt_template(pool : & PgPool, id : Uuid) -> Result <PromptTemplate, ClassifyError> |
Classification
Classify service — polymorphic AI classification (Sprint 41).
| Item |
|---|
pub struct Classification |
ClassifyError
Classify service — polymorphic AI classification (Sprint 41).
| Item |
|---|
pub enum ClassifyError |
async fn mark_running(pool : & PgPool, job_id : Uuid) -> Result <(), ClassifyError> |
async fn fail(pool : & PgPool, job_id : Uuid, error : & str) -> Result <(), ClassifyError> |
async fn get_active_prompt_text(pool : & PgPool, tenant_id : Uuid, handler_key : & str,) -> Result <Option <(String, String, Option <i32>)>, ClassifyError> |
ClassifyJob
Classify service — polymorphic AI classification (Sprint 41).
| Item |
|---|
pub struct ClassifyJob |
CreatePromptTemplateInput
Classify service — polymorphic AI classification (Sprint 41).
| Item |
|---|
pub struct CreatePromptTemplateInput |
EnqueueRequest
Classify service — polymorphic AI classification (Sprint 41).
| Item |
|---|
pub struct EnqueueRequest |
PromptTemplate
Classify service — polymorphic AI classification (Sprint 41).
| Item |
|---|
pub struct PromptTemplate |
ClassifyWorkerConfig
Classify worker loop (Sprint 46 + 47).
| Item |
|---|
pub struct ClassifyWorkerConfig |
ClassifyWorkerConfig :: fn new(handler_key : impl Into <String>, provider_name : impl Into <String>) -> Self |
ClassifyWorkerConfig :: fn with_prompt_builder(mut self, pb : Arc <dyn PromptBuilder>) -> Self |
async fn run_classify_worker(pool : PgPool, provider : Arc <dyn AiProvider>, config : ClassifyWorkerConfig, shutdown : CancellationToken,) |
DefaultPromptBuilder
Prompt builder trait for the classify worker (Sprint 47).
| Item |
|---|
pub struct DefaultPromptBuilder |
DefaultPromptBuilder :: fn default() -> Self |
DefaultPromptBuilder :: async fn build(& self, pool : & PgPool, job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError> |
InlinePromptBuilder
Prompt builder trait for the classify worker (Sprint 47).
| Item |
|---|
pub struct InlinePromptBuilder |
InlinePromptBuilder :: fn new <F>(f : F) -> Self where F : for <'a> Fn(& 'a PgPool, & 'a ClassifyJob,) -> futures_util::future::BoxFuture <'a, Result <CompletionRequest, PromptBuilderError>,> + Send + Sync + 'static, |
InlinePromptBuilder :: async fn build(& self, pool : & PgPool, job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError> |
PromptBuilder
Prompt builder trait for the classify worker (Sprint 47).
| Item |
|---|
pub trait PromptBuilder |
PromptBuilderError
Prompt builder trait for the classify worker (Sprint 47).
| Item |
|---|
pub enum PromptBuilderError |
StubPromptBuilder
Prompt builder trait for the classify worker (Sprint 47).
| Item |
|---|
pub struct StubPromptBuilder |
StubPromptBuilder :: async fn build(& self, _pool : & PgPool, _job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError> |
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
application_classify
apiapi::classify_adminservicesservices::classifyworkersworkers::classify_workerworkers::prompt_builder
flowchart TD n_application_classify["application_classify"] n_application_classify --> n_api["api"] n_api --> n_api__classify_admin["classify_admin"] n_application_classify --> n_services["services"] n_services --> n_services__classify["classify"] n_application_classify --> n_workers["workers"] n_workers --> n_workers__classify_worker["classify_worker"] n_workers --> n_workers__prompt_builder["prompt_builder"]
Public surface
`crate root`
| Item | What it is |
|---|---|
pub struct ClassifyModule | — |
ClassifyModule :: fn new() -> Self | — |
ClassifyModule :: fn name(& self) -> & 'static str | — |
ClassifyModule :: fn version(& self) -> & 'static str | — |
ClassifyModule :: fn migrations(& self) -> Vec <MigrationSet> | — |
ClassifyModule :: async fn migrate_pending(& self, pool : & PgPool) -> Result <u32, MigrationError> | — |
`api`
| Item | What it is |
|---|---|
fn admin_router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, | Compose all admin-facing classify routers (classify jobs/handlers + application-ai's AI-settings credential management) into one router, generic over S. |
`api::classify_admin`
| Item | What it is |
|---|---|
fn router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, | — |
`services::classify`
| Item | What it is |
|---|---|
pub enum ClassifyError | — |
pub struct Classification | — |
pub struct ClassifyJob | — |
pub struct EnqueueRequest | — |
async fn enqueue(pool : & PgPool, req : EnqueueRequest) -> Result <ClassifyJob, ClassifyError> | Enqueue a new pending job |
async fn get_job(pool : & PgPool, job_id : Uuid) -> Result <ClassifyJob, ClassifyError> | — |
async fn next_pending(pool : & PgPool, handler_key : & str, limit : i64,) -> Result <Vec <ClassifyJob>, ClassifyError> | — |
async fn mark_running(pool : & PgPool, job_id : Uuid) -> Result <(), ClassifyError> | — |
async fn complete(pool : & PgPool, job_id : Uuid, result : serde_json::Value, confidence : Option <f32>, source_prompt_template_id : Option <Uuid>, source_prompt_version_id : Option <Uuid>,) -> Result <Classification, ClassifyError> | Complete a running job with the classification result |
async fn fail(pool : & PgPool, job_id : Uuid, error : & str) -> Result <(), ClassifyError> | — |
async fn latest_for(pool : & PgPool, tenant_id : Uuid, entity_type : & str, entity_id : Uuid, classification_type : & str,) -> Result <Option <Classification>, ClassifyError> | — |
async fn list_for_entity(pool : & PgPool, tenant_id : Uuid, entity_type : & str, entity_id : Uuid,) -> Result <Vec <Classification>, ClassifyError> | List ALL active classification types for an entity (each classification_type returns its single canonical row). |
pub struct PromptTemplate | — |
pub struct CreatePromptTemplateInput | — |
async fn create_prompt_template(pool : & PgPool, input : CreatePromptTemplateInput,) -> Result <PromptTemplate, ClassifyError> | — |
async fn list_prompt_templates(pool : & PgPool, prompt_kind : Option <& str>,) -> Result <Vec <PromptTemplate>, ClassifyError> | — |
async fn get_prompt_template(pool : & PgPool, id : Uuid) -> Result <PromptTemplate, ClassifyError> | — |
async fn get_active_prompt_text(pool : & PgPool, tenant_id : Uuid, handler_key : & str,) -> Result <Option <(String, String, Option <i32>)>, ClassifyError> | Active prompt content for a given handler_key (Sprint 47) |
`workers::classify_worker`
| Item | What it is |
|---|---|
pub struct ClassifyWorkerConfig | — |
ClassifyWorkerConfig :: fn new(handler_key : impl Into <String>, provider_name : impl Into <String>) -> Self | — |
ClassifyWorkerConfig :: fn with_prompt_builder(mut self, pb : Arc <dyn PromptBuilder>) -> Self | Override the prompt builder (e.g |
async fn run_classify_worker(pool : PgPool, provider : Arc <dyn AiProvider>, config : ClassifyWorkerConfig, shutdown : CancellationToken,) | Run the classify worker until the cancellation token fires |
`workers::prompt_builder`
| Item | What it is |
|---|---|
pub enum PromptBuilderError | — |
pub trait PromptBuilder | — |
pub struct DefaultPromptBuilder | Default impl |
DefaultPromptBuilder :: fn default() -> Self | — |
DefaultPromptBuilder :: async fn build(& self, pool : & PgPool, job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError> | — |
pub struct StubPromptBuilder | Returns the same CompletionRequest for every job |
StubPromptBuilder :: async fn build(& self, _pool : & PgPool, _job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError> | — |
pub struct InlinePromptBuilder | Wraps a caller-supplied async closure |
InlinePromptBuilder :: fn new <F>(f : F) -> Self where F : for <'a> Fn(& 'a PgPool, & 'a ClassifyJob,) -> futures_util::future::BoxFuture <'a, Result <CompletionRequest, PromptBuilderError>,> + Send + Sync + 'static, | — |
InlinePromptBuilder :: async fn build(& self, pool : & PgPool, job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError> | — |
No pub use re-exports: every item above is declared in this crate.
Boundary
Reaches into infrastructure, platform.
Shares tier application with 120 other crates: application-agreements, application-ai, application-analytics, application-approvals, application-assessments, application-audit-log, application-auth, application-billing, … (120 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) | application |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/application/classify |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_application["application"] --> n_infrastructure["infrastructure"] n_application["application"] --> n_platform["platform"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `application-ai` | application | no | always |
| `application-core` | application | no | always |
| `infrastructure-ai` | infrastructure | no | always |
| `platform-dto` | platform | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
axum | ^0.7 | multipart | no | always |
chrono | ^0.4 | serde | no | always |
futures-util | ^0.3 | — | no | always |
rust_decimal | ^1 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
sqlx | ^0.8 | runtime-tokio, postgres, chrono, uuid, json | no | always |
thiserror | ^2 | — | no | always |
tokio | ^1 | full | no | always |
tokio-util | ^0.7 | rt | no | always |
tracing | ^0.1 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development. None.
Build. None.
Depended on by. Nothing in this workspace.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR SELF["application-classify"] SELF -->|runtime| n_application_ai["application-ai"] SELF -->|runtime| n_application_core["application-core"] SELF -->|runtime| n_infrastructure_ai["infrastructure-ai"] SELF -->|runtime| n_platform_dto["platform-dto"] 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 | application_classify | `src/lib.rs` |
| test | pg_forge_classify | `tests/pg_forge_classify.rs` |
Error model
| Error type | Named by |
|---|---|
ClassifyError | complete, create_prompt_template, enqueue, fail, get_active_prompt_text, get_job, … (12 total) |
PromptBuilderError | declared, no public signature returns it |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | yes |
| async runtime | yes |
| database access | yes |
| network I/O | yes |
| unsafe code | none detected |
| environment variables | yes |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
| Variable | Read in |
|---|---|
CARGO_PKG_VERSION | src/lib.rs |
Related capabilities
No workspace crate depends on this one.
Verification
| Kind | Count |
|---|---|
| Unit tests | 1 |
| Integration tests | 1 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 1 | 0 | 0 |
api | 1 | 0 | 0 |
api::classify_admin | 1 | 0 | 0 |
services::classify | 18 | 0 | 0 |
workers::classify_worker | 2 | 0 | 0 |
workers::prompt_builder | 5 | 0 | 0 |
What the tests establish, by name:
migrate_pending_creates_classifications_and_classify_jobs_tables—tests/pg_forge_classify.rstest_module_migrations_non_empty—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 10 | 40 |
Public modules with a //! block | 5 | 7 |
pie showData
title Public items with rustdoc
"Documented" : 10
"No rustdoc detected" : 30
Metrics
| Metric | Value |
|---|---|
| Rust source files | 8 |
| Source lines | 1080 |
| Code lines | 787 |
| Public API items | 40 |
| Public modules | 7 |
| Tests | 2 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 17 |
| Workspace reverse dependencies | 0 |
pie showData
title Public API by kind
"enum" : 2
"function" : 15
"method" : 12
"struct" : 10
"trait" : 1
pie showData
title Rust source composition
"Code" : 787
"Blank or comment" : 293
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.