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.7.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.7-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: staticfloww-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 15f31a5eeae811f171b4d4c1e3d0b0d6e8625e33b99101c44328f235ee3c343e
MD5 9f6d26997919448be4895d95cc95e156
BLAKE2b-256 b16b571d9e03deedde9309f3488bed16436ea12a40aa867022f1ca8267b9a370

See more details on using hashes here.

File details

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

File metadata

  • Download URL: staticfloww-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 17.5 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e4ac6611432466db4faebf8d31f48bc66a88751418c2917471fb6ab96b78ab90
MD5 999f857736e630d23a2a2bf22dfa5aee
BLAKE2b-256 ac601525ee5f4e105697e5814a722212d6fc9b11172d569f6c17eef8a3329314

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