Skip to content

Conversation

Copy link

Copilot AI commented Dec 15, 2025

Adds a FastAPI service with Docker deployment using uv package manager, implementing a search endpoint that accepts ID parameters.

Application Structure

  • Factory pattern: create_app() in app/main.py instantiates the FastAPI application
  • Routes: Separated into app/routes.py using APIRouter
    • GET / - Service health/info
    • GET /search?id=<id> - Search by ID
# app/main.py
def create_app() -> FastAPI:
    app = FastAPI(title="TableScanner", ...)
    app.include_router(router)
    return app

app = create_app()
# app/routes.py
router = APIRouter()

@router.get("/search")
async def search(id: str = Query(...)):
    return {"query_id": id, "status": "success", ...}

Docker Setup

  • Base image: ghcr.io/astral-sh/uv:python3.14-alpine
  • Dependencies: fastapi, uvicorn, minio, KBUtilLib installed via uv
  • Docker Compose: Service on port 8000 with health checks and volume mounting

Dependencies

Managed through both requirements.txt and pyproject.toml:

  • fastapi ≥0.109.0
  • uvicorn[standard] ≥0.27.0
  • minio ≥7.2.0
  • KBUtilLib (KBase internal library)
Original prompt

Fastapi with dockerfile and docker-compose.
uv install fastapi KBUtilLib minio
one route with endpoint called search that takes an ID


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits December 15, 2025 19:31
Co-authored-by: bio-boris <1258634+bio-boris@users.noreply.github.com>
Co-authored-by: bio-boris <1258634+bio-boris@users.noreply.github.com>
Co-authored-by: bio-boris <1258634+bio-boris@users.noreply.github.com>
Co-authored-by: bio-boris <1258634+bio-boris@users.noreply.github.com>
Co-authored-by: bio-boris <1258634+bio-boris@users.noreply.github.com>
Copilot AI changed the title [WIP] Add search endpoint for FastAPI application Implement FastAPI application with uv-based Docker setup and search endpoint Dec 15, 2025
Copilot AI requested a review from bio-boris December 15, 2025 19:45
@bio-boris bio-boris marked this pull request as ready for review December 15, 2025 20:59
Copilot AI review requested due to automatic review settings December 15, 2025 20:59
@bio-boris bio-boris merged commit 5acf062 into develop Dec 15, 2025
6 of 7 checks passed
@bio-boris bio-boris deleted the copilot/add-fastapi-search-endpoint branch December 15, 2025 20:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a FastAPI application called TableScanner with Docker deployment using the uv package manager. It introduces a basic web service with two endpoints: a root health check endpoint and a search endpoint that accepts ID parameters.

Key Changes:

  • Added FastAPI application structure with factory pattern (app/main.py) and modular routing (app/routes.py)
  • Implemented Docker setup using uv-based Alpine image with uv for dependency management
  • Created search endpoint accepting ID query parameters and returning JSON responses

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
pyproject.toml Defines project metadata and dependencies (fastapi, uvicorn, minio) using modern Python packaging standards
Dockerfile Creates containerized application using ghcr.io/astral-sh/uv:python3.13-alpine with uv sync for dependencies
docker-compose.yml Configures service orchestration with port mapping, volume mounts, and health checks
app/main.py Implements FastAPI factory pattern with application configuration and router inclusion
app/routes.py Defines API endpoints including root service info and search functionality
app/init.py Initializes app package with simple comment
README.md Provides comprehensive documentation including setup, usage, API endpoints, and development instructions
.gitignore Adds Python and uv-specific ignore patterns for development artifacts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



@router.get("/search")
def search(id: str = Query(..., description="ID to search for")):
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'id' parameter lacks input validation. Consider adding validation for the format, length, or allowed characters of the ID to prevent potential issues with malformed inputs. FastAPI's Query parameter supports min_length, max_length, and regex patterns for validation.

Suggested change
def search(id: str = Query(..., description="ID to search for")):
def search(
id: str = Query(
...,
description="ID to search for",
min_length=1,
max_length=32,
regex="^[a-zA-Z0-9_-]+$"
)
):

