# codershubhammate/block-chain-based-secure-notarization-system architecture

> Architecture diagram of the GitHub repository codershubhammate/block-chain-based-secure-notarization-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codershubhammate/block-chain-based-secure-notarization-system
- Repository: https://github.com/codershubhammate/block-chain-based-secure-notarization-system

## Overview

1. **This is a multi-surface notarization platform, not a single app.**  
   The repo contains three primary runtime surfaces: a **web portal** (`Web-App`), a **desktop console** (`Frontend Desktop Application`), and a **backend orchestration layer** (`backend`). All three are tied together by a shared document/notary/governance model and by the same blockchain contracts.

2. **The web portal is the main end-user entry point.**  
   `Web-App` is a Next.js application with dashboard pages for uploading, verifying, versioning, documents, tokens, and governance. It includes auth UX, wallet/session hooks, liveness/face-scan components, and client-side helpers for API calls, web3, encryption, and PDF handling. The `public/models` directory shows that liveness checks are partially performed in-browser with bundled face-recognition models.

3. **The desktop application is a role-focused console for notaries/admins.**  
   `Frontend Desktop Application` is a packaged desktop frontend with Electron-style entry points (`main.js`, `preload.js`) and separate role-based screens for admin and notary workflows. It also includes a `Remote Auth` sub-application, suggesting a desktop-assisted remote-signing or remote-login path. This surface is optimized for operational users rather than general customers.

4. **The backend is the system’s central orchestrator.**  
   `backend/src` is the main service layer and is organized into clear runtime boundaries:  
   - **routes** for auth, documents, upload, tokens, governance, notaries, users, transactions, disputes, and system  
   - **middleware** for auth, actor context, correlation IDs, rate limiting, and circuit breaking  
   - **services** for storage, config, logging, identity sync, reputation, secrets, maintenance, and startup guards  
   - **workers** for reconciliation, identity sync, reputation updates, cleanup, and scavenging  
   This is the piece that mediates between UI, database, object storage, and blockchain.

5. **Persistent state is split between PostgreSQL and object storage.**  
   The `backend/migrations` and `deployment_validation/migrations` trees show a heavily evolved PostgreSQL schema with tables for users, documents, upload intents, wallet nonces, governance, token audits, notary applications, and system logs. Files and document payloads are not stored in the database; the backend’s storage service points to **AWS S3** as the document vault, with signed URLs used for upload/download flows.

6. **Blockchain is the source of truth for finalized actions.**  
   The `contracts` directory contains the on-chain layer: `DocumentRegistry`, `NotaryRegistry`, `NTK`, `NTKR`, and `BBSNSMultiSig`. These contracts model document finalization, identity/role registry, reputation/token mechanics, and multi-signature governance. ABIs and tests are present, along with deployment scripts, so the repo treats chain interactions as a first-class subsystem rather than a thin integration.

7. **Backend-to-chain interaction is explicitly mediated.**  
   The backend’s `src/blockchain` folder contains a connection layer, nonce manager, KMS-backed signer, registry/notary helpers, and a circuit-breaker state. The readme’s EIP-712 flow matches this: the backend fetches the nonce, assembles a typed payload, collects a signature from the remote wallet, and relays the transaction to the chain. That makes the backend a trusted relay and policy gate, not just a pass-through API.

8. **The document lifecycle is an end-to-end state machine.**  
   A typical flow is: intent creation → S3 upload → payment/token verification → notary assignment → signature/chain relay → on-chain confirmation. The `backend/src/services/document-status.service.js`, `upload` and `documents` routes, plus `workers/reconciliation*` indicate that document state is tracked in both DB and chain, with background jobs reconciling drift and cleaning stale intents.

9. **Identity, liveness, and role assignment are core security boundaries.**  
   The repo contains liveness checks in both client and backend, auth nonces, remote auth, notary registration, wallet normalization, and reputation-related migrations. This suggests identity is not a simple username/password model; it is a combined system of wallet binding, liveness verification, and role status that feeds into notary/admin privileges and document authorization.

10. **Governance is a dedicated subsystem, not an admin afterthought.**  
   Governance is represented by the multisig contract, governance routes/UI, proposal targeting, remote confirm/sign pages, and token audits/deposits. Admin actions appear to be separated from ordinary notarization, with explicit approval workflows and threshold-based execution. That makes governance a distinct path through the system, likely involving multiple signers and on-chain confirmations.

