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//! # Quick start
33//!
34//! ```no_run
35//! use ironflow_api::prelude::*;
36//! use ironflow_api::routes::create_router;
37//! use ironflow_store::prelude::*;
38//! use ironflow_engine::engine::Engine;
39//! use ironflow_core::providers::claude::ClaudeCodeProvider;
40//! use ironflow_auth::jwt::JwtConfig;
41//! use std::sync::Arc;
42//!
43//! # async fn example() {
44//! let store = Arc::new(InMemoryStore::new());
45//! let user_store: Arc<dyn ironflow_store::user_store::UserStore> = Arc::new(InMemoryStore::new());
46//! let provider = Arc::new(ClaudeCodeProvider::new());
47//! let engine = Arc::new(Engine::new(store.clone(), provider));
48//! let jwt_config = Arc::new(JwtConfig {
49//! secret: "your-secret-key".to_string(),
50//! access_token_ttl_secs: 900,
51//! refresh_token_ttl_secs: 604800,
52//! cookie_domain: None,
53//! cookie_secure: false,
54//! });
55//! let state = AppState { store, user_store, engine, jwt_config, worker_token: "token".to_string() };
56//! let app = create_router(state, None);
57//!
58//! let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
59//! .await
60//! .unwrap();
61//! axum::serve(listener, app).await.unwrap();
62//! # }
63//! ```
64
65#[cfg(feature = "dashboard")]
66pub mod dashboard;
67pub mod entities;
68pub mod error;
69pub mod middleware;
70pub mod response;
71pub mod routes;
72pub mod state;
73
74/// Convenience re-exports for common API usage.
75pub mod prelude {
76 pub use crate::error::ApiError;
77 pub use crate::response::{ApiMeta, ApiResponse, ok, ok_paged};
78 pub use crate::routes::create_router;
79 pub use crate::state::AppState;
80}
81
82pub use routes::create_router;
83pub use state::AppState;