How baseprime/dynamodb works
Main Components
• Client Layer: This represents the applications or scripts that use the library. They call methods like “dynamo.define” or “Account.create”, “Account.update”, etc.
• API / Model Definition Module: This layer is represented by the main index.js and the “lib” directory. It exposes core data mapper methods such as define(), create(), get(), update(), destroy(), query(), scan(), and other operations. The lib modules (e.g. batch.js, createTables.js, expressions.js, item.js, etc.) abstract the internal operations.
• Schema and Validation: The library integrates with Joi for schema definitions and validation. This component is part of the model definition and is referenced in the schema parts of each model.
• Command & Utility Layer: This includes various helper functions and utilities located in files like utils.js and serializer.js in the lib directory.
• Examples & Test Suites: Although not part of the runtime architecture, the examples and tests (in the “examples” and “test” directories) illustrate how the library is intended to be used.
• Integration with AWS SDK: Internally, the library makes calls to the AWS SDK’s DynamoDB client. This runtime dependency acts as the bridge to the actual DynamoDB service.
Relationships and Interactions
• The client code calls the API exposed by the library.
• The API layer (model definitions and operations) validates input using defined schemas (via Joi) and converts data into DynamoDB-friendly formats using serializer and other utilities.
• For each operation (such as create, update, query), the API layer builds the corresponding DynamoDB request and interacts with the AWS SDK.
• The AWS SDK then communicates with the actual AWS DynamoDB service (which can be deployed on AWS infrastructure).
• Optional components include logging and configuration of custom AWS SDK instances, as highlighted in the README.
Architectural Patterns and Design Principles
• Modular design: Each functionality (CRUD operations, scanning, query filtering, table creation) is implemented in its own module under the “lib” directory.
• Chainable APIs: By providing chainable methods for queries and scans, the architecture encourages a fluid interface.
• Configuration flexibility: The library supports dynamic table names and custom configurations for throughput or logging, indicating a design that favors convention over configuration while still providing flexibility.
• Testing and CI: With directories and files for tests and continuous integration configurations (e.g., .circleci, .travis.yml, Dockerfile), there is a clear emphasis on automated testing and deployment.
Relevant Technologies, Frameworks, and Libraries
• Node.js, AWS SDK for DynamoDB, Joi for data validation.
• Testing frameworks (as seen in the “test” directory).
• Docker and Travis for CI/CD.
• Helper libraries for logging and expressions.