How zs0c131y/trustvault works
Project Type and Purpose
• TrustVault is a hybrid full-stack system that combines blockchain smart contracts with a traditional RESTful backend and web-based frontend.
• The focus is on property registration/ownership transfers and document verification, integrating Ethereum smart contracts (PropertyRegistry.sol and DocumentVerification.sol) along with IPFS for decentralized file storage.
• Security is a paramount design aspect with JWT authentication, input sanitization, CSRF protections, and HTTP security headers.
Main Components
a. Frontend:
– Represented by the public directory with HTML, CSS, and JavaScript files.
– Includes pages for property registration, document verification, government dashboards, and user management.
– Uses Web3.js to interact with the blockchain and Firebase for authentication.
b. Backend API Server:
– Built in Node.js/Express (entry point: server.js) that handles RESTful API requests.
– Uses middleware (e.g., authProtection, csrfProtection, etc.) and models (MongoDB models in the models folder).
– Manages business logic, file uploads, and integration with the blockchain.
c. Blockchain & Smart Contracts:
– Two contracts (PropertyRegistry.sol and DocumentVerification.sol) compiled by Hardhat.
– Deployment artifacts and configuration files reside in the artifacts, contracts, and deployments directories.
– The backend and frontend interact with these contracts via Web3.js.
d. Database:
– A MongoDB database is used for storing user details, transaction records, logs, etc.
– Represented by models in the project.
e. Services and Utilities:
– Services like BlockchainSync.js, IPFSService.js, and IPFSVerificationService.js indicate background processes managing blockchain state syncing and IPFS integration.
– Utility functions for logging and error handling as found in the utils folder.
Architectural Relationships and Data Flow
– Users interact with the frontend (client-side HTML/JS) which makes REST API calls to the backend server.
– The backend processes these requests, validates access via middleware, and interacts with both MongoDB (for data storage) and the Ethereum network (invoking smart contracts) using Web3.js.
– Smart contracts are deployed on the Ethereum blockchain (local development with Hardhat) for secure verification and registry operations.
– IPFS is integrated for decentralized file storage of document content, where file hashes are stored on-chain for verification.
– External authentication services (e.g., Firebase Authentication) might be used to manage user sessions.
Architectural Patterns & Design Principles
– Layered Architecture: Separates concerns between presentation (frontend), business logic (backend), and data storage (MongoDB and blockchain).
– Microservices-like Separation: Even though it is a monolithic repository, distinct directories for middleware, services, and models reflect separation of concerns.
– Blockchain Integration: Hybrid approach keeping off-chain data in a database while maintaining security-critical data on-chain.
– Security-Oriented Design: Emphasis on JWT-based authentication, rate limiting, and middleware for validating inputs and protecting against CSRF/XSS.
Putting It All Together
Layer 1 – User Interface (Frontend: HTML/JS/CSS).
Layer 2 – API Gateway (Express server with middleware).
Layer 3 – Data Management (MongoDB database and file storage via IPFS).
Layer 4 – Verification & Integrity Layer (Ethereum smart contracts on the blockchain).