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_store::api_key_store::ApiKeyStore;
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::new(InMemoryStore::new());
49//! let user_store: Arc<dyn ironflow_store::user_store::UserStore> = Arc::new(InMemoryStore::new());
50//! let api_key_store: Arc<dyn ApiKeyStore> = 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, user_store, api_key_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 config;
72#[cfg(feature = "dashboard")]
73pub mod dashboard;
74pub mod entities;
75pub mod error;
76pub mod middleware;
77#[cfg(feature = "openapi")]
78pub mod openapi;
79pub mod rate_limit;
80pub mod response;
81pub mod routes;
82pub mod sse;
83pub mod state;
84
85/// Convenience re-exports for common API usage.
86pub mod prelude {
87 pub use crate::error::ApiError;
88 pub use crate::response::{ApiMeta, ApiResponse, ok, ok_paged};
89 pub use crate::routes::{RouterConfig, create_router};
90 pub use crate::state::AppState;
91}
92
93pub use routes::{RouterConfig, create_router};
94pub use state::AppState;