A comprehensive Temporal workflow application built with Python, FastAPI, and Hydra configuration management. This project demonstrates best practices for building scalable, reliable workflow systems.
- Temporal Workflows: Complex workflow orchestration with activities
- FastAPI API: RESTful API for workflow management
- Hydra Configuration: Flexible configuration management with environment overrides
- Comprehensive Logging: Structured logging with Loguru and Rich
- Monitoring: Performance metrics and health checks
- Testing: Unit, integration, and end-to-end tests
- Docker Support: Containerized deployment with Docker Compose
graph TB
subgraph "Client Layer"
A[Web Client] --> B[FastAPI API]
end
subgraph "Application Layer"
B --> C[Workflow Service]
C --> D[Temporal Client]
end
subgraph "Workflow Engine"
D --> E[Temporal Server]
E --> F[Workflow Workers]
F --> G[Activities]
end
subgraph "Data Layer"
G --> H[Database]
G --> I[External APIs]
G --> J[File System]
end
subgraph "Infrastructure"
K[Docker Compose]
L[Redis Cache]
M[PostgreSQL]
end
temporal-practice/
βββ .cursor/ # Cursor IDE rules
βββ conf/ # Hydra configuration
βββ docs/ # Documentation
βββ src/ # Source code
β βββ api/ # FastAPI application
β βββ workflows/ # Temporal workflows
β βββ activities/ # Temporal activities
β βββ workers/ # Temporal workers
β βββ models/ # Pydantic models
β βββ services/ # Business logic
β βββ utils/ # Utilities
βββ tests/ # Test suite
βββ scripts/ # Utility scripts
βββ docker/ # Docker configuration
βββ logs/ # Log files
- Python 3.11+: Core language
- Temporal: Workflow orchestration
- FastAPI: Web framework
- Hydra: Configuration management
- Loguru: Logging
- Rich: Console output
- Pydantic: Data validation
- Pytest: Testing framework
- Docker: Containerization
- Python 3.11+
- Docker and Docker Compose
- Git
-
Clone the repository
git clone <repository-url> cd temporal-practice
-
Install dependencies
# Using uv (recommended) uv pip install -e ".[dev]" # Or using pip pip install -e ".[dev]"
-
Start infrastructure services
make run-docker
-
Run the application
# Start the API server make run-dev # In another terminal, start the worker make run-worker
-
Install pre-commit hooks
pre-commit install
-
Run tests
make test -
Format code
make format
-
Lint code
make lint
curl -X POST "http://localhost:8000/api/v1/workflows/start" \
-H "Content-Type: application/json" \
-d '{
"workflow_type": "complex_workflow",
"input_data": {
"user_id": "user_123",
"data": {"key": "value"}
},
"user_id": "user_123"
}'curl "http://localhost:8000/api/v1/workflows/{workflow_id}/status"curl "http://localhost:8000/api/v1/workflows/{workflow_id}/result"The application uses Hydra for configuration management. Configuration files are located in the conf/ directory:
conf/config.yaml: Main configurationconf/config/: Configuration modulesconf/env/: Environment-specific overrides
# Required
ENVIRONMENT=development
DATABASE_URL=postgresql://user:password@localhost:5432/temporal_db
REDIS_URL=redis://localhost:6379/0
TEMPORAL_HOST=localhost:7233
# Optional
SECRET_KEY=your-secret-key
LOG_LEVEL=INFOmake test# Unit tests only
make test-unit
# Integration tests only
make test-integration
# End-to-end tests only
make test-e2emake test
# Coverage report will be generated in htmlcov/- Basic:
GET /health - Detailed:
GET /health/detailed
- Workflow execution metrics
- Activity performance metrics
- API request metrics
- System resource metrics
- Structured JSON logs
- Rich console output
- Log rotation and retention
- Correlation IDs for tracing
make buildmake run-dockermake stop-dockerOnce the application is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Format and lint your code
- Submit a pull request
# Create feature branch
git checkout -b feature/your-feature-name
# Make changes and commit often
git add .
git commit -m "feat: add new workflow feature"
# Push changes
git push origin feature/your-feature-nameThis project follows strict coding standards defined in .cursor/rules/:
- Python Standards: Type hints, docstrings, error handling
- Temporal Patterns: Workflow and activity best practices
- FastAPI Standards: API design and testing patterns
- Configuration: Hydra configuration management
- Logging: Structured logging and monitoring
- Testing: Comprehensive test coverage
-
Temporal Server Connection
# Check if Temporal server is running docker-compose ps temporal -
Database Connection
# Check database connectivity docker-compose exec postgresql psql -U temporal -d temporal
-
Port Conflicts
# Check if ports are in use lsof -i :8000 # API server lsof -i :7233 # Temporal server
# Application logs
make logs
# Worker logs
make logs-worker
# All services
docker-compose logs -fThis project is licensed under the MIT License - see the LICENSE file for details.