How hassanuos/nodejs-dynodb-audit-log works
Project type and purpose
• This is a small Node.js “audit‐log” utility. It takes incoming JSON objects, computes what has changed compared to the last stored version in DynamoDB, and writes a new audit record (while marking the prior one as “archived”). It is not a full‐stack web app but rather a backend scripting/tooling component intended to run either via CLI or as part of a larger pipeline.
File structure
• Top‐level files:
• index.js – the entry point of the audit‐log workflow
• DynamoDBWrapper.js – encapsulates all interactions with DynamoDB (CRUD, table creation)
• CreateTable.js – a standalone script to bootstrap the audit‐log table schema
• compareJSON.js / compareJSONNew.js – modules that diff two JSON objects to produce “old_value” and “new_value” pairs
• currentDateTime.js – returns the current timestamp in the required format
• package.json / package-lock.json – declare dependencies (AWS SDK, etc.)
README for additional insights
• Purpose is to maintain an append‐only audit trail in a DynamoDB table, keyed by ref_id.
• Uses AWS DynamoDB SDK (or local DynamoDB for testing).
• Audit entries carry fields: id, ref_id, latest_object, old_value, new_value, new_date, old_date, entry_status.
a. Main components:
1. Input Producer (could be a REST service, CLI, or upstream system that fed JSON records)
2. Audit‐Log Service (the Node.js script)
– index.js as orchestrator
– DynamoDBWrapper module
– JSON diff modules (compareJSON.js / compareJSONNew.js)
– Date util module
3. AWS DynamoDB
4. (Optional) Local DynamoDB instance or AWS CLI for setup/testing
b. Relationships & interactions:
• Input Producer → index.js: sends new JSON object + ref_id
• index.js → DynamoDBWrapper.getLatest(ref_id): fetch last audit entry
• index.js → compareJSON(oldObject, newObject): compute diffs
• index.js → DynamoDBWrapper.writeNewEntry(diffResult): create new audit record
• index.js → DynamoDBWrapper.archiveOldEntry(entry_id): set entry_status = 0 on prior record
• DynamoDBWrapper → DynamoDB: issues GetItem / PutItem / UpdateItem calls
• CreateTable.js → DynamoDB: CreateTable on startup or via AWS CLI
c. Architectural patterns & principles:
• Single Responsibility: each module handles one concern (DB access, JSON diff, timestamp formatting).
• Orchestration: index.js coordinates modules in a linear workflow.
• Idempotency & append‐only: previous records are not deleted, only flagged inactive.
d. Key technologies:
• Node.js
• AWS SDK for JavaScript (v2 or v3)
• AWS DynamoDB (local or remote)
• JSON diff algorithm (custom in compareJSON)