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