Consortium-based Criminal Data Management System - Backend API
The CDMS Backend provides a secure, blockchain-based API for managing criminal records with end-to-end encryption, access control, and audit trails. Built on Hyperledger Fabric with HashiCorp Vault for key management.
- 🔐 End-to-End Encryption: AES-256-GCM encryption with Vault key management
- 🔗 Blockchain Storage: Hyperledger Fabric for immutable record storage
- 👥 Multi-Organization Support: Consortium-based architecture
- 🛡️ Access Control: Role-based and attribute-based access control
- 📊 Audit Trails: Comprehensive logging and audit capabilities
- 📁 Flexible Storage: Local filesystem or MinIO object storage
- 🔍 Search & Filter: Advanced record querying capabilities
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend │ │ Backend API │ │ Blockchain │
│ (React) │◄──►│ (Express) │◄──►│ (Fabric) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ Vault (KMS) │
│ (Encryption) │
└─────────────────┘
│
▼
┌─────────────────┐
│ Storage │
│ (Local/MinIO) │
└─────────────────┘
- Node.js >= 14.0.0
- npm >= 6.0.0
- Hyperledger Fabric network running
- HashiCorp Vault server
- (Optional) MinIO for object storage
-
Clone and navigate to backend directory:
cd cdms-backend -
Install dependencies:
npm install
-
Run setup script:
node setup.js
-
Configure environment:
cp env.example .env # Edit .env with your configuration -
Start the server:
npm start
Create a .env file with the following variables:
# Server Configuration
PORT=3000
NODE_ENV=development
FRONTEND_URL=http://localhost:5173
# Vault Configuration
VAULT_ADDR=http://127.0.0.1:8200
VAULT_TOKEN=your-vault-token-here
VAULT_MOUNT_PATH=cdms-kms
# Blockchain Configuration
CHANNEL_NAME=mychannel
CONTRACT_NAME=cdmscontract
# Storage Configuration
USE_MINIO=false
MINIO_ENDPOINT=localhost
MINIO_PORT=9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_BUCKET=cdms-filesPOST /login- User loginGET /auth/me- Get current user infoPOST /auth/certificate- Upload user certificate
POST /record/upload- Upload encrypted recordGET /record/:id/download- Download and decrypt recordGET /record/:id/metadata- Get record metadataGET /records- List all records (with filtering)GET /records/:id- Get specific recordGET /records/case/:caseId- List records by case
POST /policy- Create access policyGET /policy/:id- Get policy detailsGET /policies- List all policiesPUT /policies/:id/update- Update policyDELETE /policies/:id- Delete policy
POST /access/grant- Grant access to recordPOST /access/revoke- Revoke accessGET /access/check- Check access permissionsGET /access/list- List access permissions
POST /audit- Add audit entryGET /audit/trail/:recordId- Get audit trailGET /audit/list- List all audit entries
GET /health- API health checkGET /vault/status- Vault connection statusGET /storage/status- Storage system status
curl -X POST http://localhost:3000/record/upload \
-H "Content-Type: multipart/form-data" \
-F "file=@evidence.pdf" \
-F "case_id=CASE-001" \
-F "record_type=Evidence" \
-F "userId=InvestigatorA" \
-F "org=Org1"curl -X GET "http://localhost:3000/record/RECORD-123/download?userId=InvestigatorA&org=Org1" \
-o downloaded_file.pdfcurl -X GET "http://localhost:3000/records?userId=InvestigatorA&org=Org1&caseId=CASE-001"curl -X POST http://localhost:3000/policy \
-H "Content-Type: application/json" \
-d '{
"policy_id": "policy-001",
"rules": [
{
"action": "read",
"resource": "record",
"conditions": {
"org": "Org1"
}
}
],
"categories": ["Evidence", "FIR"]
}' \
-F "userId=AdminOrg1" \
-F "org=Org1"Register users with the blockchain network:
# Register District Police A
node registerDistrictPoliceA.js
# Register District Police B
node registerDistrictPoliceB.js
# Register Forensics Officers
node registerForensicsOfficerA.js
node registerForensicsOfficerB.js
# Register Investigators
node registerInvestigatorA.js
node registerInvestigatorB.js- AES-256-GCM for file encryption
- Vault Transit Engine for key management
- Unique DEK per record
- Authenticated encryption with integrity verification
- Role-based access (Admin, Investigator, Forensics Officer)
- Organization-based access control
- Attribute-based policies
- Time-based access expiration
- Immutable audit trails on blockchain
- Comprehensive logging of all operations
- User activity tracking
- Data integrity verification
cdms-backend/
├── api.js # Main API server
├── backend.js # Core backend logic
├── storage.js # File storage abstraction
├── setup.js # Setup and initialization
├── chaincode-methods.js # Blockchain method documentation
├── register*.js # User registration scripts
├── wallet/ # Fabric wallet (identities)
├── files/ # Local file storage
├── logs/ # Application logs
└── package.json # Dependencies
- Add route handler in
api.js - Add corresponding method in
backend.jsif needed - Update chaincode methods in
chaincode-methods.js - Add validation middleware if required
- Update documentation
# Run health checks
curl http://localhost:3000/health
# Check Vault status
curl http://localhost:3000/vault/status
# Check storage status
curl http://localhost:3000/storage/status-
Vault Connection Failed
- Ensure Vault server is running
- Check VAULT_ADDR and VAULT_TOKEN in .env
- Verify Vault is unsealed
-
Blockchain Connection Failed
- Ensure Fabric network is running
- Check wallet contains valid identities
- Verify connection profiles exist
-
File Storage Issues
- Check files directory permissions
- Verify MinIO configuration if using object storage
- Ensure sufficient disk space
Check application logs in the logs/ directory for detailed error information.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review the API documentation
- Check blockchain and Vault logs
- Ensure all prerequisites are met