How davejfranco/python-fastapi-demo works
Project Type and Purpose
• This is a backend microservice/demo written in Python using FastAPI.
• It exposes a simple REST API, backed by a light-weight persistence layer (data loaded from JSON or a local database file).
• It is containerized (Dockerfile) and packaged for Kubernetes deployment via a Helm chart.
• It also includes GitHub Actions workflows for CI/CD (build, test, push, deploy).
File Structure Analysis
─ .github/workflows : CI/CD pipelines (cicd.yaml, pr.yaml)
─ Dockerfile : Container image build definition
─ README.md : Project overview & startup instructions
─ app/
├─ main.py : UVicorn/FastAPI application entrypoint
├─ api/api.py : Route definitions / request handlers
└─ db/
├─ database.py : Data-access layer (session/connection)
└─ models.py : ORM/data models
─ chart/ : Helm chart for on-cluster deployment
├─ Chart.yaml : Chart metadata
├─ values.yaml, *-values.yaml : Environment-specific settings (local, EKS)
└─ templates/ : Kubernetes manifests (Deployment, Service, Ingress, HPA, ServiceAccount, tests)
─ k8s/app.yaml : Raw Kubernetes manifest example
─ data/ : Static JSON data (products.json, stores.json)
─ test/ : Unit test suite (pytest)
─ requirements.txt : Python dependencies
Additional Insights from README
• It’s a demonstration of FastAPI, containerization, and CI/CD rather than a production-grade system.
• Startup is via uvicorn app.main:app --reload, tests via pytest.
a. Main Components
• Client (e.g. browser, curl, Postman)
• API Service Pods (FastAPI app in Docker)
• Data Layer (in-pod JSON or lightweight DB)
• Kubernetes Cluster Resources: Ingress, Service, Deployment, HPA
• Container Registry (Docker Hub/ECR)
• CI/CD Pipeline (GitHub Actions)
• Helm Chart (packaging & configuration)
b. Relationships & Interactions
1. Client → Ingress (via HTTP/HTTPS)
2. Ingress → Service → Deployment pods (FastAPI)
3. FastAPI handlers ↔ Data Layer (JSON files or DB session)
4. GitHub Actions on push: run tests, build Docker image, push to registry, trigger Helm-based deploy to Kubernetes
5. Helm Chart parameters drive the Deployment, Service, Ingress, HPA manifests
c. Architectural Patterns & Principles
– 12-factor app: config via environment/values.yaml
– Infrastructure as code: Kubernetes manifest templates + Helm
– Continuous delivery: automated workflows for build/test/deploy
– Clear separation: API logic vs. data-access layer vs. deployment artifacts
d. Key Technologies & Libraries
• FastAPI + Uvicorn
• SQLAlchemy or Pydantic models (depending on implementation in models.py)
• Docker
• Kubernetes + Helm
• GitHub Actions
• pytest