Skip to main content

Universal Gateway Framework for God Schema Architectures

Project description

StaticFlow

The Unified API Gateway Framework for "God Schema" Architectures.

StaticFlow is a lightweight, high-performance Python framework designed to simplify Backend-for-Frontend (BFF) development. It enables a "Universal Gateway" pattern where the frontend communicates via a single, static JSON contract (the "God Schema"), while the gateway handles routing, data extraction, and upstream proxying.


The Problem

In modern microservice or multi-API environments, frontend applications suffer from:

  • Fragmented Requests: Needing to hit multiple diverse endpoints for a single view.
  • Breaking Contracts: Any change in an upstream API requires a frontend update.
  • Auth Complexity: Managing different authentication flows for different services.
  • Observability Gaps: Difficulty tracking a single user action across multiple downstream calls.

The Solution: StaticFlow

StaticFlow provides a unified proxy layer that "plucks" exactly what it needs from a static, massive payload (the God Schema) and forwards it to the correct upstream service. It turns your backend into a clean, predictable API for your frontend team.


Key Features

  • The God Schema Engine: Maintain one single Pydantic-based schema that never changes shape.
  • Smart Extraction: Automatically extract and validate data segments based on the request action.
  • Parallel Fan-out: Trigger multiple upstream requests in parallel (using asyncio.TaskGroup) and merge results into a single response.
  • Resilience: Built-in Exponential Backoff Retries and Circuit Breaking to prevent cascading failures.
  • Flexible Auth: Handle API Keys (Header/Body/Param), OAuth2 Client Credentials, or Passthrough with Bearer normalization.
  • Unified Auditing: Log entire request/response/error cycles as single atomic transactions to MongoDB or In-Memory.
  • Contract Generation: Automatically export your Python schema to TypeScript types for your frontend team.
  • Mocking Mode: Return mock data for specific routes to unblock frontend development.

Architecture

graph TD
    A[Frontend App] -- "1. Single POST (Static God Schema)" --> B[StaticFlow Gateway]
    B -- "2. Extract & Validate" --> C{Routing Engine}
    C -- "Internal Action" --> D[Internal Handler (Auth/Logs/DB)]
    C -- "Proxy Action" --> E[Upstream Service A]
    C -- "Proxy Action" --> F[Upstream Service B]
    B -- "3. Standardized Response" --> A
    B -. "4. Unified Audit Log" .-> G[(Audit Database)]

Quick Start

1. Install

pip install staticfloww

2. Define your Static Schema

from staticfloww import StaticPayload, Section
from typing import Optional

class UserDetails(Section):
    first_name: str
    last_name: str

class MyGodSchema(StaticPayload):
    # Data Sections for specific requests
    UserDetails: Optional[UserDetails] = None

3. Configure the Gateway

from staticfloww import Gateway, APIKeyHandler, MemoryAuditor

# Initialize with In-Memory Auditing
auditor = MemoryAuditor()
app = Gateway(base_url="https://api.your-backend.com", auditor=auditor)

app.add_route(
    action="CREATE_MEMBER",
    path="/api/members/register",
    method="POST",
    extract="UserDetails",
    auth=APIKeyHandler(key="your-secret-key", location="header")
)

4. Use in FastAPI

from fastapi import FastAPI
from my_schema import MyGodSchema

web_app = FastAPI()

@web_app.post("/gateway")
async def handle_request(payload: MyGodSchema):
    return await app.route_request(payload)

Project Structure

staticfloww/
├── core/
│   ├── engine.py      # Orchestrator (TaskGroups & Semaphores)
│   ├── gateway.py     # Main Entry point
│   ├── proxy.py       # Httpx communication
│   ├── routing.py     # Route & Action mapping
│   ├── auth.py        # APIKey, OAuth2, Passthrough
│   └── resilience.py  # Retries & Circuit Breaker
├── middleware/
│   └── auditing.py    # Memory & MongoDB logging
├── schemas/
│   └── base.py        # StaticPayload & Section definitions
└── utils/
    └── ts_gen.py      # TypeScript Generator

Future Roadmap

  • Rate Limiting: Built-in protection to prevent gateway or upstream abuse.
  • Health Dashboard: Real-time status of all upstream services and circuit states.
  • AI Scaffolding Agent: Automatically generate Pydantic schemas from Swagger/OpenAPI docs.

License

MIT License. Created for clean API architectures.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

staticfloww-0.1.8.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

staticfloww-0.1.8-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file staticfloww-0.1.8.tar.gz.

File metadata

  • Download URL: staticfloww-0.1.8.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for staticfloww-0.1.8.tar.gz
Algorithm Hash digest
SHA256 c33e265b4506e3d49e068b93745f870645fb2f34583bdf37d59b5990c75d0373
MD5 932ab6d373839db421e30244bb672913
BLAKE2b-256 fcb68303f0bc7c0f5ed3bf4c28a3d639c82ce999250901e75be6acd51aaafe61

See more details on using hashes here.

File details

Details for the file staticfloww-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: staticfloww-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for staticfloww-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 046975f00d578a64a7f038ea1a7642a8c3a22caa6b14e15267a1d684d389e0b3
MD5 62e9e109fdfb4de538ab225c583aa38e
BLAKE2b-256 faa4faa88176bd9d1e465c443e7a5c85f1da72166790b7e0f11d4379c6dfa58d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page