# kaymen99/ipfs-storage-dapp architecture

> Architecture diagram of the GitHub repository kaymen99/ipfs-storage-dapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaymen99/ipfs-storage-dapp
- Repository: https://github.com/kaymen99/ipfs-storage-dapp

## Overview

##### Main Components
- Blockchain/Smart Contract Layer:
- The “contracts” directory shows that the core functionality is encapsulated in a smart contract (FileStorage) that handles file information, fee-setting, file-upload, and price feed integration.
- There is also inclusion of Chainlink dependencies for real-time price conversion (from USD to MATIC).
- Deployment & Scripting Layer:
- The “scripts” directory contains Python scripts (deploy.py, reset.py, update_front_end.py, etc.) which manage the deployment and updates to the front-end artifacts.
- The “build” folder holds deployment artifacts and contract JSONs (used for connecting the front end to the deployed contracts).
- Front-End Application:
- The “front-end” directory contains a React.js application that manages user interactions (uploading files, connecting to MetaMask, etc.).
- It uses several components (Account, FileStorage, Main, etc.), along with Redux for state management, and utilities for IPFS connectivity (via the web3.storage API).
- External Services:
- IPFS service is used to store files (the code explicitly mentions use of web3.storage for interfacing with IPFS).
- External blockchain networks (Ethereum/Polygon based on brownie network configuration and deployment instructions) plus testing networks like Ganache.

##### Relationships and Interactions
- The front end interacts with the blockchain:
- Users use React components to connect using MetaMask and sign transactions via ethers.js.
- The connection to smart contracts is enabled by the deployed contract addresses and ABIs (transferred from Brownie via “update_front_end.py” and stored in the “artifacts”).
- The smart contract (FileStorage) acts as the backend service:
- It enforces fee uploads and links with Chainlink for price feeds.
- Handles storage metadata (but not the actual file data).
- File uploads are actually stored on IPFS:
- The front end (through a utility file, StoreContent.js) interacts with IPFS using the web3.storage API.
- The deployment scripts (in the “scripts” directory) serve as a bridge:
- They deploy the contracts on local or test networks (Ganache, Polygon Mumbai etc.) and then update the front end artifacts with the correct addresses.

##### Architectural Patterns and Design Principles
- Separation of concerns between the blockchain backend and the React-based front-end.
- Use of a microservice-like approach: a smart contract “service” for file metadata and fee enforcement, and an external IPFS service for actual file storage.
- The project leverages a clear separation in the code organization by isolating contracts, tests, front end, and deployment scripts.
- Reliance on configuration files (like brownie-config.yaml, .env) to manage environment-specific variables (API keys, private keys, network URLs).

##### Final Checklist for the Principal Software Engineer
- Each component should have a clear, descriptive label (e.g., “FileStorage Smart Contract”, “React Front End”, “Brownie Deployment Scripts”, “IPFS via web3.storage”).
- Front-end → Blockchain (transaction calls)
- Front-end → IPFS (file uploads)
- Deployment scripts → Blockchain (contract deployments)
- Annotations where necessary to note key functionalities (e.g., “Chainlink Price Feed integration”, “Redux state management”, “API key integration for IPFS”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Blockchain Network
    subgraph "Blockchain Network"
        FS["FileStorage Smart Contract"]:::blockchain
        CL["Chainlink Price Feed Integration"]:::blockchain
    end

    %% Deployment & Scripting
    subgraph "Deployment & Scripting"
        DS["Deployment Scripts"]:::deployment
        DA["Deployment Artifacts"]:::deployment
    end

    %% Front-End Application
    subgraph "Front-End Application"
        FE["React Front End"]:::frontend
        IP["IPFS Storage Utility"]:::frontend
    end

    %% External Service for IPFS
    ES["IPFS Storage Service"]:::external

    %% Connections
    FE -->|"callsContract"| FS
    FE -->|"readsArtifacts"| DA
    DS -->|"deploysContract"| FS
    DS -->|"updatesArtifacts"| DA
    FE -->|"uploadsFiles"| ES
    FE -->|"utilizes"| IP
    CL -->|"integratedWith"| FS

    %% Class Definitions for Colors
    classDef blockchain fill:#f9f,stroke:#333,stroke-width:2px;
    classDef deployment fill:#fea,stroke:#333,stroke-width:2px;
    classDef frontend fill:#9df,stroke:#333,stroke-width:2px;
    classDef external fill:#ccf,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click FS "https://github.com/kaymen99/ipfs-storage-dapp/tree/main/contracts"
    click CL "https://github.com/kaymen99/ipfs-storage-dapp/blob/main/front-end/src/artifacts/contracts/dependencies/smartcontractkit/chainlink-brownie-contracts@0.2.1"
    click DS "https://github.com/kaymen99/ipfs-storage-dapp/tree/main/scripts"
    click DA "https://github.com/kaymen99/ipfs-storage-dapp/tree/main/build"
    click FE "https://github.com/kaymen99/ipfs-storage-dapp/tree/main/front-end"
    click IP "https://github.com/kaymen99/ipfs-storage-dapp/blob/main/front-end/src/utils/StoreContent.js"
```
