|
1 |
| -[](https://github.com/ks6088ts-labs/template-fastapi/actions/workflows/test.yaml?query=branch%3Amain) |
2 |
| -[](https://github.com/ks6088ts-labs/template-fastapi/actions/workflows/docker.yaml?query=branch%3Amain) |
3 |
| -[](https://github.com/ks6088ts-labs/template-fastapi/actions/workflows/docker-release.yaml) |
4 |
| -[](https://github.com/ks6088ts-labs/template-fastapi/actions/workflows/ghcr-release.yaml) |
5 |
| -[](https://github.com/ks6088ts-labs/template-fastapi/actions/workflows/github-pages.yaml) |
6 |
| - |
7 | 1 | # template-fastapi
|
8 | 2 |
|
9 |
| -This is a template repository for Python |
| 3 | +A comprehensive FastAPI template with Azure cloud services integration, Agent-based workflows, and multi-service API architecture. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Multiple API Services**: Items management, file operations, restaurant discovery, speech transcription, and agent-based chat |
| 8 | +- **Azure Cloud Integration**: CosmosDB, Blob Storage, OpenAI, AI Speech, and Application Insights |
| 9 | +- **Agent Workflows**: LangGraph and Azure AI Foundry integration for conversational AI |
| 10 | +- **Real-time Communication**: WebSocket-based chat functionality |
| 11 | +- **Comprehensive Logging**: Configurable log levels with structured error handling |
| 12 | +- **Testing & Quality**: 37+ automated tests with logging and monitoring |
| 13 | +- **Container Ready**: Docker support with multi-stage builds |
10 | 14 |
|
11 |
| -## Prerequisites |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +### Prerequisites |
12 | 18 |
|
13 | 19 | - [Python 3.10+](https://www.python.org/downloads/)
|
14 |
| -- [uv](https://docs.astral.sh/uv/getting-started/installation/) |
| 20 | +- [uv](https://docs.astral.sh/uv/getting-started/installation/) (recommended) or pip |
15 | 21 | - [GNU Make](https://www.gnu.org/software/make/)
|
16 | 22 |
|
17 |
| -## Development instructions |
| 23 | +### Installation |
18 | 24 |
|
19 |
| -### Local development |
| 25 | +```bash |
| 26 | +# Clone the repository |
| 27 | +git clone <repository-url> |
| 28 | +cd template-fastapi |
20 | 29 |
|
21 |
| -Use Makefile to run the project locally. |
| 30 | +# Install dependencies |
| 31 | +make install-deps-dev |
22 | 32 |
|
23 |
| -```shell |
24 |
| -# help |
25 |
| -make |
| 33 | +# Copy environment template |
| 34 | +cp .env.template .env |
| 35 | +# Edit .env with your Azure service credentials |
| 36 | +``` |
26 | 37 |
|
27 |
| -# install dependencies for development |
28 |
| -make install-deps-dev |
| 38 | +### Running the Application |
| 39 | + |
| 40 | +```bash |
| 41 | +# Development server with hot reload |
| 42 | +make dev |
| 43 | + |
| 44 | +# Production server |
| 45 | +make run |
29 | 46 |
|
30 |
| -# run tests |
| 47 | +# Run tests |
31 | 48 | make test
|
32 | 49 |
|
33 |
| -# run CI tests |
34 |
| -make ci-test |
| 50 | +# View documentation |
| 51 | +make docs-serve |
| 52 | +``` |
| 53 | + |
| 54 | +The API will be available at http://localhost:8000 with interactive documentation at http://localhost:8000/docs. |
| 55 | + |
| 56 | +## API Services |
| 57 | + |
| 58 | +### Core Services |
| 59 | +- **Items API** (`/items/`): CRUD operations for item management |
| 60 | +- **Files API** (`/files/`): File upload, download, and management with Azure Blob Storage |
| 61 | +- **Restaurants API** (`/foodies/`): Restaurant discovery with geospatial search |
| 62 | +- **Speech API** (`/speeches/`): Batch transcription jobs using Azure AI Speech |
| 63 | + |
| 64 | +### Agent Services |
| 65 | +- **LangGraph Agents** (`/agents/langgraph/`): AI agents with custom tools |
| 66 | +- **Azure AI Foundry** (`/agents/azure-ai-foundry/`): Thread-based conversations |
| 67 | +- **Chat Interface** (`/chats/`): Real-time WebSocket chat with agent integration |
| 68 | + |
| 69 | +### Demo & Utilities |
| 70 | +- **Demo Endpoints** (`/demos/`): Dice rolling, flaky endpoints for testing |
| 71 | +- **Health & Monitoring**: Application Insights integration with OpenTelemetry |
| 72 | + |
| 73 | +## Configuration |
| 74 | + |
| 75 | +### Environment Variables |
| 76 | + |
| 77 | +Key configuration options in `.env`: |
| 78 | + |
| 79 | +```bash |
| 80 | +# Logging |
| 81 | +LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR, CRITICAL |
| 82 | + |
| 83 | +# Azure OpenAI |
| 84 | +AZURE_OPENAI_ENDPOINT=https://<name>.openai.azure.com/ |
| 85 | +AZURE_OPENAI_API_KEY=<key> |
| 86 | +AZURE_OPENAI_MODEL_CHAT=gpt-4o |
| 87 | + |
| 88 | +# Azure Storage & Database |
| 89 | +AZURE_COSMOSDB_CONNECTION_STRING=<connection-string> |
| 90 | +AZURE_BLOB_STORAGE_CONNECTION_STRING=<connection-string> |
| 91 | + |
| 92 | +# Monitoring |
| 93 | +APPLICATIONINSIGHTS_CONNECTION_STRING=<connection-string> |
35 | 94 | ```
|
36 | 95 |
|
37 |
| -### Docker development |
| 96 | +See `.env.template` for complete configuration options. |
38 | 97 |
|
39 |
| -```shell |
40 |
| -# build docker image |
| 98 | +## Docker Deployment |
| 99 | + |
| 100 | +```bash |
| 101 | +# Build image |
41 | 102 | make docker-build
|
42 | 103 |
|
43 |
| -# run docker container |
44 |
| -make docker-run |
| 104 | +# Run container |
| 105 | +docker run -p 8000:8000 --env-file .env ks6088ts/template-fastapi:latest |
45 | 106 |
|
46 |
| -# run CI tests in docker container |
47 |
| -make ci-test-docker |
| 107 | +# Docker Compose (if available) |
| 108 | +docker-compose up |
48 | 109 | ```
|
49 | 110 |
|
50 |
| -## Deployment instructions |
| 111 | +## Development |
| 112 | + |
| 113 | +### Project Structure |
| 114 | + |
| 115 | +``` |
| 116 | +template_fastapi/ |
| 117 | +├── routers/ # API route handlers |
| 118 | +│ ├── agents/ # Agent-based endpoints |
| 119 | +│ ├── chats.py # WebSocket chat |
| 120 | +│ ├── demos.py # Demo endpoints |
| 121 | +│ ├── files.py # File operations |
| 122 | +│ ├── foodies.py # Restaurant API |
| 123 | +│ ├── items.py # Items CRUD |
| 124 | +│ └── speeches.py # Speech transcription |
| 125 | +├── models/ # Pydantic data models |
| 126 | +├── repositories/ # Data access layer |
| 127 | +├── settings/ # Configuration management |
| 128 | +└── templates/ # Jinja2 templates |
| 129 | +``` |
51 | 130 |
|
52 |
| -### Docker Hub |
| 131 | +### Testing |
53 | 132 |
|
54 |
| -To publish the docker image to Docker Hub, you need to [create access token](https://app.docker.com/settings/personal-access-tokens/create) and set the following secrets in the repository settings. |
| 133 | +```bash |
| 134 | +# Run all tests |
| 135 | +make test |
55 | 136 |
|
56 |
| -```shell |
57 |
| -gh secret set DOCKERHUB_USERNAME --body $DOCKERHUB_USERNAME |
58 |
| -gh secret set DOCKERHUB_TOKEN --body $DOCKERHUB_TOKEN |
| 137 | +# Run with coverage |
| 138 | +pytest --cov=template_fastapi |
| 139 | + |
| 140 | +# Run specific test file |
| 141 | +pytest tests/test_api.py -v |
59 | 142 | ```
|
| 143 | + |
| 144 | +### Code Quality |
| 145 | + |
| 146 | +```bash |
| 147 | +# Format code |
| 148 | +make format |
| 149 | + |
| 150 | +# Lint code |
| 151 | +make lint |
| 152 | + |
| 153 | +# Apply auto-fixes |
| 154 | +make fix |
| 155 | +``` |
| 156 | + |
| 157 | +## Azure Functions Deployment |
| 158 | + |
| 159 | +The application supports Azure Functions deployment: |
| 160 | + |
| 161 | +```bash |
| 162 | +# Export requirements |
| 163 | +uv export --format requirements-txt --no-dev --no-hashes --output-file requirements.txt |
| 164 | + |
| 165 | +# Deploy to Azure Functions |
| 166 | +func azure functionapp publish <function-app-name> |
| 167 | +``` |
| 168 | + |
| 169 | +## Contributing |
| 170 | + |
| 171 | +1. Fork the repository |
| 172 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 173 | +3. Make your changes with tests |
| 174 | +4. Run quality checks (`make ci-test`) |
| 175 | +5. Commit your changes (`git commit -m 'Add amazing feature'`) |
| 176 | +6. Push to the branch (`git push origin feature/amazing-feature`) |
| 177 | +7. Open a Pull Request |
| 178 | + |
| 179 | +## License |
| 180 | + |
| 181 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
0 commit comments