Skip to main content

pjson_rs/application/
mod.rs

1//! Application layer - Use cases and orchestration
2//!
3//! Implements CQRS pattern with separate command and query handlers.
4//! Orchestrates domain logic and infrastructure concerns.
5
6pub mod commands;
7pub mod dto;
8pub mod handlers;
9pub mod queries;
10pub mod shared;
11
12pub use commands::{
13    BatchGenerateFramesCommand, CloseSessionCommand, CompleteStreamCommand, CreateSessionCommand,
14    CreateStreamCommand, GenerateFramesCommand, StartStreamCommand,
15};
16pub use queries::{
17    FramesResponse, GetActiveSessionsQuery, GetSessionHealthQuery, GetSessionQuery,
18    GetSessionStatsQuery, GetStreamFramesQuery, GetStreamQuery, GetStreamsForSessionQuery,
19    GetSystemStatsQuery, HealthResponse, SearchSessionsQuery, SessionFilters, SessionResponse,
20    SessionSortField, SessionStatsResponse, SessionsResponse, SortOrder, StreamResponse,
21    StreamsResponse, SystemStatsResponse,
22};
23pub use shared::AdjustmentUrgency;
24
25/// Application Result type
26pub type ApplicationResult<T> = Result<T, ApplicationError>;
27
28/// Application-specific errors
29#[derive(Debug, thiserror::Error)]
30pub enum ApplicationError {
31    /// Wraps a domain-layer error that bubbled up to the application boundary.
32    #[error("Domain error: {0}")]
33    Domain(#[from] crate::domain::DomainError),
34
35    /// Input failed validation before any domain logic ran.
36    #[error("Validation error: {0}")]
37    Validation(String),
38
39    /// Caller is not authorized to perform the requested operation.
40    #[error("Authorization error: {0}")]
41    Authorization(String),
42
43    /// A concurrent operation conflicted with the current request.
44    #[error("Concurrency error: {0}")]
45    Concurrency(String),
46
47    /// Requested entity does not exist.
48    #[error("Not found: {0}")]
49    NotFound(String),
50
51    /// Operation conflicted with the current state of the resource.
52    #[error("Conflict: {0}")]
53    Conflict(String),
54
55    /// Generic application-layer logic error not covered by other variants.
56    #[error("Application logic error: {0}")]
57    Logic(String),
58}