How tobkosty1986/patients-api works
Purpose and Entry Point
This repository is a small REST API for exposing sample medical patient records. The executable ASGI application is src/main.py, served locally with Uvicorn as src.main:app. Its public contract is FastAPI-generated HTTP endpoints and OpenAPI documentation.
API Layer
src/main.py defines the FastAPI application and all request routing:
• GET /patients returns the complete dataset.
• GET /patients/find accepts repeated ids query parameters.
• GET /patients/search performs case-insensitive name matching.
• GET /patients/{id} resolves one patient by identifier.
Route ordering is material: static routes such as /patients/find and /patients/search must be handled before the parameterized /{id} route.
Patient Data Boundary
src/data.py is the application’s current data source: an in-process sample dataset loaded with the application. There is no persistence layer, database connection, external patient-record service, or write path indicated by the repository.
The API layer reads and filters this dataset directly, making the process stateless apart from module-loaded data.
Request and Response Flow
An HTTP client reaches the FastAPI ASGI app in src/main.py. Endpoint handlers validate/path-parse request inputs through FastAPI, query or filter records from src/data.py, and serialize the selected records as JSON responses. Missing or unmatched identifiers are handled at the API boundary rather than delegated to a datastore.
Configuration and Runtime Environment
src/config.py and .env.example represent the configuration boundary for environment-driven runtime settings. The service runs on Python with dependencies declared in requirements.txt; Uvicorn is the production/local ASGI server implied by the documented launch command.
Container Delivery
Dockerfile defines multi-stage container targets separating test execution from the runtime image. The runtime container exposes the FastAPI service, receives environment variables via Docker’s --env-file, and is intended to be published on port 8000. .dockerignore limits build context content.
Verification Contract
tests/test_main.py exercises the externally visible API routes against the FastAPI application in src/main.py. These tests define the main compatibility boundary for route behavior, filtering semantics, and returned patient data.
Main entry points: main.py FastAPI app · data.py Sample patient dataset · Dockerfile Multi-stage image build · config.py Runtime settings
Components 15
API runtime
- Uvicorn
- FastAPI app · Defines the public HTTP and OpenAPI contract.
src/main.py - GET /patients · Returns all sample records.
src/main.py - GET /patients/find · Filters by repeated ids query parameters.
src/main.py - GET /patients/search · Performs case-insensitive name matching.
src/main.py - GET /patients/{id} · Resolves one patient after static routes.
src/main.py - Runtime settings · Environment-driven settings boundary.
src/config.py - Environment file template
.env.example
Data boundary
- Sample patient dataset · Module-loaded, read-only application data.
src/data.py
Delivery & verification
- Python dependencies
requirements.txt - Multi-stage image build · Separates test execution from the runtime image.
Dockerfile - Build context filter
.dockerignore - Runtime container · Publishes the ASGI service on port 8000.
- API compatibility tests · Exercises externally visible route behavior and returned data.
tests/test_main.py
Other components
- HTTP client
Connections 17
- HTTP client → Uvicorn: HTTP requests
- Uvicorn → FastAPI app: ASGI
- FastAPI app → GET /patients: routes
- FastAPI app → GET /patients/find: routes before {id}
- FastAPI app → GET /patients/search: routes before {id}
- FastAPI app → GET /patients/{id}: routes
- GET /patients → Sample patient dataset: reads all records
- GET /patients/find → Sample patient dataset: filters ids
- GET /patients/search → Sample patient dataset: filters names
- GET /patients/{id} → Sample patient dataset: looks up id
- Environment file template → Runtime settings: supplies values
- Runtime settings → FastAPI app: runtime settings
- Python dependencies → Multi-stage image build: installed during build
- Build context filter → Multi-stage image build: limits context
- Multi-stage image build → Runtime container: builds runtime target
- Runtime container → Uvicorn: runs src.main:app
- API compatibility tests → FastAPI app: exercises public routes