11. **Operational reliability is handled through workers and safety middleware.**  
   The backend includes circuit breakers, rate limiting, correlation/audit-session middleware, and a startup guard. Workers handle eventual-consistency tasks such as identity sync, reconciliation, cleanup of upload intents, and reputation adjustments. Architecturally, this means the system tolerates asynchronous side effects and retries rather than forcing every action to complete synchronously in the request path.

12. **The repo includes a large validation/audit layer alongside the product code.**  
   There are extensive scripts, audits, migration checkers, end-to-end tests, and a `deployment_validation` mirror of the backend. This indicates a strong separation between the operational product and the validation/hardening environment, with tools for schema verification, contract checks, token role checks, and forensic audits. For an architecture diagram, this should be shown as an adjacent compliance/ops lane rather than part of the live request path.

13. **The main external dependencies are material to the architecture.**  
   The system depends on **PostgreSQL** for structured state, **AWS S3** for document storage, a **blockchain network** for finality, and a **relayer/private key or KMS-backed signing authority** for relay transactions. Those integrations are not incidental; they define how data moves and where trust boundaries sit.

14. **Net effect: the architecture is a layered notarization pipeline.**  
   User-facing clients collect intent and identity evidence, the backend enforces policy and manages state, background workers keep the database consistent, object storage holds the documents, and smart contracts provide final immutable state. The key diagram boundary is therefore: **clients → backend/orchestrator → DB/S3/blockchain**, with governance and validation as cross-cutting subsystems.

