Development Guidelines
This guide outlines the coding standards and best practices for developing TableTheory in this multi-language monorepo:
- Go (root module)
- TypeScript (
ts/) - Python (
py/)
Struct Definition Standards
TableTheory relies heavily on Go struct tags. Follow these rules strictly:
- Primary Keys: Always tag your partition key with
theorydb:"pk"and sort key withtheorydb:"sk". For legacy DynamORM-compatible models, addtheorydb:"naming:dynamorm"on a marker field so the actual DynamoDB key attributes stayPKandSK. - JSON Tags: Always include
json:"name"tags matching your attribute names. For new models this is usually snake_case; for legacy DynamORM models use JSON names that match the legacy wire format you need to preserve. - Types: Use standard Go types (
string,int,int64,float64,bool,time.Time).
// ✅ CORRECT
type Product struct {
ID string `theorydb:"pk" json:"id"`
Price float64 `json:"price"`
}
// ❌ INCORRECT
type Product struct {
ID string // Missing tags!
}
// ✅ LEGACY DYNAMORM COMPATIBLE
type LegacyUser struct {
_ struct{} `theorydb:"naming:dynamorm"`
UserID string `theorydb:"pk" json:"PK"`
Entity string `theorydb:"sk" json:"SK"`
FirstName string `json:"firstName"`
}
TypeScript SDK standards (ts/)
- Runtime/toolchain: Node.js 24
- Must pass:
npm --prefix ts run typechecknpm --prefix ts run lintnpm --prefix ts run test
- Prefer explicit attribute names in model definitions (
defineModel) to stay DMS-friendly and avoid drift. - Do not weaken testkit strictness (
@theory-cloud/tabletheory-ts/testkit).
See TypeScript Development Guidelines.
Python SDK standards (py/)
- Runtime/toolchain: Python 3.14
- Must pass:
uv --directory py run mypy src(strict)uv --directory py run ruff checkuv --directory py run pytest -q tests/unit
- Prefer dataclasses with explicit roles via
theorydb_field(...). - Do not weaken strict fakes (
theorydb_py.mocks); unit tests must not call real AWS.
See Python Development Guidelines.
Error Handling
Always check errors. TableTheory returns typed errors where possible.
- Validation Errors: Occur before network calls (invalid struct tags, missing keys).
- Runtime Errors: Occur during AWS execution (throughput exceeded, conditional check failed).
if err := db.Model(item).Create(); err != nil {
if errors.Is(err, customerrors.ErrConditionFailed) {
// Handle duplicate
}
return err
}
Code Style
- Fluent Chains: Break long query chains onto multiple lines for readability.
- Context: Use
context.TODO()orcontext.Background()if you aren’t passing a request context (thoughWithContextis preferred).
// Readable
db.Model(&Item{}).
Where("ID", "=", "1").
Limit(1).
First(&item)
Contribution Workflow
- Fork & Branch: Create a feature branch.
- Test: Run
go test ./...to ensure no regressions. - Docs: Update documentation if you change public APIs.
- PR: Submit a Pull Request with a clear description.