Architecture Overview
The Fabric integration layer consists of:Ledger Registry
Records document metadata and state changes on the Fabric ledgerScript:
sync-db-to-ledger.jsAudit Log
Captures access events with actor, action, and result detailsScript:
record-access-event.jsExternalToolsService.
Document Registration
Documents are registered on Fabric when citizens approve access requests or during manual synchronization.Synchronization Workflows
Approval Trigger
When a citizen approves an access request, the system automatically syncs their documents to Fabric:If sync fails, the approval is rolled back.
Admin Sync
Administrators can manually synchronize documents from the admin dashboard at
/admin/sync:- Sync All - Registers all approved documents in the database
- Sync Person - Registers documents for a specific person by
id_typeandid_number
Chaincode Invocation
The Node.js script invokes the Fabric chaincode to store document metadata:Script:
sync-db-to-ledger.jsMetadata includes:- Document ID (composite key:
idType:idNumber:docId) - Title
- Issue date
- Expiry date
- File path
- File size
- SHA256 hash
- Issuing entity
- Status (VIGENTE, VENCIDO, etc.)
Script Configuration
Fabric sync scripts:| Environment Variable | Purpose | Default |
|---|---|---|
FABRIC_WORKDIR | Directory containing Fabric client scripts | - |
FABRIC_NODE_BIN | Node.js executable | node |
FABRIC_SYNC_ALL_SCRIPT | Global sync script | sync-db-to-ledger.js |
FABRIC_SYNC_PERSON_SCRIPT | Person-specific sync script | sync-person-to-ledger.js |
EXTERNAL_TOOLS_TIMEOUT_SECONDS | Script execution timeout | 300 |
Querying Fabric Ledger
The system queries Fabric to list documents for verification and display purposes.Document Listing
list-docs.js
Command format:
Parsed Document View
The raw JSON output is parsed intoFabricDocView records:
FabricDocView.java
Access Event Recording
Every document access operation is logged to Fabric with full context.Event Types
CCDigital records the following event types:| Event Type | Triggered By | Purpose |
|---|---|---|
REQUEST_CREATED | Access request creation | Track consent workflow initiation |
DOC_VERIFY_ON_REQUEST | Request approval | Verify document presence in Fabric |
DOC_VIEW_GRANTED | Document view | Log successful document access |
DOC_DOWNLOAD_GRANTED | Document download | Log file download event |
DOC_BLOCK_TRACE_QUERY | Blockchain trace query | Track metadata access |
DOC_ACCESS_CHECK | Authorization validation | Record access attempts |
USER_ACCESS_STATE_CHANGE | Admin state update | Log account enable/suspend/disable |
Recording Audit Events
record-access-event.js
Audit Recording Modes
CCDigital supports two audit recording strategies:Strict Mode
Strict Mode
Audit failure causes the entire operation to fail.Used for critical operations like document access where audit trail is mandatory.
Best Effort Mode
Best Effort Mode
Audit failure is logged but doesn’t block the operation.Used for auxiliary operations where operational continuity is prioritized.
Block Trace Details
Administrators and authorized entities can query blockchain trace details for registered documents.Block Reader Service
read-block-by-ref.js
Returns:
- Block number
- Transaction ID
- Timestamp
- Chaincode name
- Endorser signatures
- Read/write sets
Trace Query in Access Workflow
Audit Event Listing
Query recorded access events from the Fabric ledger:list-access-events.js
Usage in reports:
Synchronization Best Practices
Approval-Triggered Sync: Documents are automatically synced to Fabric when citizens approve access requests, ensuring the ledger reflects the exact documents authorized for access.
Manual Sync for Pre-Existing Data: Administrators should use the sync tools at
/admin/sync to register historical documents that existed before blockchain integration.Configuration Reference
Fabric Scripts
| Variable | Purpose | Default |
|---|---|---|
FABRIC_WORKDIR | Working directory for Fabric client | Required |
FABRIC_NODE_BIN | Node.js executable path | node |
FABRIC_LIST_DOCS_SCRIPT | List documents script | list-docs.js |
FABRIC_BLOCK_READER_SCRIPT | Block detail reader | read-block-by-ref.js |
FABRIC_RECORD_ACCESS_SCRIPT | Audit event recorder | record-access-event.js |
FABRIC_LIST_ACCESS_SCRIPT | Audit event lister | list-access-events.js |
FABRIC_SYNC_ALL_SCRIPT | Global sync script | sync-db-to-ledger.js |
FABRIC_SYNC_PERSON_SCRIPT | Person sync script | sync-person-to-ledger.js |
Network Configuration
Connection Profile: Fabric client scripts must have access to:- Peer endpoint(s) with TLS certificates
- Orderer endpoint(s) with TLS certificates
- Channel name
- Chaincode name
- MSP identity with signing key
FABRIC_CHANNEL_NAMEFABRIC_CHAINCODE_NAMEFABRIC_MSP_IDFABRIC_PEER_ENDPOINTFABRIC_ORDERER_ENDPOINT
Key Services
FabricLedgerCliService.java
FabricLedgerCliService.java
Location:
src/main/java/co/edu/unbosque/ccdigital/service/FabricLedgerCliService.javaQueries documents from Fabric ledger via list-docs.js and parses results into FabricDocView records for application use.Key Methods:listDocsRaw(String idType, String idNumber)- Raw stdout from scriptlistDocsView(String idType, String idNumber)- Parsed document listfindDocById(String idType, String idNumber, String docId)- Find specific document
FabricAuditCliService.java
FabricAuditCliService.java
Location:
src/main/java/co/edu/unbosque/ccdigital/service/FabricAuditCliService.javaRecords access events to Fabric via record-access-event.js and retrieves audit trail via list-access-events.js.Key Methods:recordEvent(AuditCommand cmd)- Write audit event to ledgerlistAccessEvents(String idType, String idNumber, Integer limit)- Query audit log
ExternalToolsService.java
ExternalToolsService.java
Location:
src/main/java/co/edu/unbosque/ccdigital/service/ExternalToolsService.javaGeneric command execution service for invoking external scripts (Fabric Node.js, Indy Python) with timeout and error handling.Key Methods:exec(List<String> command, String workdir, Map<String, String> env)- Execute commandrunFabricSyncAll()- Sync all documentsrunFabricSyncPerson(String idType, String idNumber)- Sync person documents
BlockchainTraceDetailService.java
BlockchainTraceDetailService.java
Location:
src/main/java/co/edu/unbosque/ccdigital/service/BlockchainTraceDetailService.javaRetrieves detailed block/transaction information from Fabric for administrative inspection and audit reports.Key Methods:getBlockDetailByRef(String blockRef)- Get block metadata- Used by admin reporting and trace visualization
Document-to-Ledger Matching
When validating approved documents against Fabric ledger, the system uses flexible matching:- Path matching - Primary strategy, handles both absolute and relative paths
- Title matching - Fallback strategy using case-insensitive comparison
Why flexible matching? Fabric may store absolute paths while the database stores relative paths. The matching logic accommodates both representations.
Admin Dashboard Integration
The admin dashboard at/admin/sync provides:
Sync Status
View last sync timestamp and results for all documents and per-person syncs
Manual Triggers
Execute sync operations on-demand for testing, recovery, or initial data load
Audit Trail
View recent access events and blockchain trace summaries
Error Logs
Review sync failures and script execution errors for troubleshooting
AdminController.java (endpoints: /admin/sync, /admin/sync/run, /admin/sync/person)
Security Considerations
Immutable Audit Log: Events written to Fabric cannot be modified or deleted, providing tamper-proof evidence for compliance and forensic investigation.