Copilot uses AI. Check for mistakes.
dependencies = [
"fastapi>=0.124.4",
"uvicorn>=0.38.0",
#"KBUtilLib", # KBase internal library - version managed by KBase infrastructure
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description states dependencies should include KBUtilLib, but it's commented out in pyproject.toml. This creates an inconsistency between the documented dependencies and the actual configuration. Either uncomment this dependency with appropriate version constraints or update the documentation to reflect that it's intentionally excluded.

Suggested change
#"KBUtilLib", # KBase internal library - version managed by KBase infrastructure
"KBUtilLib", # KBase internal library - version managed by KBase infrastructure

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
version: '3.8'

Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'version' field in docker-compose.yml is deprecated and should be removed. Docker Compose v2 no longer requires or uses the version field, and its presence is now obsolete.

Suggested change
version: '3.8'

Copilot uses AI. Check for mistakes.
RUN apk --no-cache add curl
WORKDIR /app
COPY app ./app
COPY pyproject.toml /app/pyproject.toml
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 'uv sync' without copying a lock file (uv.lock) means dependencies will be resolved at build time, potentially leading to non-reproducible builds. Consider adding uv.lock to version control and copying it before running uv sync to ensure consistent dependency versions across builds.

Suggested change
COPY pyproject.toml /app/pyproject.toml
COPY pyproject.toml /app/pyproject.toml
COPY uv.lock /app/uv.lock

Copilot uses AI. Check for mistakes.
Comment on lines +89 to +92
1. Install dependencies:
```bash
pip install -r requirements.txt
```
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation references 'requirements.txt' for local development, but this file doesn't exist in the repository. The project uses pyproject.toml for dependency management. Update the installation command to use 'uv sync' or 'pip install .' instead.

Copilot uses AI. Check for mistakes.
requires-python = ">=3.9"
dependencies = [
"fastapi>=0.124.4",
"uvicorn>=0.38.0",
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimum version constraint for uvicorn is set to 0.38.0, but this version does not exist. Uvicorn versions are currently in the 0.3x range (e.g., 0.30.x, 0.31.x). This will cause installation failures.

Suggested change
"uvicorn>=0.38.0",
"uvicorn>=0.30.0",

Copilot uses AI. Check for mistakes.


@router.get("/")
async def root():
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root endpoint is defined as async but doesn't perform any asynchronous operations. For consistency with the search endpoint at line 23, which is not async, this should either be made synchronous or the search endpoint should be made async to maintain a consistent pattern.

Suggested change
async def root():
def root():

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +37
@router.get("/search")
def search(id: str = Query(..., description="ID to search for")):
"""
Search endpoint that takes an ID parameter.
Args:
id: The ID to search for (required)
Returns:
A dictionary with search results
"""
return {
"query_id": id,
"status": "success",
"message": f"Search completed for ID: {id}"
}
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search endpoint lacks test coverage. Consider adding tests to verify the endpoint correctly handles valid IDs, missing ID parameters, and different ID formats to ensure the API behaves as expected.

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +84
### Dependencies

The application requires:
- `fastapi` - Web framework
- `uvicorn[standard]` - ASGI server
- `minio` - MinIO client for object storage
- `KBUtilLib` - KBase utility library

Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README documents that 'requirements.txt' manages dependencies, but the project uses pyproject.toml. This creates confusion about the actual dependency management approach. Update the documentation to reflect that pyproject.toml is the source of truth for dependencies.

Copilot uses AI. Check for mistakes.
RUN apk --no-cache add bash curl

ENTRYPOINT ["sleep 1d"]
FROM ghcr.io/astral-sh/uv:python3.13-alpine
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dockerfile uses Python 3.13, while pyproject.toml specifies requires-python >= 3.9. Consider aligning these to use a more widely-adopted Python version like 3.11 or 3.12, as Python 3.13 is relatively new and may have compatibility issues with some dependencies.

Suggested change
FROM ghcr.io/astral-sh/uv:python3.13-alpine
FROM ghcr.io/astral-sh/uv:python3.12-alpine

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants