
Rhino-Merge Framework
A distributed file management system built with Go, that lets you merge multiple Google Drives into a single storage unit with file compression, chunk encryption, and a P2P content-addressable storage network.
Timeline
2 Months
Role
Distributed Systems Developer
Team
Solo
Status
CompletedTechnology Stack
Key Challenges
- Designing zero-copy streaming AES-256-CTR encryption and decryption pipelines in Go
- Implementing SHA-1 content-addressable storage (CAS) sharded directory paths
- Dynamic multi-account Google Drive chunk placement and live quota tracking
- Multi-tenant database manifest isolation and OAuth token encryption at rest
Key Learnings
- Raw TCP socket programming, framing protocols, and gob serialization in Go
- GORM schema modeling with Neon PostgreSQL and transaction rollback test fixtures
- Google Drive API v3 batch operations, quotas, and OAuth loopback consent flows
- Vue 3 + Pinia + Vite modern SPA architecture embedded into a single Go binary
- Docker multi-stage builds and Caddy automated TLS reverse proxy deployment
RIHNO Framework ๐ฆ: Distributed Cloud & P2P Storage Engine
Overview
RIHNO Framework is an advanced distributed storage system built in Go (1.25) featuring two tightly integrated subsystems that share a unified on-disk storage and cryptographic engine:
- Peer-to-Peer Content-Addressable Storage (CAS): Nodes communicate over raw TCP, storing file chunks on local disk using a SHA-1 content-addressable path hierarchy, and encrypting every byte with AES-256-CTR before disk writes or network transmission. Nodes without a local file query peers across the mesh network and stream data back on demand.
- Google Drive Pooling Engine & Web Portal: Pools multiple free Google Drive accounts (15GB each) into one virtually infinite storage volume. Files are compressed with DEFLATE, encrypted client-side, split into chunks, and uploaded concurrently to whichever registered account has the most free space. All chunks and file manifests are tracked in a shared PostgreSQL database (e.g. Neon) and accessible through a Cobra CLI and a multi-user Vue 3 web portal.
๐ฏ Key Features
๐ Peer-to-Peer Content-Addressable Storage
- Raw TCP Transport: Custom framing protocol (
IncomingMessagevsIncomingStream) separating discrete RPC control messages from high-throughput raw file streams. - SHA-1 Path Sharding: Prevents flat directory bottleneck by sharding hash digests into 5-character nested subdirectories (e.g.
68044/29f74/181a6/...). - P2P Mesh Discovery & Replication: Nodes broadcast
MessageStoreFileto connected peers for automatic replication and fetch missing files viaMessageGetFile.
โ๏ธ Google Drive Multi-Account Pooling
- Virtual Unified Storage: Pools $N$ registered 15GB Google Drive accounts into a unified virtual disk, eliminating single-account file size limits.
- Smart Chunk Placement: Concurrent multi-part uploads placed dynamically on whichever account currently has the greatest available capacity.
- Selective DEFLATE Compression: Automatically compresses chunks with DEFLATE, retaining compressed data only if it yields genuine space savings while bypassing already-compressed media.
- AES-256-CTR Streaming Crypto: Stream-encrypts file bytes with AES-256 in Counter (CTR) mode with a fresh, random Initialization Vector (IV) prepended per chunk.
๐ฅ๏ธ Multi-User Web Portal & Modern UI
- Vue 3 + Vite SPA: Drive-like user interface with full-page drag-and-drop file uploads, search, and storage consumption bars per connected Drive account.
- Single Binary Distribution: The built Vue 3 frontend is embedded directly into the Go binary (
go:embed), enabling self-contained deployments with zero runtime Node.js dependency. - Multi-Tenant Isolation: Multi-user authentication using Gin, HTTP sessions, and GORM with scoped user tenant isolation.
๐ ๏ธ Powerful Cobra CLI
- Comprehensive command-line suite:
rhino account add/list/remove,rhino put,rhino get,rhino ls,rhino status, andrhino serve. - Automated OAuth2 loopback redirect consent flow for seamless Google account linking.
โ๏ธ Architecture & Subsystems
rhino-framework/
โโโ main.go # Entry point for bare TCP listener
โโโ server.go # FileServer: P2P store/get API, peer map, broadcast
โโโ storage/ # CAS on-disk storage & crypto engine
โ โโโ store.go # Store, CASPathTransformFunc (SHA-1 path sharding)
โ โโโ crypto.go # AES-256-CTR streaming crypto, MD5 key hashing
โโโ p2p/ # Transport & networking layer
โ โโโ transport.go # Transport & Peer interfaces
โ โโโ tcp_transport.go # TCPTransport (dial/accept loops, stream handling)
โ โโโ message.go # RPC struct + framing byte constants
โโโ drivepool/ # Google Drive pooling domain logic
โ โโโ pool.go # Pool / Account: PutStream/GetStream concurrent engine
โ โโโ placement.go # Dynamic quota tracker & chunk placement
โ โโโ manifest/ # GORM models (Account, VirtualFile, Chunk)
โ โโโ gdrive/ # Google Drive API v3 client wrapper
โโโ db/ # Shared PostgreSQL connection & migrations (Neon)
โ โโโ db.go # Pooled *gorm.DB connection
โ โโโ migrate.go # Idempotent SQL migration runner
โโโ backend/ # Gin-based REST API & SPA embedding
โ โโโ server.go # Gin Engine, routes & graceful shutdown
โ โโโ handlers.go # File & account CRUD handlers
โ โโโ dist/ # Embedded Vue 3 static distribution
โโโ frontend/ # Vue 3 + Vite SPA dashboard
โ โโโ src/ # Components, views, Pinia stores
โ โโโ tests/ # Vitest test suite
โโโ cmd/rhino/ # Cobra CLI binary & `rhino serve` entrypoint๐ Security & Cryptography
- At-Rest Token Encryption: All Google OAuth refresh tokens are encrypted at rest in PostgreSQL with a 32-byte master key (
RHINO_TOKEN_ENCRYPTION_KEY). - Client-Side Chunk Encryption: File chunks are encrypted locally prior to transmission; raw file data is never visible to Google Drive or intermediate network peers.
- Key Obfuscation: Storage keys sent over the P2P wire are hashed via MD5 to prevent plaintext filename inspection by network eavesdroppers.
๐ ๏ธ CLI Usage Guide
# Set user identity
export RHINO_USER=souvik
# Connect Google Drive accounts via browser OAuth loopback
bin/rhino account add --label personal-drive
bin/rhino account add --label secondary-drive
# List connected accounts and free capacity
bin/rhino account list
# Output:
# personal-drive 14.8 GiB free of 15.0 GiB
# secondary-drive 13.2 GiB free of 15.0 GiB
# Upload a file across pooled accounts
bin/rhino put ~/videos/demo.mp4 --as videos/demo.mp4
# Check pooled virtual drive status
bin/rhino status
# Output: 2/2 accounts healthy | 30.0 GiB total | 28.0 GiB free | 1 files
# Retrieve and reconstruct file
bin/rhino get videos/demo.mp4 ~/restored_demo.mp4๐คธ Quick Start & Local Setup
1. Prerequisites
- Go: Version 1.25 or newer
- PostgreSQL: Neon DB connection string or local Postgres 14+
- Google Cloud OAuth: Google Cloud Console project with Google Drive API enabled and OAuth client JSON (
client_secret.json)
2. Clone & Build CLI
git clone https://github.com/Souvik-223/rhino-merge-framework.git
cd rhino-merge-framework
go mod download
# Build binaries
go build -o bin/fs .
go build -o bin/rhino ./cmd/rhino3. Run the Web Portal
# Build frontend and compile embedded portal binary
make build-frontend
make build-portal
# Start portal server
./bin/rhino serve4. Deploying with Docker Compose & Caddy
cp .env.example .env
mkdir -p secrets
# Generate security keys
echo -n "$(openssl rand -base64 32)" > secrets/session_secret.txt
echo -n "postgres://user:pass@host/db?sslmode=require" > secrets/database_url.txt
echo -n "$(openssl rand -hex 32)" > secrets/token_encryption_key.txt
cp client_secret.json secrets/client_secret.json
# Launch containerized stack
docker compose up -d --build๐งช Comprehensive Automated Testing
The entire P2P and Drive pooling test suites run against in-memory mock stores and transactional PostgreSQL rollbacks without requiring real Google Cloud credentials:
# Run all Go unit and integration tests
export DATABASE_URL="postgres://postgres:postgres@localhost:5432/rhino_dev?sslmode=disable"
go test ./... -v
# Run frontend Vitest test suite
cd frontend
npm run test