A FastAPI-based REST API for managing veterinary patients, owners, visits, and clinic operations using PostgreSQL, SQLAlchemy, JWT Authentication, Alembic, and Docker.
- User Registration
- User Login
- JWT Token Authentication
- Protected Routes
- Current User Context Endpoint
- Create Pet
- Get Pet By ID
- Get All Pets
- Update Pet
- Soft Delete Pet
- Filtering, Search, Sorting & Pagination
- Create Owner
- Get Owner
- Update Owner
- Delete Owner
- Create Visit
- Update Visit
- Delete Visit
- Retrieve Visit History
- PostgreSQL Database
- SQLAlchemy ORM
- Alembic Migrations
- Structured Logging
- Global Exception Handling
- Docker Support
- Environment Variables Configuration
git clone <repository-url>
cd veterinary-patient-management-apiUsing UV:
uv syncor
pip install -r requirements.txtCreate a .env file:
DATABASE_URL=your_database_url
JWT_SECRET_KEY=your_secret_key
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30| Variable | Description |
|---|---|
| DATABASE_URL | PostgreSQL database connection string |
| JWT_SECRET_KEY | Secret key used for JWT token signing |
| JWT_ALGORITHM | JWT encryption algorithm |
| ACCESS_TOKEN_EXPIRE_MINUTES | Token expiration time |
- Create a Neon account.
- Create a new PostgreSQL project.
- Copy the connection string.
- Paste it into:
DATABASE_URL=inside .env.
Create Migration:
alembic revision --autogenerate -m "migration_name"Apply Migration:
alembic upgrade headCheck Current Revision:
alembic currentMigration History:
alembic historyuv run uvicorn main:app --reloadApplication URL:
http://127.0.0.1:8000
Swagger Documentation:
http://127.0.0.1:8000/docs
ReDoc Documentation:
http://127.0.0.1:8000/redoc
docker build -t vet-api .docker run --env-file .env -p 8000:8000 vet-apidocker psPOST /registerCreates a new user.
POST /loginReturns JWT access token.
Click "Authorize" in Swagger UI and paste:
Bearer <token>
GET /auth/user-contextReturns currently authenticated user information.
POST /register
POST /login
GET /auth/user-contextPOST /owners
GET /owners
GET /owners/{id}
PUT /owners/{id}
DELETE /owners/{id}POST /pets
GET /pets
GET /pets/{id}
PUT /pets/{id}
DELETE /pets/{id}POST /pets/{id}/visits
PUT /visits/{id}
DELETE /visits/{id}The application logs:
- Request Method
- Endpoint
- Status Code
- Execution Time
- Startup Events
- Shutdown Events
- Authentication Failures
- Unhandled Exceptions
{
"success": false,
"message": "Error description"
}- FastAPI
- PostgreSQL
- SQLAlchemy
- Alembic
- Pydantic
- JWT
- Passlib
- Docker
- Uvicorn
- Python 3.13