API Design Guide
Overview
This template provides a pure REST API gateway for Temporal workflows with foundry-temporal integration. It handles workflow management operations but does NOT execute workflows - that requires separate worker services.
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Client App │───▶│ Workflow API │───▶│ Temporal Server │
│ (React/etc) │ │ (FastAPI) │ │ (External) │
│ │ │ │ │ │
│ │ │ - REST endpoints │ │ ┌─────────────┐ │
│ │ │ - foundry-temporal│ │ │ Worker │ │
│ │ │ - Health checks │ │ │ Services │ │
│ │ │ - Error handling │ │ │ (Separate) │ │
└─────────────────┘ └──────────────────┘ └─┴─────────────┴─┘
Key Principle: API gateway communicates with Temporal server. Worker services (deployed separately) execute workflows.
Core Components
FastAPI Application (src/main.py)
- FastAPI setup with foundry-temporal structured logging
- Application lifespan management with proper startup/shutdown
- Foundry-specific error handlers for WorkflowError, ValidationError, ConfigurationError
- Customize title, description, middleware as needed
Workflow Router (src/routers/workflows.py)
- POST /workflows/start - Start new workflow executions with validation
- GET /workflows/{id}/status - Get comprehensive workflow status and results
- POST /workflows/{id}/approve - Explicit approve endpoint for MyWorkflow HITL step
- POST /workflows/{id}/signal - Generic signal endpoint for arbitrary signals
- GET /workflows/{id}/query - Query workflow state information
- GET /workflows/ - List workflows with filtering and pagination
Health Router (src/routers/health.py)
- GET /health - Basic API health check
- GET /health/ready - Kubernetes readiness probe with Temporal connectivity
- GET /health/detailed - Comprehensive health check with all dependencies
- GET /health/temporal - Temporal-specific connectivity check
Models (src/models.py)
- Template request/response models
- Customize for your workflow's input/output data structures
Dependencies (src/dependencies.py)
- Temporal client connection management
- Add authentication, rate limiting as needed
Configuration (src/config.py)
- Environment-based configuration
- Add workflow-specific settings
Customization Guidelines
- Workflow Registration: Update
get_available_workflows()inworkflows.pywith your workflow names (currently registersMyWorkflow) - Workflow Types: Update
WorkflowStartRequestwith your specific workflow parameters - Signal Endpoints: Add explicit endpoints for each signal (see
/approve). The generic/signalendpoint is kept for flexibility. - Health Checks: Add checks for your workflow's dependencies
- Authentication: Implement in
dependencies.pyif required - Middleware: Add CORS, logging, rate limiting in
main.py
Template Integration
This template includes a reference to the 3-step workflow from temporal-workflow-worker-starter:
MyWorkflow- 3-step HITL workflow demonstrating:- Step 1:
my_activity— initial data processing - Step 2:
call_strands_agent— foundry-temporal-agents integration with retry policy - Step 3:
approvesignal — Human-in-the-Loop approval gate (viaHILSignalsMixin) - State management: Progress tracking (
_progress,_status) throughout the 3 steps
- Step 1:
This single workflow covers both key design document requirements, providing teams with a complete foundation for building production workflows.
Teams should replace this with their actual workflow names after deploying worker services.
Foundry Integration
This template uses foundry-temporal for:
- Structured logging with
get_logger() - Standard observability patterns
- Temporal client best practices
Development Workflow
- Customize models and endpoints for your workflow
- Update configuration for your environment
- Add tests for your specific endpoints
- Update documentation for your API
- Deploy using provided Docker/compose setup