# syarifulmujaddiq/certificate-gen-ver architecture

> Architecture diagram of the GitHub repository syarifulmujaddiq/certificate-gen-ver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/syarifulmujaddiq/certificate-gen-ver
- Repository: https://github.com/syarifulmujaddiq/certificate-gen-ver

## Overview

##### Project Type and Purpose
- This is a full-stackBlockchain-enabled certificate management and verification system.
- Purpose: Allow an admin to generate PDF certificates, hash them (SHA-256), store on IPFS via Pinata, record the CID/hash on a smart contract, and allow both admin and the public to verify certificates (via file upload or QR code).

##### File Structure
- Top-level directories:
- backend/      – Express.js REST API (controllers, routes, middleware, ABI)
- frontend/     – React + Tailwind CSS single-page app (components, public assets)
- smart-contract/ – Hardhat project (Solidity contracts, deployment/test scripts)
- Patterns:
- MVC-ish separation in backend (controllers ↔ routes ↔ middleware)
- Componentized React UI
- Separate concerns for on-chain logic (smart-contract) vs off-chain services
- Config & deployment artifacts:
- .env for secrets and RPC URL
- Hardhat config and deploy scripts
- Pinata API integration in backend via HTTP

##### README for Additional Insights
- Tech stack: React, Tailwind, Express, JWT auth, Hardhat/Ethers, IPFS/Pinata, SHA-256
- Workflow:
1. Deploy smart contract on local Hardhat node
2. Copy ABI + contract address to backend
3. Start backend Express
4. Start React frontend
- Features: Admin login, certificate generation + PDF + IPFS + blockchain, verification by upload or QR

a. Main Components (group into logical layers):
1. Presentation Layer
– Admin & Public React UI (Run in browser)
2. API Layer
– Express.js backend
- AuthController (JWT)
- CertificateController (PDF gen, hashing, IPFS upload)
- Routes (authRoutes, certificateRoutes)
3. Blockchain Layer
– Ethereum test network (Hardhat node)
– CertificateRegistry smart contract (ABI in backend/abi)
4. External Services
– IPFS via Pinata (CID storage)
5. Data Stores / Temporary Storage
– Temporary uploads/ folder (PDF staging)
– cert-metadata.json (runtime metadata)
b. Relationships & Data Flow:
1. User (Admin) → React form → HTTP POST /api/auth → JWT issued
2. Admin → fills generate form → HTTP POST /api/certificate/generate → backend:
- Generates PDF → Computes SHA-256 hash → Uploads PDF to Pinata →
- Calls smart contract method via Ethers RPC → Stores hash & CID on-chain → Responds with tx/hash
3. Public User → Scans QR (hash) → React triggers GET /api/certificate/verify/:hash →
- Backend optionally queries smart contract → Verifies against stored hash/CID → Returns status
4. Backend ↔ Hardhat Node (via RPC URL)
5. Backend ↔ Pinata API (via API_KEY/SECRET)
c. Architectural Patterns & Design Principles:
- Separation of concerns: UI vs API vs blockchain vs IPFS
- MVC-style organization in backend
- Stateless JWT authentication
- Eventual consistency: on-chain writes are asynchronous
- Component-based UI for reusability
d. Key Technologies:
- React + Tailwind CSS (frontend)
- Express.js + JWT + axios (backend)
- Hardhat + Ethers.js + Solidity (smart-contract)
- IPFS (Pinata) for off-chain storage
- SHA-256 for integrity

##### Elements
- Labels:
- “Admin UI”, “Public UI”, “Express API”, “Smart Contract”, “IPFS Pinata”
- Request/response flows (HTTP, RPC, REST)
- Annotations:
- Environment variables (.env) feeding into backend
- ABI artifact feeding into the API
- Call out the use of SHA-256 hash function

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        style Presentation Layer fill:#cce5ff,stroke:#333,stroke-width:1px
        AdminUI["Admin UI"]:::frontend
        PublicUI["Public UI"]:::frontend
        AdminUI -->|POST /api/auth| AuthAPI
        AdminUI -->|POST /api/certificate/generate| CertGenAPI
        PublicUI -->|GET /api/certificate/verify/:hash| CertVerifyAPI
    end

    %% API Layer
    subgraph "API Layer" 
        style API Layer fill:#d4edda,stroke:#333,stroke-width:1px
        AuthAPI["Express API<br/>(backend/app.js)"]:::backend
        AuthController["AuthController"]:::backend
        CertController["CertificateController"]:::backend
        AuthRoutes["authRoutes"]:::backend
        CertRoutes["certificateRoutes"]:::backend
        AuthMiddleware["JWT Auth Middleware"]:::backend
        ABI["CertificateRegistry ABI"]:::backend
        TempStorage["Temporary Storage<br/>(backend/assets/)"]:::backend
        Env["Environment Variables<br/>(.env)"]:::backend
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        style Blockchain Layer fill:#fff3cd,stroke:#333,stroke-width:1px
        HardhatNode["Hardhat Node"]:::blockchain
        SmartContract["CertificateRegistry.sol"]:::blockchain
        HardhatConfig["hardhat.config.js"]:::blockchain
        DeployScript["deploy.js"]:::blockchain
        TxHelper["getTransactionInput.js"]:::blockchain
        Tests["Certificate.test.js"]:::blockchain
    end

    %% External Services
    subgraph "External Services"
        style External Services fill:#f8d7da,stroke:#333,stroke-width:1px
        IPFS["IPFS via Pinata"]:::external
    end

    %% Relationships
    AuthAPI --> AuthRoutes
    AuthRoutes --> AuthController
    AuthController --> AuthMiddleware
    CertGenAPI --> CertRoutes
    CertRoutes --> CertController
    CertController --> TempStorage
    CertController -->|SHA-256| CertController
    CertController --> IPFS
    CertController --> ABI
    CertController --> HardhatNode
    CertVerifyAPI --> CertController
    AuthAPI --> Env
    CertGenAPI --> Env
    AuthAPI --> ABI
    AuthAPI --> HardhatNode

    HardhatNode --> SmartContract
    HardhatNode --> HardhatConfig
    HardhatNode --> DeployScript
    HardhatNode --> TxHelper
    HardhatNode --> Tests

    %% Click Events
    click AdminUI "https://github.com/syarifulmujaddiq/certificate-gen-ver/tree/main/frontend/"
    click PublicUI "https://github.com/syarifulmujaddiq/certificate-gen-ver/tree/main/frontend/"
    click AuthAPI "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/backend/app.js"
    click AuthController "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/backend/controllers/authController.js"
    click CertController "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/backend/controllers/certificateController.js"
    click AuthRoutes "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/backend/routes/authRoutes.js"
    click CertRoutes "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/backend/routes/certificateRoutes.js"
    click AuthMiddleware "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/backend/middleware/auth.js"
    click ABI "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/backend/abi/CertificateRegistry.json"
    click TempStorage "https://github.com/syarifulmujaddiq/certificate-gen-ver/tree/main/backend/assets/"
    click SmartContract "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/smart-contract/contracts/CertificateRegistry.sol"
    click HardhatConfig "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/smart-contract/hardhat.config.js"
    click DeployScript "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/smart-contract/scripts/deploy.js"
    click TxHelper "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/smart-contract/scripts/getTransactionInput.js"
    click Tests "https://github.com/syarifulmujaddiq/certificate-gen-ver/blob/main/smart-contract/test/Certificate.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:1px
    classDef blockchain fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef external fill:#f8d7da,stroke:#dc3545,stroke-width:1px
```
