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//!
27//! ## Workflows
28//! - `GET /api/v1/workflows` — List registered workflows
29//!
30//! ## Statistics
31//! - `GET /api/v1/stats` — Aggregate statistics (total runs, success rate, cost, etc.)
32//!
33//! ## Events (SSE)
34//! - `GET /api/v1/events` — Server-Sent Events stream for real-time updates
35//!
36//! # Quick start
37//!
38//! ```no_run
39//! use ironflow_api::prelude::*;
40//! use ironflow_api::routes::{RouterConfig, create_router};
41//! use ironflow_store::prelude::*;
42//! use ironflow_engine::engine::Engine;
43//! use ironflow_core::providers::claude::ClaudeCodeProvider;
44//! use ironflow_auth::jwt::JwtConfig;
45//! use std::sync::Arc;
46//!
47//! # async fn example() {
48//! let store: Arc<dyn Store> = Arc::new(InMemoryStore::new());
49//! let provider = Arc::new(ClaudeCodeProvider::new());
50//! let engine = Arc::new(Engine::new(store.clone(), provider));
51//! let jwt_config = Arc::new(JwtConfig {
52//! secret: "your-secret-key".to_string(),
53//! access_token_ttl_secs: 900,
54//! refresh_token_ttl_secs: 604800,
55//! cookie_domain: None,
56//! cookie_secure: false,
57//! });
58//! let broadcaster = ironflow_api::sse::SseBroadcaster::new();
59//! let state = AppState::new(store, engine, jwt_config, "token".to_string(), broadcaster.sender());
60//! let app = create_router(state, RouterConfig::default());
61//!
62//! let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
63//! .await
64//! .unwrap();
65//! axum::serve(listener, app).await.unwrap();
66//! # }
67//! ```
68
69pub mod actor;
70pub mod config;
71#[cfg(feature = "dashboard")]
72pub mod dashboard;
73pub mod entities;
74pub mod error;
75pub mod middleware;
76#[cfg(feature = "openapi")]
77pub mod openapi;
78pub mod purger;
79pub mod rate_limit;
80pub mod reaper;
81pub mod response;
82pub mod routes;
83pub mod sse;
84pub mod state;
85
86/// Convenience re-exports for common API usage.
87pub mod prelude {
88 pub use crate::error::ApiError;
89 pub use crate::response::{ApiMeta, ApiResponse, ok, ok_paged};
90 pub use crate::routes::{RouterConfig, create_router};
91 pub use crate::state::AppState;
92 pub use ironflow_store::store::Store;
93}
94
95pub use routes::{RouterConfig, create_router};
96pub use state::AppState;