Problem or Use Case
The current DynamoDB schema is defined implicitly in Python code (schema.py and repository.py). This makes it difficult to:
- Implement alternative aggregators (e.g., Rust) that need to read/write the same data
- Generate type-safe clients in other languages
- Validate schema consistency across implementations
- Document the schema in a language-neutral format
As the project moves toward alternative backends (v1.4.0) and multi-language ecosystem growth, a single source of truth for the DynamoDB schema becomes essential.
Proposed Solution
Create a schema.yaml (or schema.json) file that defines:
- Table structure: PK/SK patterns, GSI definitions
- Record types: All item types with their attributes and types
- Key builders: Documented patterns for constructing keys
- Attribute constraints: Required fields, enums, value ranges
# Example structure
table:
name: rate_limits
billing_mode: PAY_PER_REQUEST
keys:
primary:
partition_key: PK
sort_key: SK
gsi1:
partition_key: GSI1PK
sort_key: GSI1SK
gsi2:
partition_key: GSI2PK
sort_key: GSI2SK
prefixes:
entity: "ENTITY#"
parent: "PARENT#"
resource: "RESOURCE#"
system: "SYSTEM#"
audit: "AUDIT#"
record_types:
entity_meta:
pk_pattern: "ENTITY#{entity_id}"
sk: "#META"
attributes:
entity_id: { type: string, required: true }
parent_id: { type: string, required: false }
cascade: { type: boolean, default: false }
created_at: { type: integer, description: "Unix timestamp ms" }
composite_bucket:
pk_pattern: "ENTITY#{entity_id}"
sk_pattern: "#BUCKET#{resource}"
attributes:
# Composite bucket fields use b_{limit}_{field} naming
"b_{limit}_tk": { type: integer, description: "Tokens (millitokens)" }
"b_{limit}_cp": { type: integer, description: "Capacity (millitokens)" }
# ...
Alternatives Considered
- OpenAPI/JSON Schema: More verbose, less suited for DynamoDB-specific patterns
- Protobuf: Adds compilation step, not as readable
- Keep Python-only: Blocks multi-language growth
Acceptance Criteria
Problem or Use Case
The current DynamoDB schema is defined implicitly in Python code (
schema.pyandrepository.py). This makes it difficult to:As the project moves toward alternative backends (v1.4.0) and multi-language ecosystem growth, a single source of truth for the DynamoDB schema becomes essential.
Proposed Solution
Create a
schema.yaml(orschema.json) file that defines:Alternatives Considered
Acceptance Criteria
schema.yamlfile exists at project root (ordocs/schema.yaml)repository.pyschema.py