ironflow_api/lib.rs
1//! # ironflow-api
2//!
3//! REST API crate for the **ironflow** workflow engine. Provides endpoints for
4//! querying workflow runs, managing their lifecycle, and viewing aggregate statistics.
5//!
6//! # Architecture
7//!
8//! - `actor.rs` — Maps an authenticated caller to a persisted run author
9//! - `entities/` — DTOs and query parameter types (public API contract)
10//! - `routes/` — One file per route handler
11//! - `error.rs` — Typed API errors mapped to HTTP status codes
12//! - `response.rs` — Standard response envelope
13//! - `state.rs` — Shared application state
14//!
15//! # API Endpoints
16//!
17//! ## Health check
18//! - `GET /api/v1/health-check` — Liveness probe, always returns 200 OK
19//!
20//! ## Runs
21//! - `GET /api/v1/runs` — List runs with optional filtering and pagination
22//! - `POST /api/v1/runs` — Trigger a workflow
23//! - `GET /api/v1/runs/:id` — Get run details and steps
24//! - `POST /api/v1/runs/:id/cancel` — Cancel a pending or running run
25//! - `POST /api/v1/runs/:id/retry` — Retry a failed run (creates new run)
26//! - `POST /api/v1/runs/:id/replay` -- Replay a finished run on the current handler version (creates new run)
27//!
28//! ## Workflows
29//! - `GET /api/v1/workflows` — List registered workflows
30//!
31//! ## Statistics
32//! - `GET /api/v1/stats` — Aggregate statistics (total runs, success rate, cost, etc.)
33//!
34//! ## Events (SSE)
35//! - `GET /api/v1/events` — Server-Sent Events stream for real-time updates
36//!
37//! # Quick start
38//!
39//! ```no_run
40//! use ironflow_api::prelude::*;
41//! use ironflow_api::routes::{RouterConfig, create_router};
42//! use ironflow_store::prelude::*;
43//! use ironflow_engine::engine::Engine;
44//! use ironflow_core::providers::claude::ClaudeCodeProvider;
45//! use ironflow_auth::jwt::JwtConfig;
46//! use std::sync::Arc;
47//!
48//! # async fn example() {
49//! let store: Arc<dyn Store> = Arc::new(InMemoryStore::new());
50//! let provider = Arc::new(ClaudeCodeProvider::new());
51//! let engine = Arc::new(Engine::new(store.clone(), provider));
52//! let jwt_config = Arc::new(JwtConfig {
53//! secret: "your-secret-key".to_string(),
54//! access_token_ttl_secs: 900,
55//! refresh_token_ttl_secs: 604800,
56//! cookie_domain: None,
57//! cookie_secure: false,
58//! });
59//! let broadcaster = ironflow_api::sse::SseBroadcaster::new();
60//! let state = AppState::new(store, engine, jwt_config, "token".to_string(), broadcaster.sender());
61//! let app = create_router(state, RouterConfig::default());
62//!
63//! let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
64//! .await
65//! .unwrap();
66//! axum::serve(listener, app).await.unwrap();
67//! # }
68//! ```
69
70pub mod actor;
71pub mod config;
72#[cfg(feature = "dashboard")]
73pub mod dashboard;
74pub mod entities;
75pub mod error;
76pub mod escalator;
77pub mod middleware;
78#[cfg(feature = "openapi")]
79pub mod openapi;
80pub mod purger;
81pub mod rate_limit;
82pub mod reaper;
83pub mod response;
84pub mod routes;
85pub mod schedule_sync;
86pub mod schedule_ticker;
87pub mod sse;
88pub mod state;
89
90/// Convenience re-exports for common API usage.
91pub mod prelude {
92 pub use crate::error::ApiError;
93 pub use crate::response::{ApiMeta, ApiResponse, ok, ok_paged};
94 pub use crate::routes::{RouterConfig, create_router};
95 pub use crate::state::AppState;
96 pub use ironflow_store::store::Store;
97}
98
99pub use routes::{RouterConfig, create_router};
100pub use state::AppState;