application tier

application-classify

Forge classify module — AI classification job queue + worker + AI credential storage. Sprint 59.

Forge classify module — AI classification job queue + worker + AI credential storage. Sprint 59.

Tierapplication
Roleunclassified (baselined)
Pathcrates/application/classify
Edition2024
Targetsapplication_classify, pg_forge_classify
Public items40 across 7 modules
Tests2

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

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`

ItemWhat 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`

ItemWhat 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`

ItemWhat it is
fn router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>,

`services::classify`

ItemWhat 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`

ItemWhat 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>) -> SelfOverride 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`

ItemWhat it is
pub enum PromptBuilderError
pub trait PromptBuilder
pub struct DefaultPromptBuilderDefault impl
DefaultPromptBuilder :: fn default() -> Self
DefaultPromptBuilder :: async fn build(& self, pool : & PgPool, job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError>
pub struct StubPromptBuilderReturns the same CompletionRequest for every job
StubPromptBuilder :: async fn build(& self, _pool : & PgPool, _job : & ClassifyJob,) -> Result <CompletionRequest, PromptBuilderError>
pub struct InlinePromptBuilderWraps 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)
Locationcrates/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.

CrateTierOptionalOnly on
`application-ai`applicationnoalways
`application-core`applicationnoalways
`infrastructure-ai`infrastructurenoalways
`platform-dto`platformnoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
axum^0.7multipartnoalways
chrono^0.4serdenoalways
futures-util^0.3noalways
rust_decimal^1serdenoalways
serde^1derivenoalways
serde_json^1noalways
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonnoalways
thiserror^2noalways
tokio^1fullnoalways
tokio-util^0.7rtnoalways
tracing^0.1noalways
uuid^1v4, v7, serde, jsnoalways

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

KindNameSource
libapplication_classify`src/lib.rs`
testpg_forge_classify`tests/pg_forge_classify.rs`

Error model

Error typeNamed by
ClassifyErrorcomplete, create_prompt_template, enqueue, fail, get_active_prompt_text, get_job, … (12 total)
PromptBuilderErrordeclared, no public signature returns it

Operational characteristics

PropertyEvidence
async public surfaceyes
async runtimeyes
database accessyes
network I/Oyes
unsafe codenone detected
environment variablesyes

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

VariableRead in
CARGO_PKG_VERSIONsrc/lib.rs

No workspace crate depends on this one.

Verification

KindCount
Unit tests1
Integration tests1
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root100
api100
api::classify_admin100
services::classify1800
workers::classify_worker200
workers::prompt_builder500

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc1040
Public modules with a //! block57
pie showData
    title Public items with rustdoc
    "Documented" : 10
    "No rustdoc detected" : 30

Metrics

MetricValue
Rust source files8
Source lines1080
Code lines787
Public API items40
Public modules7
Tests2
Examples0
Cargo features0
Direct runtime dependencies17
Workspace reverse dependencies0
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.

All application · Manual