|
1 | 1 | # API Server Seam |
2 | 2 |
|
3 | | -Status: local router plus optional FastAPI seam; not a hardened public server. |
| 3 | +Status: dependency-free local HTTP server plus internal router and optional FastAPI seam; not a hardened public server. |
4 | 4 |
|
5 | 5 | ## Purpose |
6 | 6 |
|
7 | | -Define the boundary between Flow Memory's in-process API manifest/router and any future network-facing service. The seam keeps endpoint shape, handler dispatch, and generated OpenAPI-like metadata testable without requiring a daemon, reverse proxy, database, or cloud service. |
| 7 | +Define the boundary between Flow Memory's in-process API manifest/router and any future network-facing service. The local HTTP server gives operators a concrete public-alpha loop for health checks, scoped local API calls, JSON error contracts, request audit events, and fixed-window rate-limit testing without adding FastAPI or cloud infrastructure to the base install. |
| 8 | + |
| 9 | +## Local HTTP server |
| 10 | + |
| 11 | +Run the dependency-free local server: |
| 12 | + |
| 13 | +```bash |
| 14 | +python scripts/run_local_api_server.py --host 127.0.0.1 --port 8765 |
| 15 | +``` |
| 16 | + |
| 17 | +With a local development API key and scope checks: |
| 18 | + |
| 19 | +```bash |
| 20 | +python scripts/run_local_api_server.py --api-key dev-local-only --require-scopes |
| 21 | +``` |
| 22 | + |
| 23 | +Example request: |
| 24 | + |
| 25 | +```bash |
| 26 | +python - <<'PY' |
| 27 | +import json, urllib.request |
| 28 | +req = urllib.request.Request( |
| 29 | + 'http://127.0.0.1:8765/health', |
| 30 | + headers={'x-flow-memory-api-key': 'dev-local-only', 'x-flow-memory-scopes': 'api:read'}, |
| 31 | +) |
| 32 | +print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2)) |
| 33 | +PY |
| 34 | +``` |
8 | 35 |
|
9 | 36 | ## Local-safe behavior |
10 | 37 |
|
11 | | -- Default execution stays in process through the dependency-light router. |
12 | | -- The endpoint manifest is the source of truth for route groups and handler names. |
13 | | -- Optional FastAPI wiring may expose health and manifest routes when the dependency is installed. |
14 | | -- Local handlers should use deterministic state, explicit inputs, and no hidden network calls. |
| 38 | +- Default execution can stay in process through `LocalApiRouter`. |
| 39 | +- `HttpApiGateway` wraps the router with JSON parsing, error contracts, optional API-key checks, optional scope enforcement, fixed-window local rate limiting, and audit events. |
| 40 | +- The endpoint manifest is still the source of truth for route groups and handler names. |
| 41 | +- Optional FastAPI wiring remains a separate application seam when the dependency is installed. |
15 | 42 | - Value-bearing or externally visible operations must remain behind policy, approval, audit, and adapter boundaries. |
16 | 43 |
|
17 | 44 | ## Auth seam |
18 | 45 |
|
19 | 46 | - `src/flow_memory/api/auth.py` supports local API-key checks and an explicit signed-request decision helper. |
20 | 47 | - Header matching is case-insensitive for `x-flow-memory-api-key`. |
| 48 | +- `src/flow_memory/api/http_server.py` enforces local API-key and scope decisions when configured. |
21 | 49 | - Signed requests use the local development signing seam and verify method, path, and payload binding. |
22 | 50 | - This is test coverage for the API boundary contract, not production authentication, replay protection, tenant isolation, or key custody. |
23 | 51 |
|
24 | | - |
25 | 52 | ## Limitations |
26 | 53 |
|
27 | 54 | - Not production-authenticated or internet-facing. |
28 | | -- API-key and signed-request helpers are local seams only; there is no production authorization model, session handling, replay protection, tenant isolation, rate-limit enforcement at the HTTP edge, or production observability. |
| 55 | +- API-key and signed-request helpers are local seams only; there is no production authorization model, session handling, replay protection, tenant isolation, distributed rate limiting, TLS termination, WAF, or production observability. |
29 | 56 | - Optional FastAPI support is an application seam, not a deployment architecture. |
30 | 57 | - Endpoint presence does not imply that downstream blockchain, MCP/A2A, libp2p, Redis, Qdrant, Neo4j, or OPA integrations are implemented. |
31 | 58 |
|
32 | 59 | ## Next implementation steps |
33 | 60 |
|
34 | | -1. Promote the manifest into generated OpenAPI with stable request/response schemas. |
35 | | -2. Add authentication, authorization, replay protection, rate limits, and structured audit events at the server boundary. |
36 | | -3. Bind each network route to explicit capability checks before handler execution. |
37 | | -4. Add integration tests for HTTP behavior once the server contract is stable. |
| 61 | +1. Add stable request/response schema objects per endpoint. |
| 62 | +2. Add request signing/replay windows at the HTTP boundary. |
| 63 | +3. Add TLS/reverse-proxy deployment profiles. |
| 64 | +4. Add production observability hooks and structured access logs. |
38 | 65 | 5. Document deployment profiles separately for local development, private lab use, and audited production use. |
0 commit comments