# georgepeg/copychain architecture

> Architecture diagram of the GitHub repository georgepeg/copychain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/georgepeg/copychain
- Repository: https://github.com/georgepeg/copychain

## Overview

CopyChain is a web app for recording and checking copyright registrations using a locally persisted blockchain. The main workflow is: a creator submits a file, the API hashes it and queues a registration, mining commits pending registrations into a block, and users can verify files or inspect the chain. The app also documents peer registration and consensus-based chain resolution. The excerpts show the API, blockchain implementation, and parts of the browser client; UI wiring beyond those excerpts is omitted where it cannot be verified.

Main entry points: [`static/js/script.js`](https://github.com/georgepeg/copychain/blob/main/static/js/script.js) (Browser interactions), [`blockchain.py`](https://github.com/georgepeg/copychain/blob/main/blockchain.py) (Block chain), [`main.py`](https://github.com/georgepeg/copychain/blob/main/main.py) (File verification), [`templates/index.html`](https://github.com/georgepeg/copychain/blob/main/templates/index.html) (Copyright page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_page["Copyright page<br/>[index.html]"]
  node_client["Browser interactions<br/>[script.js]"]
end

subgraph group_api["API service"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_registration["File registration<br/>[main.py]"]
  node_verification["File verification<br/>[main.py]"]
  node_mining["Mining endpoint<br/>[main.py]"]
  node_chain_view["Chain query<br/>[main.py]"]
  node_node_routes["Node endpoints<br/>[main.py]"]
end

subgraph group_ledger["Copyright ledger"]
  node_hashing["File hashing<br/>[blockchain.py]"]
  node_pending["Pending registrations<br/>[blockchain.py]"]
  node_pow["Proof of Work<br/>[blockchain.py]"]
  node_chain["Block chain<br/>[blockchain.py]"]
  node_storage[("JSON chain storage")]
end

subgraph group_network["Peer network"]
  node_consensus["Chain validation / consensus<br/>[blockchain.py]"]
  node_peer(("Peer node"))
end

node_creator(("Creator / user"))

node_creator -->|"uses"| node_page
node_page -.->|"hosts interactions"| node_client
node_client -->|"submits file"| node_registration
node_client -->|"submits file"| node_verification
node_client -->|"requests mining"| node_mining
node_client -->|"requests chain"| node_chain_view
node_api -->|"serves"| node_page
node_registration -->|"hashes upload"| node_hashing
node_registration -->|"queues registration"| node_pending
node_verification -->|"hashes upload"| node_hashing
node_verification -->|"searches records"| node_chain
node_verification -->|"searches pending"| node_pending
node_mining -->|"checks pending"| node_pending
node_mining -->|"computes proof"| node_pow
node_mining -->|"creates block"| node_chain
node_chain_view -->|"reads chain"| node_chain
node_node_routes -->|"resolves conflicts"| node_consensus
node_node_routes -->|"registers peers"| node_consensus
node_consensus -->|"fetches peer chain"| node_peer
node_consensus -->|"replaces chain"| node_chain
node_chain -->|"saves / loads"| node_storage

click node_page "https://github.com/georgepeg/copychain/blob/main/templates/index.html"
click node_client "https://github.com/georgepeg/copychain/blob/main/static/js/script.js"
click node_api "https://github.com/georgepeg/copychain/blob/main/main.py"
click node_registration "https://github.com/georgepeg/copychain/blob/main/main.py"
click node_verification "https://github.com/georgepeg/copychain/blob/main/main.py"
click node_mining "https://github.com/georgepeg/copychain/blob/main/main.py"
click node_chain_view "https://github.com/georgepeg/copychain/blob/main/main.py"
click node_node_routes "https://github.com/georgepeg/copychain/blob/main/main.py"
click node_hashing "https://github.com/georgepeg/copychain/blob/main/blockchain.py"
click node_pending "https://github.com/georgepeg/copychain/blob/main/blockchain.py"
click node_pow "https://github.com/georgepeg/copychain/blob/main/blockchain.py"
click node_chain "https://github.com/georgepeg/copychain/blob/main/blockchain.py"
click node_storage "https://github.com/georgepeg/copychain/tree/main/blocks"
click node_consensus "https://github.com/georgepeg/copychain/blob/main/blockchain.py"

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_page,node_client,node_creator toneBlue
class node_api,node_registration,node_verification,node_mining,node_chain_view,node_node_routes toneAmber
class node_hashing,node_pending,node_pow,node_chain,node_storage toneMint
class node_consensus,node_peer toneRose
```

## Components

### Web interface

- [Copyright page](https://github.com/georgepeg/copychain/blob/main/templates/index.html): `templates/index.html`
- [Browser interactions](https://github.com/georgepeg/copychain/blob/main/static/js/script.js): `static/js/script.js`

### API service

- [FastAPI endpoints](https://github.com/georgepeg/copychain/blob/main/main.py): `main.py`
- [File registration](https://github.com/georgepeg/copychain/blob/main/main.py): `main.py`
- [File verification](https://github.com/georgepeg/copychain/blob/main/main.py): `main.py`
- [Mining endpoint](https://github.com/georgepeg/copychain/blob/main/main.py): `main.py`
- [Chain query](https://github.com/georgepeg/copychain/blob/main/main.py): `main.py`
- [Node endpoints](https://github.com/georgepeg/copychain/blob/main/main.py): `main.py`

### Copyright ledger

- [File hashing](https://github.com/georgepeg/copychain/blob/main/blockchain.py): `blockchain.py`
- [Pending registrations](https://github.com/georgepeg/copychain/blob/main/blockchain.py): `blockchain.py`
- [Proof of Work](https://github.com/georgepeg/copychain/blob/main/blockchain.py): `blockchain.py`
- [Block chain](https://github.com/georgepeg/copychain/blob/main/blockchain.py): `blockchain.py`
- [JSON chain storage](https://github.com/georgepeg/copychain/tree/main/blocks): `blocks`

### Peer network

- [Chain validation / consensus](https://github.com/georgepeg/copychain/blob/main/blockchain.py): `blockchain.py`
- **Peer node**

### Other components

- **Creator / user**

## Connections

- Creator / user → Copyright page: uses (evidence: `ReadMe.md`)
- Copyright page → Browser interactions: hosts interactions
- Browser interactions → File registration: submits file (evidence: `static/js/script.js`)
- Browser interactions → File verification: submits file (evidence: `static/js/script.js`)
- Browser interactions → Mining endpoint: requests mining (evidence: `static/js/script.js`)
- Browser interactions → Chain query: requests chain (evidence: `static/js/script.js`)
- FastAPI endpoints → Copyright page: serves (evidence: `main.py`)
- File registration → File hashing: hashes upload (evidence: `main.py`)
- File registration → Pending registrations: queues registration (evidence: `main.py`)
- File verification → File hashing: hashes upload (evidence: `main.py`)
- File verification → Block chain: searches records (evidence: `main.py`)
- File verification → Pending registrations: searches pending (evidence: `main.py`)
- Mining endpoint → Pending registrations: checks pending (evidence: `main.py`)
- Mining endpoint → Proof of Work: computes proof (evidence: `main.py`)
- Mining endpoint → Block chain: creates block (evidence: `main.py`)
- Chain query → Block chain: reads chain (evidence: `main.py`)
- Node endpoints → Chain validation / consensus: resolves conflicts (evidence: `main.py`)
- Node endpoints → Chain validation / consensus: registers peers (evidence: `main.py`)
- Chain validation / consensus → Peer node: fetches peer chain (evidence: `blockchain.py`)
- Chain validation / consensus → Block chain: replaces chain (evidence: `blockchain.py`)
- Block chain → JSON chain storage: saves / loads (evidence: `blockchain.py`)
