backend/openapi-service/README.md
RPA OpenAPI Service is an RPA workflow management service built on FastAPI, providing workflow creation, execution, monitoring, and API key management functions. The service integrates WebSocket real-time communication, MCP (Model Context Protocol) support, Redis caching, request tracing and other modern technology stacks, providing complete API service capabilities for the RPA platform.
The service adopts a clear layered architecture design, specifically designed for RPA workflow management:
app/routers/)workflows.py) - Workflow CRUD operationsexecutions.py) - Workflow execution and status monitoringapi_keys.py) - API key generation and validationwebsocket.py) - Real-time communication and status pushstreamable_mcp.py) - Model Context Protocol supportapp/services/)workflow.py) - Workflow business logic processingexecution.py) - Workflow execution logicwebsocket.py) - Real-time communication managementapi_key.py) - Key generation and validation logicapp/schemas/)workflow.py) - Workflow data structure definitionsexecution.py) - Execution status and result definitionsapi_key.py) - Key-related data structuresapp/dependencies/) - User authentication, service dependency managementapp/middlewares/) - Request tracing middlewareapp/internal/) - Management and maintenance interfacesapp/config.py) - Environment variables and configuration managementapp/redis.py) - Async Redis connection poolapp/logger.py) - Unified logging configuration| Component | Technology | Version Requirement |
|---|---|---|
| Backend Framework | FastAPI | >=0.115.12 |
| Python | Python | >=3.11 |
| Database | MySQL + SQLAlchemy | >=2.0.41 |
| Cache | Redis | >=6.1.0 |
| Async Support | asyncio + aiomysql | >=0.2.10 |
| Config Management | Pydantic Settings | >=2.9.1 |
| Containerization | Docker + Docker Compose | - |
| Testing Framework | pytest + pytest-asyncio | >=8.3.5 |
| Code Quality | Ruff | >=0.11.11 |
| Dependency Management | uv | - |
rpa-openapi-service/
โโโ app/ # Main application directory
โ โโโ main.py # FastAPI application entry point
โ โโโ config.py # Configuration management
โ โโโ redis.py # Redis connection pool management
โ โโโ logger.py # Logging configuration
โ โโโ dependencies/ # Dependency injection modules
โ โ โโโ __init__.py # Common dependency injection
โ โโโ schemas/ # Pydantic data schemas
โ โ โโโ workflow.py # Workflow data structures
โ โ โโโ execution.py # Execution status and results
โ โ โโโ api_key.py # API key data structures
โ โโโ routers/ # API routes
โ โ โโโ workflows.py # Workflow management routes
โ โ โโโ executions.py # Execution management routes
โ โ โโโ api_keys.py # API key management routes
โ โ โโโ websocket.py # WebSocket communication routes
โ โ โโโ streamable_mcp.py # MCP protocol support
โ โโโ services/ # Business logic services
โ โ โโโ workflow.py # Workflow service
โ โ โโโ execution.py # Execution service
โ โ โโโ api_key.py # API key service
โ โ โโโ websocket.py # WebSocket service
โ โโโ middlewares/ # Middlewares
โ โ โโโ tracing.py # Request tracing middleware
โ โโโ internal/ # Internal management interfaces
โ โโโ admin.py # Admin interface
โโโ tests/ # Test code
โ โโโ conftest.py # Test configuration
โ โโโ test_main.py # Main application tests
โ โโโ routers/ # Route tests
โโโ logs/ # Log directory
โโโ Dockerfile # Docker image build
โโโ pyproject.toml # Project dependency configuration
โโโ uv.lock # uv dependency lock file
โโโ README.md # Project documentation
/workflows)/workflows/upsert) - Support for workflow creation and update/workflows/{project_id}) - Query workflow details by project ID/workflows) - Paginated workflow list query/workflows/{project_id}) - Delete specified workflow/executions)/executions) - Create workflow execution task/executions/{execution_id}) - Get execution status and results/executions) - Paginated execution record query/executions/{execution_id}/cancel) - Cancel running workflow/api-keys)/api-keys) - Create new API key/api-keys) - Query user's API key list/api-keys/{key_id}) - Delete specified API key/ws)/mcp)# Install using pip
pip install -e .
# Or use uv (recommended)
uv sync
It is recommended to use uv for dependency management. The
uv.lockfile has locked dependency versions to ensure environment consistency.
There are three configuration files, sorted by priority from low to high: .env.default < .env < .env.local, where .env.local is only used for local debugging and should never be used in production.
Create .env file and configure necessary environment variables:
# Database configuration
DATABASE_URL=mysql+aiomysql://username:password@localhost:3306/rpa_openapi
# Redis configuration
REDIS_URL=redis://localhost:6379/0
# Application name
APP_NAME="RPA OpenAPI Service"
# Use uvicorn directly (development environment)
uvicorn app.main:app --reload --host 0.0.0.0 --port 8020
# Or use uv
uv run python run.py dev
Visit http://localhost:8020/docs to view API documentation.
FastAPI automatically generates interactive documentation for your API:
/docs - Suitable for development and debugging/redoc - More suitable for reading and sharing# Start test database
docker-compose -f docker-compose.test.yaml up -d
# Run all tests
pytest
# Run specific test file
pytest tests/routers/test_workflows.py
# Run tests with coverage
pytest --cov=app
# Format code
ruff format
# Check code quality
ruff check
# Fix auto-fixable issues
ruff check --fix
# Real-time view of application logs
tail -f logs/app.log
The service uses layered configuration files that can be created and modified as needed:
.env.default - Default configuration, committed to version control.env - Environment-specific configuration, customized according to deployment environment.env.local - Local development configuration, not committed to version controlConfiguration loading order: .env.default < .env < .env.local
LOG_LEVEL environment variable (default: INFO)LOG_DIR environment variableEach request is assigned a unique Request ID for easy troubleshooting:
2025-06-06 10:30:15 - app.main - [abc-123-def] - INFO - Root endpoint accessed!
Request ID automatically:
X-Request-IDA: You can specify through environment variables or directly in startup command:
# Specify in command
uvicorn app.main:app --host 0.0.0.0 --port 8020
# Or modify mapping in docker-compose.yml
ports:
- "8020:8020"
A: Consider the following solutions:
--workers 4A: You can monitor through:
/healthA: Recommended production deployment solutions:
If you have any improvement suggestions or questions, welcome to contribute through:
This project is licensed under the MIT License. You are free to use, modify and distribute this code for both personal and commercial projects.