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