Main entry points: [`backend/src/server.js`](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/blob/main/backend/src/server.js) (API Core), [`backend/src/blockchain`](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/blockchain) (Chain Bridge), [`contracts/abi`](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/abi) (Deployments), [`backend/migrations`](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/migrations) (PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client surfaces"]
  node_web_app["Web App<br/>nextjs portal"]
  node_desktop_app["Desktop Console<br/>electron console"]
  node_remote_auth["Remote Auth<br/>desktop auth app"]
end

subgraph group_backend["Backend core"]
  node_backend_api["API Core<br/>nextjs/api host<br/>[server.js]"]
  node_routes["Routes<br/>domain endpoints"]
  node_middleware["Middleware<br/>policy layer"]
  node_services["Services"]
  node_blockchain_bridge["Chain Bridge<br/>relay layer"]
  node_workers["Workers<br/>async jobs"]
  node_document_state["Doc State<br/>state machine"]
end

subgraph group_contracts["On-chain layer"]
  node_documents["Documents<br/>notarization contract"]
  node_notary_registry["Notary Registry<br/>role registry"]
  node_token_contracts["Token System<br/>token/reputation"]
  node_multisig{{"Multisig Gov<br/>governance contract"}}
  node_deploy_artifacts["Deployments<br/>abis/scripts"]
end

subgraph group_state["Persistent state"]
  node_postgres[("PostgreSQL<br/>relational state")]
  node_s3[("S3 Vault<br/>object storage<br/>[storage.service.js]")]
end

subgraph group_ops["Validation and ops"]
  node_validation_suite["Validation Suite<br/>audit layer"]
  node_deployment_validation["Deployment Mirror<br/>hardening env"]
  node_docs["Docs<br/>guides"]
end

node_web_app -->|"API calls"| node_backend_api
node_desktop_app -->|"ops calls"| node_backend_api
node_remote_auth -->|"remote auth"| node_backend_api
node_backend_api -->|"routes"| node_routes
node_backend_api -->|"guards"| node_middleware
node_backend_api -->|"orchestrates"| node_services
node_backend_api -->|"relays"| node_blockchain_bridge
node_backend_api -->|"queues jobs"| node_workers
node_routes -->|"updates"| node_document_state
node_document_state -->|"persists"| node_postgres
node_routes -->|"reads/writes"| node_postgres
node_services -->|"stores files"| node_s3
node_services -->|"reads/writes"| node_postgres
node_blockchain_bridge -->|"finalizes docs"| node_documents
node_blockchain_bridge -->|"role sync"| node_notary_registry
node_blockchain_bridge -->|"token ops"| node_token_contracts
node_backend_api -->|"governance"| node_multisig
node_deploy_artifacts -->|"deploys"| node_documents
node_deploy_artifacts -->|"deploys"| node_notary_registry
node_deploy_artifacts -->|"deploys"| node_token_contracts
node_deploy_artifacts -->|"deploys"| node_multisig
node_validation_suite -.->|"audits"| node_backend_api
node_validation_suite -.->|"verifies"| node_blockchain_bridge
node_validation_suite -.->|"checks schema"| node_postgres
node_validation_suite -.->|"checks chain"| node_deploy_artifacts
node_deployment_validation -.->|"mirrors"| node_backend_api
node_deployment_validation -.->|"mirrors"| node_postgres
node_deployment_validation -.->|"verifies"| node_blockchain_bridge
node_docs -.->|"documents"| node_backend_api
node_docs -.->|"documents"| node_multisig

click node_web_app "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/Web-App"
click node_desktop_app "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/Frontend Desktop Application"
click node_remote_auth "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/Frontend Desktop Application/Remote Auth"
click node_backend_api "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/blob/main/backend/src/server.js"
click node_routes "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/routes"
click node_middleware "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/middleware"
click node_services "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/services"
click node_blockchain_bridge "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/blockchain"
click node_workers "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/workers"
click node_document_state "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/blob/main/backend/src/services/document-status.service.js"
click node_postgres "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/migrations"
click node_s3 "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/blob/main/backend/src/services/storage.service.js"
click node_documents "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts"
click node_notary_registry "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts"
click node_token_contracts "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts"
click node_multisig "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts"
click node_deploy_artifacts "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/abi"
click node_validation_suite "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/scripts/audit"
click node_deployment_validation "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/deployment_validation"
click node_docs "https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/documentation"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_app,node_desktop_app,node_remote_auth toneBlue
class node_backend_api,node_routes,node_middleware,node_services,node_blockchain_bridge,node_workers,node_document_state toneAmber
class node_documents,node_notary_registry,node_token_contracts,node_multisig,node_deploy_artifacts toneMint
class node_postgres,node_s3 toneRose
class node_validation_suite,node_deployment_validation,node_docs toneIndigo
```

## Components

### Client surfaces

End-user web and desktop entry points.

- [Web App](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/Web-App): nextjs portal · Primary customer-facing portal for notarization, identity, documents, and governance. · `Web-App`
- [Desktop Console](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/HEAD/Frontend%20Desktop%20Application): electron console · Operational desktop frontend for admin and notary workflows. · `Frontend Desktop Application`
- [Remote Auth](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/HEAD/Frontend%20Desktop%20Application/Remote%20Auth): desktop auth app · Separate remote authentication/signing surface bundled with the desktop ecosystem. · `Frontend Desktop Application/Remote Auth`

### Backend core

Live orchestration, policy, and APIs.

- [API Core](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/blob/main/backend/src/server.js): nextjs/api host · Main backend application shell and request entry point. · `backend/src/server.js`
- [Routes](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/routes): domain endpoints · Auth, upload, document, token, governance, notary, user, transaction, dispute, and system endpoints. · `backend/src/routes`
- [Middleware](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/middleware): policy layer · Authentication, actor context, correlation, rate limiting, and circuit breaking. · `backend/src/middleware`
- [Services](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/services): core services · Storage, configuration, logging, identity sync, reputation, secrets, maintenance, and startup guards. · `backend/src/services`
- [Chain Bridge](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/blockchain): relay layer · Backend blockchain connection, nonce management, KMS signer, and registry helpers. · `backend/src/blockchain`
- [Workers](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/src/workers): async jobs · Reconciliation, cleanup, identity sync, reputation, and scavenging jobs. · `backend/src/workers`
- [Doc State](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/blob/main/backend/src/services/document-status.service.js): state machine · Document lifecycle tracking and state reconciliation across DB and chain. · `backend/src/services/document-status.service.js`

### On-chain layer

Smart contracts and deployment artifacts.

- [Documents](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts): notarization contract · On-chain finalization and document registry. · `contracts/contracts`
- [Notary Registry](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts): role registry · On-chain notary identity and role registry. · `contracts/contracts`
- [Token System](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts): token/reputation · NTK and NTKR token/reputation mechanics. · `contracts/contracts`
- [Multisig Gov](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/contracts): governance contract · Threshold governance and multisig execution layer. · `contracts/contracts`
- [Deployments](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/contracts/abi): abis/scripts · ABIs, deployment scripts, and contract test artifacts. · `contracts/abi`

### Persistent state

Database and object storage boundaries.

- [PostgreSQL](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/migrations): relational state · Structured system state, audits, intents, roles, governance, and identity records. · `backend/migrations`
- [S3 Vault](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/blob/main/backend/src/services/storage.service.js): object storage · Document payload vault used for upload/download flows via signed URLs. · `backend/src/services/storage.service.js`

### Validation and ops

Audit, validation, and recovery tooling.

- [Validation Suite](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/backend/scripts/audit): audit layer · Scripts and audits for schema, roles, relayer, balances, and end-to-end verification. · `backend/scripts/audit`
- [Deployment Mirror](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/deployment_validation): hardening env · Parallel migration and runtime mirror for deployment validation and forensic checks. · `deployment_validation`
- [Docs](https://github.com/codershubhammate/block-chain-based-secure-notarization-system/tree/main/documentation): guides · Architecture, security, governance, database, installation, and walkthrough documentation. · `documentation`

## Connections

- Web App → API Core: API calls · Customer flows submit auth, document, token, and governance requests.
- Desktop Console → API Core: ops calls · Desktop console uses backend APIs for notary/admin workflows.
- Remote Auth → API Core: remote auth · Remote login and signing paths are brokered through backend APIs.
- API Core → Routes: routes · Application shell exposes domain endpoints through route handlers.
- API Core → Middleware: guards · Requests pass through policy, identity, and resilience middleware.
- API Core → Services: orchestrates · Backend services handle config, storage, logging, sync, and startup policy.
- API Core → Chain Bridge: relays · Backend assembles signed transactions and interacts with chain infrastructure.
- API Core → Workers: queues jobs · Long-running consistency and sync tasks are handled asynchronously.
- Routes → Doc State: updates · Document and upload endpoints drive the lifecycle state machine.
- Doc State → PostgreSQL: persists · Document status and audit state are stored in PostgreSQL.
- Routes → PostgreSQL: reads/writes · Domain endpoints operate against structured relational state.
- Services → S3 Vault: stores files · Document payloads are written to object storage and served through signed URLs.
- Services → PostgreSQL: reads/writes · Configuration, audit, identity, and reputation data live in PostgreSQL.
- Chain Bridge → Documents: finalizes docs · Registry helper layer submits document finalization transactions.
- Chain Bridge → Notary Registry: role sync · Notary and registry helpers mediate role and identity on chain.
- Chain Bridge → Token System: token ops · NTK and NTKR interactions support deposits, audits, and rewards.
- API Core → Multisig Gov: governance · Governance routes trigger proposal and threshold-signature flows.
- Deployments → Documents: deploys · ABIs and deployment scripts define contract interfaces and rollout.
- Deployments → Notary Registry: deploys · Deployment artifacts cover registry contracts and tests.
- Deployments → Token System: deploys · Deployment artifacts cover token and reputation contracts.
- Deployments → Multisig Gov: deploys · Deployment artifacts cover multisig governance contracts.
- Validation Suite → API Core: audits · Validation scripts exercise live API, schema, and runtime behavior.
- Validation Suite → Chain Bridge: verifies · Audit scripts check nonce, relayer, roles, balances, and signatures.
- Validation Suite → PostgreSQL: checks schema · Schema and constraint audits validate database integrity.
- Validation Suite → Deployments: checks chain · Bytecode, ABI, and deployment audits validate contract artifacts.
- Deployment Mirror → API Core: mirrors · Parallel validation runtime mirrors the live backend architecture.
- Deployment Mirror → PostgreSQL: mirrors · Validation migrations and state checks mirror production schema.
- Deployment Mirror → Chain Bridge: verifies · Validation scripts re-run relayer and chain-role checks.
- Docs → API Core: documents · System and architecture docs explain backend flows and boundaries.
- Docs → Multisig Gov: documents · Governance and security docs describe multisig execution and policy.
