A modular TypeScript library for AWS DynamoDB that provides best practices, pattern helpers, and performance monitoring. Works seamlessly with both standalone DynamoDB and AWS Amplify Gen 2.
https://ddb-lib.dev - Complete documentation with guides, examples, and API reference
This is a monorepo containing multiple packages that can be used independently or together:
| Package | Description | Use Case |
|---|---|---|
| @ddb-lib/core | Pure utility functions for DynamoDB patterns | Pattern helpers, multi-attribute keys, expression builders |
| @ddb-lib/stats | Performance monitoring and recommendations | Statistics collection, anti-pattern detection |
| @ddb-lib/client | Full-featured DynamoDB client | Standalone DynamoDB applications |
| @ddb-lib/amplify | AWS Amplify Gen 2 integration | Amplify applications with monitoring |
Install the client package (includes core and stats):
npm install @ddb-lib/clientimport { TableClient } from '@ddb-lib/client'
import { PatternHelpers } from '@ddb-lib/core'
const table = new TableClient({
tableName: 'my-table',
region: 'us-east-1',
statsConfig: { enabled: true }
})
// Use pattern helpers
const userKey = PatternHelpers.entityKey('USER', '123')
// Perform operations
await table.put({ pk: userKey, sk: 'PROFILE', name: 'Alice' })
const user = await table.get({ pk: userKey, sk: 'PROFILE' })
// Get recommendations
const recommendations = table.getRecommendations()Install the Amplify integration package:
npm install @ddb-lib/amplifyimport { generateClient } from 'aws-amplify/data'
import { AmplifyMonitor } from '@ddb-lib/amplify'
import { PatternHelpers } from '@ddb-lib/core'
import type { Schema } from './amplify/data/resource'
const client = generateClient<Schema>()
// Create monitor
const monitor = new AmplifyMonitor({
statsConfig: { enabled: true }
})
// Wrap your Amplify model
const monitoredTodos = monitor.wrap(client.models.Todo)
// Use as normal - operations are automatically monitored
await monitoredTodos.create({ title: 'Buy groceries', completed: false })
// Get statistics and recommendations
const stats = monitor.getStats()
const recommendations = monitor.getRecommendations()If you only need pattern helpers without a client:
npm install @ddb-lib/coreimport { PatternHelpers, multiTenantKey } from '@ddb-lib/core'
// Use pattern helpers in your own code
const key = PatternHelpers.compositeKey(['USER', '123', 'ORDER', '456'])
const tenantKey = multiTenantKey('TENANT-1', 'CUST-123')- Pattern helpers: Entity keys, composite keys, time-series keys, hierarchical keys
- Multi-attribute keys: Native support for DynamoDB's multi-attribute composite keys
- Expression builders: Type-safe builders for key conditions, filters, and conditions
- Type guards: Runtime type checking utilities
- Zero dependencies: Pure TypeScript with no external dependencies
- Performance tracking: Automatic latency and capacity monitoring
- Anti-pattern detection: Identifies scans, hot partitions, inefficient queries
- Recommendations: Actionable suggestions for optimization
- Framework agnostic: Works with any data access layer
- Complete DynamoDB API: All operations with simplified interface
- Automatic batching: Intelligent chunking for batch operations
- Retry logic: Configurable exponential backoff
- Access patterns: Named, reusable query patterns
- Type safety: Full TypeScript support with inference
- Seamless integration: Works with Amplify Gen 2 data client
- Automatic monitoring: Zero-config operation tracking
- Pattern helpers: Use DynamoDB best practices with Amplify
- Type safe: Preserves Amplify's type definitions
Visit https://ddb-lib.dev for comprehensive documentation including:
- Getting started - Installation and setup guides
- Usage guides - Core operations, queries, batch operations, transactions
- DynamoDB patterns - Entity keys, composite keys, time-series, hierarchical data
- Best practices - Query optimization, key design, capacity planning
- Anti-patterns - Common mistakes and how to avoid them
- API reference - Complete API documentation for all packages
- Examples - Real-world code examples for standalone and Amplify
- Core package documentation - Pattern helpers and utilities
- Stats package documentation - Monitoring and recommendations
- Client package documentation - Standalone TableClient
- Amplify package documentation - Amplify Gen 2 integration
- Complete API reference - Detailed API documentation
The documentation is built with MkDocs and Material theme:
# Install Python dependencies
pip install -r requirements.txt
# Serve documentation locally
python3 -m mkdocs serve
# Build static site
python3 -m mkdocs buildβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Application β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββ΄βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββ ββββββββββββββββββββββββ
β @ddb-lib/client β β @ddb-lib/amplify β
β (Standalone) β β (Amplify Gen 2) β
βββββββββββββββββββββ ββββββββββββββββββββββββ
β β
ββββββββββββββββββββ¬βββββββββββββββββββ
β
ββββββββββββββββββββ΄βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββ ββββββββββββββββββββββββ
β @ddb-lib/core β β @ddb-lib/stats β
β (Utilities) ββββββββββββββββ (Monitoring) β
βββββββββββββββββββββ ββββββββββββββββββββββββ
@ddb-lib/core
- You need pattern helpers for key construction
- You want multi-attribute key utilities
- You're building your own DynamoDB abstraction
- You need expression builders
@ddb-lib/stats
- You want to monitor DynamoDB performance
- You need anti-pattern detection
- You want optimization recommendations
- You're using a custom data access layer
@ddb-lib/client
- You're building a standalone Node.js application
- You want a simplified DynamoDB interface
- You need built-in monitoring and best practices
- You're not using Amplify
@ddb-lib/amplify
- You're using AWS Amplify Gen 2
- You want to monitor Amplify operations
- You need DynamoDB best practices with Amplify
- You want pattern helpers for Amplify keys
This is a monorepo managed with npm workspaces.
# Install dependencies
npm install
# Build all packages
npm run build
# Run all tests
npm run test
# Run tests for a specific package
npm run test -w @ddb-lib/core
# Type check
npm run typecheck
# Lint
npm run lint- Node.js >= 18.0.0
- TypeScript >= 5.0.0
- AWS SDK v3 (peer dependency for @ddb-lib/client)
- aws-amplify (peer dependency for @ddb-lib/amplify)
Contributions are welcome! Please see our contributing guidelines.
MIT
- Documentation - Complete guides and API reference
- GitHub repository
- npm organization
- Examples
The modular architecture allows you to:
- Minimize bundle size: Install only what you need
- Mix and match: Use utilities with any data access layer
- Framework agnostic: Core utilities work everywhere
- Easy migration: Move between standalone and Amplify easily
- Tree-shaking: Unused code is eliminated from your bundle
| Feature | @ddb-lib/client | @ddb-lib/amplify | Raw DynamoDB SDK | Amplify Data |
|---|---|---|---|---|
| Type safety | β | β | β | |
| Pattern helpers | β | β | β | β |
| Performance monitoring | β | β | β | β |
| Anti-Pattern detection | β | β | β | β |
| Simplified API | β | β | β | β |
| Multi-attribute keys | β | β | ||
| GraphQL integration | β | β | β | β |
| Authorization rules | β | β | β | β |
Visit https://ddb-lib.dev for: