[!CAUTION] These design documents are generated by AI and may not be fully accurate or complete. They are intended to provide a starting point for understanding the system architecture and design patterns used in the template-fastapi application.
External API Specification
Overview
The template-fastapi application provides a comprehensive REST API built with FastAPI, integrating multiple Azure cloud services to deliver enterprise-grade functionality for content management, AI-powered conversations, and data processing.
API Services
1. Items Management API
Base Path: /items/
Purpose: Core CRUD operations for item management with Azure CosmosDB backend.
Endpoints:
GET /items/
- List all items with paginationGET /items/{item_id}
- Retrieve specific itemPOST /items/
- Create new itemPUT /items/{item_id}
- Update existing itemDELETE /items/{item_id}
- Delete itemGET /items/search/?q={query}
- Search items by text
Data Model:
{
"id": "string",
"name": "string",
"description": "string",
"price": 0.0,
"tax": 0.0
}
2. File Management API
Base Path: /files/
Purpose: File upload, storage, and retrieval using Azure Blob Storage.
Endpoints:
GET /files/
- List files with optional prefix filterPOST /files/upload
- Upload single filePOST /files/upload-multiple
- Upload multiple filesGET /files/{filename}
- Download fileGET /files/{filename}/info
- Get file metadataDELETE /files/{filename}
- Delete single fileDELETE /files/
- Delete multiple files (request body)
Features:
- Automatic content type detection
- File metadata tracking
- Bulk operations support
3. Restaurant Discovery API
Base Path: /foodies/restaurants/
Purpose: Restaurant management with geospatial search capabilities.
Endpoints:
GET /restaurants/
- List restaurants with paginationGET /restaurants/{id}
- Get restaurant detailsPOST /restaurants/
- Create new restaurantPUT /restaurants/{id}
- Update restaurantDELETE /restaurants/{id}
- Delete restaurantGET /restaurants/search/?query={text}
- Vector-based text searchGET /restaurants/near/?latitude={lat}&longitude={lng}
- Geospatial proximity search
Search Features:
- Text-based vector search using embeddings
- Location-based proximity search with configurable radius
- Pagination support for all list operations
4. Speech Transcription API
Base Path: /speeches/transcriptions/
Purpose: Batch audio transcription using Azure AI Speech Services.
Endpoints:
GET /transcriptions/
- List all transcription jobsPOST /transcriptions/
- Create transcription jobGET /transcriptions/{job_id}
- Get job statusGET /transcriptions/{job_id}/files
- List result filesGET /transcriptions/{job_id}/result?file_url={url}
- Get transcription resultDELETE /transcriptions/{job_id}
- Delete job
Workflow:
- Submit audio URLs for batch processing
- Monitor job status (Created → Running → Succeeded/Failed)
- Retrieve transcription results when complete
5. Agent-Based Conversation API
LangGraph Agents
Base Path: /agents/langgraph/
Purpose: AI agents with custom tools for mathematical calculations, web search, and time queries.
Endpoints:
GET /tools
- List available agent tools
Available Tools:
- Calculator: Mathematical expression evaluation
- Current Time: Timezone-aware time queries
- Search: Web search capabilities
Azure AI Foundry Agents
Base Path: /agents/azure-ai-foundry/
Purpose: Thread-based conversational AI using Azure AI Foundry platform.
Agent Management:
GET /
- List agentsPOST /
- Create agentGET /{agent_id}
- Get agent detailsDELETE /{agent_id}
- Delete agentPOST /{agent_id}/chat
- Chat with agent
Thread Management:
GET /threads/
- List conversation threadsPOST /threads/
- Create new threadGET /threads/{thread_id}
- Get thread detailsDELETE /threads/{thread_id}
- Delete thread
6. Real-time Chat Interface
Base Path: /chats/
Purpose: WebSocket-based real-time chat with HTML interface.
Endpoints:
GET /
- Chat interface (HTML page)WebSocket /ws/{client_id}
- Real-time messaging
Features:
- Real-time bidirectional communication
- Multi-client support
- Agent integration capabilities
7. Demo & Testing API
Base Path: /demos/
Purpose: Demonstration endpoints for testing and monitoring.
Endpoints:
GET /roll_dice
- Random dice roll (1-6)GET /flaky/{failure_rate}
- Configurable failure simulation (0-100%)GET /flaky/exception
- Guaranteed exception endpointGET /heavy_sync/{sleep_ms}
- Simulated heavy processing
Azure Cloud Services Integration
Azure CosmosDB
- Purpose: Primary database for items and restaurant data
- Features: Global distribution, automatic scaling, vector search support
- Configuration: Connection string in
AZURE_COSMOSDB_CONNECTION_STRING
Azure Blob Storage
- Purpose: File storage and management
- Features: Hierarchical namespace, metadata support, CDN integration
- Configuration: Connection string in
AZURE_BLOB_STORAGE_CONNECTION_STRING
Azure OpenAI Service
- Purpose: LLM capabilities for agents and embeddings
- Models: GPT-4o for chat, text-embedding-3-small for search
- Configuration: Endpoint and API key in environment variables
Azure AI Speech
- Purpose: Batch audio transcription
- Features: Multi-language support, custom vocabulary, speaker diarization
- Configuration: API key and endpoint in environment variables
Azure AI Foundry
- Purpose: Enterprise AI agent platform
- Features: Thread-based conversations, tool integration, model selection
- Configuration: Project endpoint and API key
Azure Application Insights
- Purpose: Application monitoring and telemetry
- Features: Request tracing, performance monitoring, custom metrics
- Configuration: Connection string enables automatic instrumentation
Authentication & Security
Current Implementation
- No authentication required (template/development setup)
- Internal service-to-service authentication via API keys
- Azure services authenticate via connection strings
Production Recommendations
- Implement OAuth 2.0 / JWT authentication
- Use Azure Active Directory integration
- Enable API rate limiting
- Configure CORS policies
- Use Azure Key Vault for secrets management
Error Handling
Standard HTTP Status Codes
200
- Success201
- Created400
- Bad Request (validation errors)404
- Not Found422
- Unprocessable Entity (Pydantic validation)500
- Internal Server Error
Error Response Format
{
"detail": "Error description in Japanese/English",
"type": "error_type",
"loc": ["field", "path"] // For validation errors
}
Monitoring & Observability
Structured Logging
- Configurable log levels via
LOG_LEVEL
environment variable - JSON-structured logs for production deployment
- Request/response logging with correlation IDs
Metrics & Tracing
- OpenTelemetry integration with Azure Application Insights
- Custom metrics for business operations
- Distributed tracing across service boundaries
Health Checks
- Built-in FastAPI health monitoring
- Azure service dependency health checks
- Container readiness and liveness probes
API Versioning & Compatibility
Current Version
- API Version: 1.0
- No explicit versioning in URLs (future consideration)
- Backward compatibility maintained for minor updates
Future Considerations
- URL-based versioning (
/v1/
,/v2/
) - Header-based versioning
- Feature flags for gradual rollouts