Skip to content

A full-stack Python backend for simulating healthcare workflows — combines REST, gRPC, Kafka, and Spark in a clean, testable architecture. Designed for real-world API, data engineering, and cloud deployment demos.

License

Notifications You must be signed in to change notification settings

daviguides/care-gateway

Repository files navigation

🩺 Care Gateway: All-in-One Portfolio Project

Diagram

Care Gateway is a modular, full-stack backend simulating healthcare claim workflows — built to showcase real-world skills in APIs, gRPC, ETL, and streaming.

It integrates PostgreSQL, Kafka, PySpark, and Python frameworks (Flask, FastAPI) in a clean, cloud-ready architecture. Ideal for demonstrating expertise in Python, API design, and data engineering.

The project emphasizes simplicity, transparency, and human-centered design—mirroring values found in modern healthtech platforms. Each component is crafted to reflect practical scenarios, from claim ingestion to real-time processing, with clear structure and extensibility.

⭐ My Related Projects

  • eks-ec2-cdk-react-dns-demo: Deploys EKS (EC2) with AWS CDK, runs containerized apps (incl. React), routes via Route53 — sharp, real-world IaC. Pairs naturally with Care Gateway as next deployment step.
  • sftp2s3: Syncs files from SFTP to S3 — used as the upstream file drop in the Care Gateway pipeline, triggering Kafka events when .edi claim files land in the bucket.
  • sftp-aws-cdk-infra: Provisions AWS Transfer Family SFTP with AWS CDK — secure ingestion pipelines.
  • keysentinel: Local token management with layered security — built for zero-trust systems.
  • lettuce-events: Minimal event-driven app using RabbitMQ — clean pub/sub architecture for async flows.

🛡️ Security Articles by Me

A look into the ideas, experiments, and lessons behind my code:

✨ Features

Architecture

  • Modular: APIs, gRPC, ETL, DB — real-world healthcare flows (claims, eligibility, EDI)
  • Clean Python structure — designed for clarity, reuse, and testing

APIs & Services

  • REST with Flask + SQLAlchemy (sync) and FastAPI + SQLModel (async)
  • gRPC microservice — shared backend logic
  • Kafka integration — async, event-driven design

Data Layer

  • PostgreSQL — shared DB
  • Dual ORM: SQLAlchemy + SQLModel
  • Alembic — migrations ready

ETL Pipeline

  • PySpark worker + databricksx12 — parses EDI 837 → flattens to DB
  • Kafka triggers ingestion on file arrival

Dev & Testing

  • Full coverage: REST, gRPC, async
  • Makefile for migrations, tests, bootstrap
  • .http test file for manual requests

Cloud Ready

  • Docker-friendly
  • EKS-ready — CDK + GitOps compatible

🔧 Components Overview

1. FastAPI Application

  • Async REST API using FastAPI + SQLModel
  • Designed for high performance and modern async use cases
  • Fully covered with pytest-asyncio

Entry Point: care_gateway/api_fastapi/app.py

Example Endpoints:

GET /claims/
GET /claim_events/
GET /claim_events/by-claim/{claim_id}

Fastapi


2. Flask Application

  • Synchronous REST API with Flask + SQLAlchemy
  • Uses Marshmallow for serialization
  • Communicates with the gRPC service for deeper logic
  • Great for demonstrating traditional Flask-based workflows

Entry Point: care_gateway/api_flask/app.py

Example Endpoints:

GET /claims/
POST /claim_events/
POST /claim_events/submit

3. gRPC Service

  • Built using grpcio and grpcio-tools
  • Provides backend logic for claim submission
  • Decoupled architecture simulating modern backend patterns

Protos: care_gateway/service_grpc/proto/claims/

To Run:

python scripts/run_service_grpc.py

4. ETL Worker (Kafka + Spark)

  • Event-driven ETL pipeline using Kafka and PySpark
  • Processes EDI 837 healthcare claim files via databricksx12
  • Transforms and flattens data into PostgreSQL-ready format

Entry Point: care_gateway/worker_kafka/app.py

Flow:

  1. An .edi or .txt file lands in S3 (via sftp2s3)
  2. A Kafka event is emitted
  3. Worker consumes the event, parses the EDI file, and prepares DB records

Worker Kakfa


📦 Directory Structure

care_gateway/
├── api_fastapi/            # FastAPI app (SQLModel + async)
├── api_flask/              # Flask app (SQLAlchemy + Marshmallow)
├── db/                     # Shared DB models
├── service_grpc/           # gRPC server and services
├── worker_kafka/           # Kafka + Spark ETL worker
├── utils/                  # Utilities (e.g., test DB setup)
├── logging_config.py       # Logging setup
scripts/                    # Execution helpers
data/                       # EDI inbox/outbox folders
alembic/                    # Alembic migrations

📥 Installation & Setup

✅ Requirements

  • Python 3.12+
  • PostgreSQL running locally (claims_test_db, claims_test_db_test)
  • Kafka broker (for ETL)

1. Create Environment & Install

uv venv
uv pip install -e .[dev,api-fastapi,worker-kafka-spark,grpcio-server]

2. Create Databases and Run Migrations

createdb claims_test_db
createdb claims_test_db_test
make upgrade

3. Run Applications

# Terminal 1: gRPC Service
python scripts/run_service_grpc.py

# Terminal 2: Flask API
python scripts/run_api_flask.py

# Terminal 3: FastAPI
bash scripts/run_api_fastapi.zsh

# Terminal 4: Kafka Worker
python scripts/run_kafka_scheduler.py

4. Run Tests

pytest --cov=care_gateway --cov-report=term-missing

Coverage

Or test manually with tests/requests.http.


🧪 Test Coverage

  • ✅ Full test coverage for Flask and FastAPI APIs
  • ✅ DB model validation
  • ✅ gRPC call simulation
  • ✅ Kafka + ETL test structure (expandable)

⚠️ Disclaimer

This project was built with a focus on demonstrating integration of multiple technologies. As such:

  • Data models are intentionally simplified
  • EDI 837 ingestion does not parse every segment
  • Certain flows (e.g., full S3 sync + Kafka trigger) are simulated
  • The primary goal is showcasing architecture, backend versatility, and tech integration, not production-readiness

📄 License

MIT License


👨‍💼 Author

Built with ❤️ by Davi Luiz Guides

Diagram

About

A full-stack Python backend for simulating healthcare workflows — combines REST, gRPC, Kafka, and Spark in a clean, testable architecture. Designed for real-world API, data engineering, and cloud deployment demos.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages