# sensedeep/dynamodb-onetable architecture

> Architecture diagram of the GitHub repository sensedeep/dynamodb-onetable, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sensedeep/dynamodb-onetable
- Repository: https://github.com/sensedeep/dynamodb-onetable

## Overview

##### Main Components

a) Core Library Components:
- Schema Management System
- Model Layer
- Expression Builder
- Type Management System
- Table Operations Handler
- Metrics Collection System

b) External Integration Points:
- AWS DynamoDB Client Interface (both v2 and v3 SDK support)
- TypeScript Type System Integration
- Migration Tools Integration

##### Key Architectural Elements

**┌─ Application Layer ─────────────────────┐**
- User Application Code                   │
- ┬─────────────────────────┘
- ↓
**┌─ OneTable API Layer ───────────────────────────────────────┐**
- ┌─────────────┐  ┌──────────┐  ┌────────────────────┐     │
- Table Class │  │  Models  │  │ TypeScript Types   │     │
- ┬──────┘  └────┬─────┘  └──────────┬─────────┘     │
- ↓              ↓                    ↓               │
- ┌─────────────────────────────────────────────────────┐   │
- Schema Management System               │   │
- ┬───────────────────────┘   │
- ┬─┴───────────────────────────┘
- ↓
**┌─ Core Processing Layer ────────────────────────────────────┐**
- ┌─────────────┐ ┌──────────────┐ ┌────────────────────┐   │
- Expression  │ │ Type         │ │ Validation &       │   │
- Builder    │ │ Marshalling  │ │ Encoding           │   │
- ┬──────┘ └──────┬───────┘ └──────────┬─────────┘   │
- ┬──┴────────────────────┘             │
- ┼──────────────────────────────────────┘
- ↓
**┌─ Database Layer ──────────────────────────────────────────┐**
- ┌─────────────────────────────────────────────────────┐   │
- DynamoDB Client Interface              │   │
- ┬───────────────────────────┘   │
- ┬─┴───────────────────────────────┘
- ↓
**┌─ AWS DynamoDB ─────────────────────────────────────────────┐**

- ┘

##### Important Relationships

- Bidirectional flow between Schema Management and Model Layer
- Type inference flow from Schema to TypeScript types
- Transaction flow through the various layers
- Validation and encoding pipeline

##### Implementation Details

- Clear component boundaries

##### Additional Elements

Small sidebars or callouts showing:
- Supported data types
- Index types (GSI, LSI)
- Key template syntax
- Common use patterns

- Multiple layers
- Export to common formats
- Collaborative editing

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Application["Application Layer"]
        UserApp["User Application Code"]:::application
    end

    subgraph API["OneTable API Layer"]
        Table["Table Class"]:::core
        Models["Models"]:::core
        TypeSystem["TypeScript Types"]:::types
        Schema["Schema Management System"]:::schema
    end

    subgraph Core["Core Processing Layer"]
        Expression["Expression Builder"]:::core
        TypeMarshalling["Type Marshalling"]:::core
        Validation["Validation & Encoding"]:::core
        ErrorHandling["Error Handling"]:::core
        Metrics["Metrics Collection"]:::core
        Utils["Utility Functions"]:::utils
    end

    subgraph DB["Database Layer"]
        DynamoClient["DynamoDB Client Interface"]:::aws
        subgraph SDKs["AWS SDK Support"]
            SDKV2["SDK v2"]:::aws
            SDKV3["SDK v3"]:::aws
        end
    end

    AWS["AWS DynamoDB"]:::aws

    %% Relationships
    UserApp --> Table
    UserApp --> Models
    Table --> Schema
    Models --> Schema
    TypeSystem --> Schema
    Schema --> Expression
    Schema --> TypeMarshalling
    Schema --> Validation
    Expression --> DynamoClient
    TypeMarshalling --> DynamoClient
    Validation --> DynamoClient
    ErrorHandling --> DynamoClient
    Metrics --> DynamoClient
    DynamoClient --> SDKV2
    DynamoClient --> SDKV3
    SDKV2 --> AWS
    SDKV3 --> AWS

    %% Click Events
    click Schema "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/Schema.js"
    click Models "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/Model.js"
    click Expression "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/Expression.js"
    click Table "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/Table.js"
    click Metrics "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/Metrics.js"
    click DynamoClient "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/Dynamo.js"
    click TypeSystem "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/index.d.ts"
    click ErrorHandling "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/Error.js"
    click Utils "https://github.com/sensedeep/dynamodb-onetable/blob/main/src/utils.d.ts"

    %% Styles
    classDef application fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef types fill:#c9f,stroke:#333,stroke-width:2px
    classDef schema fill:#fc9,stroke:#333,stroke-width:2px
    classDef aws fill:#9f9,stroke:#333,stroke-width:2px
    classDef utils fill:#ccc,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Application Components"]:::application
        L2["Core Components"]:::core
        L3["Type System"]:::types
        L4["Schema Management"]:::schema
        L5["AWS Integration"]:::aws
        L6["Utilities"]:::utils
    end
```
