azurespheredev / GridUnity-Assessment
README
GridUnity Take Home Assessment Solution
๐ Features Implemented
- Access directories using
snapshot,list,restore,pruneoperations - Enhance
listoperation to include additional disk-usage metrics - Implement a
checkoperation that scans the database for any corrupted file
content - Use chunking to de-duplicate storage at a more fine-grained level
- GraphQL APIs to test out via tools like
Postman
๐ฆ Architecture
.
โโโ src/
โ โโโ config/ # Database configuration files
โ โโโ entities/ # Database entity definitions
โ โโโ graphql/
โ โ โโโ resolvers/ # GraphQL resolvers
โ โโโ helpers/ # CLI & server helpers
โ โโโ utils/ # Utility modules (hashing, chunking, etc.)
โ โโโ app.ts # Entry point for the Koa + Apollo server
โ โโโ database.ts # Database connection setup
โโโ tests/ # Comprehensive integration & unit tests
โโโ database.sqlite # SQLite database file (generated)
โโโ package.json # Project dependencies & scripts
โโโ tsconfig.json # TypeScript configuration
โ๏ธ Technologies
- Node.js / TypeScript
- GraphQL (Apollo)
- TypeORM (SQLite Database)
- Koa Framework
- Jest (Testing Framework)
โ Prerequisites
- Node.js (20.x or later recommended)
- npm or yarn (preferred)
๐ Installation
-
Clone Repository
git clone https://github.com/azurespheredev/GridUnity-Assessment cd GridUnity-Assessment -
Install Dependencies
yarn install -
Environment Setup
Create a
.envfile (for development):NODE_ENV=development PORT=4000 -
Register Environment Variable (Windows OS)
Make sure you have these dependencies installed globally
npm i -g ts-node typescriptAnd add
<your absolute folder path>/scripts/windowsto PATH in environment variable settings.
โถ๏ธ Usage
In the root directory of the project, run the following:
Snapshot a Directory
backuptool snapshot --target-directory=./data
List Snapshots
backuptool list
Example Output:
SNAPSHOT TIMESTAMP FILE SIZE DISTINCT_SIZE
1 2025-03-31 10:58:31.000 data_001.txt 2750 2750
1 2025-03-31 10:58:31.000 data_002.txt 2727 2727
1 2025-03-31 10:58:31.000 data_003.txt 1855 1855
total 7332
Restore a Snapshot
backuptool restore --snapshot-number=1 --output-directory=./out
Prune a Snapshot
backuptool prune --snapshot=1
Check Data Integrity
backuptool check
๐งช Running Tests
yarn test
๐งช GraphQL Resolver Tests:
โ List snapshots returns correct snapshot details (564 ms)
โ Get snapshot by ID returns correct snapshot (29 ms)
โ Create snapshot from the specific directory (23 ms)
โ Restore snapshot to new directory (20 ms)
โ Snapshotting twice without changes should not duplicate chunk content (24 ms)
โ Pruning snapshot does not affect others (40 ms)
Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 5.325 s
Tests cover snapshot creation, chunk-based deduplication, restores, pruning safety, and integrity verification.
