# tobkosty1986/patients-api architecture

> Architecture diagram of the GitHub repository tobkosty1986/patients-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tobkosty1986/patients-api
- Repository: https://github.com/tobkosty1986/patients-api

## Overview

#### 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: [`src/main.py`](https://github.com/tobkosty1986/patients-api/blob/main/src/main.py) (FastAPI app), [`src/data.py`](https://github.com/tobkosty1986/patients-api/blob/main/src/data.py) (Sample patient dataset), [`Dockerfile`](https://github.com/tobkosty1986/patients-api/blob/main/Dockerfile) (Multi-stage image build), [`src/config.py`](https://github.com/tobkosty1986/patients-api/blob/main/src/config.py) (Runtime settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["API runtime"]
  node_uvicorn["Uvicorn<br/>ASGI server"]
  node_app["FastAPI app<br/>ASGI application<br/>[main.py]"]
  node_list["GET /patients<br/>route<br/>[main.py]"]
  node_find["GET /patients/find<br/>route<br/>[main.py]"]
  node_search["GET /patients/search<br/>route<br/>[main.py]"]
  node_patient["GET /patients/&#123;id&#125;<br/>route<br/>[main.py]"]
  node_config["Runtime settings<br/>configuration<br/>[config.py]"]
  node_env["Environment file template<br/>environment contract<br/>[.env.example]"]
end

subgraph group_data["Data boundary"]
  node_data[("Sample patient dataset<br/>in-process data<br/>[data.py]")]
end

subgraph group_delivery["Delivery &amp; verification"]
  node_requirements["Python dependencies<br/>dependency manifest<br/>[requirements.txt]"]
  node_dockerfile["Multi-stage image build<br/>container build"]
  node_dockerignore["Build context filter<br/>container configuration<br/>[.dockerignore]"]
  node_container["Runtime container<br/>containerized service"]
  node_tests["API compatibility tests<br/>integration tests<br/>[test_main.py]"]
end

node_client(("HTTP client<br/>consumer"))

node_client -->|"HTTP requests"| node_uvicorn
node_uvicorn -->|"ASGI"| node_app
node_app -->|"routes"| node_list
node_app -->|"routes before &#123;id&#125;"| node_find
node_app -->|"routes before &#123;id&#125;"| node_search
node_app -->|"routes"| node_patient
node_list -->|"reads all records"| node_data
node_find -->|"filters ids"| node_data
node_search -->|"filters names"| node_data
node_patient -->|"looks up id"| node_data
node_env -.->|"supplies values"| node_config
node_config -.->|"runtime settings"| node_app
node_requirements -->|"installed during build"| node_dockerfile
node_dockerignore -.->|"limits context"| node_dockerfile
node_dockerfile -->|"builds runtime target"| node_container
node_container -->|"runs src.main:app"| node_uvicorn
node_tests -->|"exercises public routes"| node_app

click node_app "https://github.com/tobkosty1986/patients-api/blob/main/src/main.py"
click node_list "https://github.com/tobkosty1986/patients-api/blob/main/src/main.py"
click node_find "https://github.com/tobkosty1986/patients-api/blob/main/src/main.py"
click node_search "https://github.com/tobkosty1986/patients-api/blob/main/src/main.py"
click node_patient "https://github.com/tobkosty1986/patients-api/blob/main/src/main.py"
click node_data "https://github.com/tobkosty1986/patients-api/blob/main/src/data.py"
click node_config "https://github.com/tobkosty1986/patients-api/blob/main/src/config.py"
click node_env "https://github.com/tobkosty1986/patients-api/blob/main/.env.example"
click node_requirements "https://github.com/tobkosty1986/patients-api/blob/main/requirements.txt"
click node_dockerfile "https://github.com/tobkosty1986/patients-api/blob/main/Dockerfile"
click node_dockerignore "https://github.com/tobkosty1986/patients-api/blob/main/.dockerignore"
click node_tests "https://github.com/tobkosty1986/patients-api/blob/main/tests/test_main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_uvicorn,node_app,node_list,node_find,node_search,node_patient,node_config,node_env toneBlue
class node_data toneAmber
class node_requirements,node_dockerfile,node_dockerignore,node_container,node_tests toneMint
class node_client toneNeutral
```

## Components

### API runtime

- **Uvicorn**: ASGI server
- [FastAPI app](https://github.com/tobkosty1986/patients-api/blob/main/src/main.py): ASGI application · Defines the public HTTP and OpenAPI contract. · `src/main.py`
- [GET /patients](https://github.com/tobkosty1986/patients-api/blob/main/src/main.py): route · Returns all sample records. · `src/main.py`
- [GET /patients/find](https://github.com/tobkosty1986/patients-api/blob/main/src/main.py): route · Filters by repeated ids query parameters. · `src/main.py`
- [GET /patients/search](https://github.com/tobkosty1986/patients-api/blob/main/src/main.py): route · Performs case-insensitive name matching. · `src/main.py`
- [GET /patients/{id}](https://github.com/tobkosty1986/patients-api/blob/main/src/main.py): route · Resolves one patient after static routes. · `src/main.py`
- [Runtime settings](https://github.com/tobkosty1986/patients-api/blob/main/src/config.py): configuration · Environment-driven settings boundary. · `src/config.py`
- [Environment file template](https://github.com/tobkosty1986/patients-api/blob/main/.env.example): environment contract · `.env.example`

### Data boundary

- [Sample patient dataset](https://github.com/tobkosty1986/patients-api/blob/main/src/data.py): in-process data · Module-loaded, read-only application data. · `src/data.py`

### Delivery & verification

- [Python dependencies](https://github.com/tobkosty1986/patients-api/blob/main/requirements.txt): dependency manifest · `requirements.txt`
- [Multi-stage image build](https://github.com/tobkosty1986/patients-api/blob/main/Dockerfile): container build · Separates test execution from the runtime image. · `Dockerfile`
- [Build context filter](https://github.com/tobkosty1986/patients-api/blob/main/.dockerignore): container configuration · `.dockerignore`
- **Runtime container**: containerized service · Publishes the ASGI service on port 8000.
- [API compatibility tests](https://github.com/tobkosty1986/patients-api/blob/main/tests/test_main.py): integration tests · Exercises externally visible route behavior and returned data. · `tests/test_main.py`

### Other components

- **HTTP client**: consumer

## Connections

- 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
