How sidth3dr3amer/medora_sandbocx works
Project Type and Purpose
• This is a full-stack decentralized application (“dApp”) for managing patient documents and consent on a blockchain.
• Frontend: React (Vite) SPA that interacts with users and MetaMask.
• Backend: Node.js/Express API that handles authentication, audit logs, consent, document metadata, patient records, and orchestrates blockchain/IPFS interactions.
• Smart Contracts: Solidity code managed by Hardhat (in contracts/, artifacts/, cache/).
• Data stores: MongoDB (configured in backend/src/config/db.js) for off-chain data; IPFS for file storage; Ethereum (Hardhat or testnet) for on-chain consent and audit.
File Structure Highlights
• Top level:
• contracts/, artifacts/, cache/ — smart contract sources, compiled ABIs, build caches.
• backend/ — Express service organized by routes, controllers, services, models, middlewares.
• medora-frontend/ — React/Vite app with components, pages, API client, contexts, utility modules.
• scripts/deploy.js — contract deployment.
• test/medora.test.js — integration or contract tests.
• Backend layers:
• routes → controllers → services → models → database/blockchain.
• services/blockchainService.js, ipfsService.js, hashService.js.
• Frontend layers:
• pages (Dashboard, Upload, Login)
• components (Navbar, ProtectedRoute)
• API client (axios.js)
• MetaMask utilities and cryptographic helpers.
Core Components
a. Presentation Layer
• User’s Web Browser
• React SPA (medora-frontend)
• MetaMask extension (interacts with Web3 provider)
b. API Layer
• Express.js server (backend/src/server.js)
• REST endpoints: /auth, /patients, /documents, /consent, /audit
c. Business Logic & Services
• Auth, Consent, Patient, Document, Audit Controllers & Services
• blockchainService (ethers.js/web3)
• ipfsService (file upload/retrieval)
• hashService (document hashing)
d. Data Stores
• MongoDB (collections: Users, Patients, Documents, Consents, Audits)
• IPFS (file storage)
• Ethereum Blockchain (smart contracts deployed via Hardhat)
e. Smart Contracts
• ConsentContract.sol, DocumentRegistry.sol, etc. (in contracts/)
• Deployment via scripts/deploy.js
• ABIs consumed by both backend and frontend (backend/src/abis, artifacts/)
Relationships & Data Flows
• User ↔ React SPA
• React SPA → Express API (Axios calls) → Controllers → Services → MongoDB
• React SPA → MetaMask → Ethereum node → Smart Contracts
• API (blockchainService) → Ethereum node → Smart Contracts
• API (ipfsService) → IPFS network
• Smart Contracts emit events → backend listeners or frontend subscriptions
• Tests (test/medora.test.js) validate end-to-end behavior and contracts
Architectural Patterns & Principles
• Layered MVC-style backend
• Client-server separation
• On-chain/off-chain split: sensitive data off-chain, proofs & consents on-chain
• Service-oriented internal modules (blockchain, IPFS, hashing)
• Stateless REST API behind authentication middleware