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.10.tar.gz (21.5 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.10-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: staticfloww-0.1.10.tar.gz
  • Upload date:
  • Size: 21.5 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.10.tar.gz
Algorithm Hash digest
SHA256 82bc1c87c4954045a9f0c525d0133aa5ce206ab4292d847858bcac6c1198ca9c
MD5 f2621c44e6eb6f3dcfee785b62b36550
BLAKE2b-256 1a2e0c4cb0676fea74358224ebdb12624451b515478bd60ff2075253776f6f40

See more details on using hashes here.

File details

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

File metadata

  • Download URL: staticfloww-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 18.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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 9efa9f6639d75d6e29cf7929b58b1ad8d729bf5fe0f17866ab4268d7ad1c7c06
MD5 7e41088bb02cea2560ce27a4813a2370
BLAKE2b-256 5661a689995326179e9df3ef35382733ae63e82012a34ba7f58c4bddca48f0bc

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