How shieldersoftops/healthapishield works
Project Type and Purpose
• This is a backend API-gateway/microservice (no UI) built with FastAPI.
• Purpose: secure, monitor, and process healthcare data requests. It exposes three routes—main gateway (/medx/{path}), a health check (/health), and a webhook (/webhook/alerts)—and implements IP-validation, authentication, payload inspection, PII sanitization, rate limiting, analytics logging, and alerting.
File Structure
• Top-level:
• main.py – application entry point
• init_db.py – one-time DB initializer
• app/ – code modules
• app/core: configuration loader (env, settings)
• app/db: database connection (database.py) and ORM models (models.py)
• app/middleware: FastAPI middleware chain (auth, rate limiter, payload inspector, PII shredder, IP validator, analytics logger)
• app/routers: route definitions (gateway/API, health, webhook)
• app/services: business logic services that each middleware or router calls
• app/models: Pydantic request/response schemas
• Requirements: FastAPI, SQLAlchemy, Pydantic, SQLite
README for Insights
• Confirms layered architecture: routers → middleware → services → database
• Lists features (IP validation, OAuth2/OpenID, payload security, rate limiting, PII sanitization, analytics, security alerts)
• SQLite DB persisted at ./healthshield.db
Main Components
a. External Clients
• API consumers (mobile/web apps, other services)
• OAuth/OpenID Provider (external authentication)
• Monitoring/Alerting system (webhook receiver)
b. API Gateway (FastAPI Server)
• Routers (API, Health, Webhook)
• Middleware chain (Auth, Rate Limiter, Validator, Payload Inspector, PII Shredder, Analytics Logger)
c. Service Layer
• Auth Service
• Rate Limiter Service
• IP Validation Service
• Payload Inspection Service
• PII Shredder Service
• Analytics Service
• Alerts Service
• Client Handler (for proxying/forwarding requests)
d. Data Layer
• SQLite Database (via SQLAlchemy)
e. Configuration
• Config module (env loading)
Relationships and Interactions
• Within Gateway: request flows through middleware chain in configured order
• After passing middleware, Router → calls appropriate Service(s)
• Service(s) → read/write to Database (for rate-limit counters, audit logs, alerts, etc.)
• Auth Service ↔ External OAuth/OpenID Provider
• Alerts Service → sends to Webhook endpoint or external monitoring
• Analytics Service → writes logs/metrics (could be DB or external)
Key Architectural Patterns and Design Principles
• Layered Architecture: clear separation of concerns (API, middleware, services, data)
• Chain of Responsibility: middleware components process or short-circuit requests
• Dependency Injection: FastAPI’s DI for injecting config, DB session, services
• Single Responsibility: each module handles one concern (e.g., pii_shredder.py only scrubs PII)
Technologies and Frameworks
• FastAPI (ASGI, routers, DI)
• SQLAlchemy (DB models, session management)
• Pydantic (request/response schemas)
• Uvicorn (server)
• SQLite (embedded DB)