> For the complete documentation index, see [llms.txt](https://bittu-1.gitbook.io/meshkit-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bittu-1.gitbook.io/meshkit-documentation/architecture.md).

# Architecture Overview

MeshKit is organized as a small SDK layer over a storage provider interface.

## Overview

```
Application
  -> Meshkit
    -> StorageProvider
      -> PinataProvider
        -> Pinata API
        -> IPFS gateway
```

The `Meshkit` class exposes developer-facing methods. Provider-specific HTTP behavior is isolated behind the `StorageProvider` interface.

## Architecture Diagram

```mermaid
flowchart TD
  App[Application] --> Meshkit[Meshkit]
  Meshkit --> StorageProvider[StorageProvider]
  StorageProvider --> PinataProvider[PinataProvider]
  PinataProvider --> PinataAPI[Pinata API]
  PinataProvider --> Gateway[IPFS Gateway]

  subgraph JSONStore[JSON store flow]
    StoreCall[store data] --> PutJSON[putJSON]
    PutJSON --> PinJSON[POST /pinning/pinJSONToIPFS]
    PinJSON --> StoreCID[CID]
  end

  subgraph JSONRetrieve[JSON retrieve flow]
    RetrieveCall[retrieve cid] --> GetJSON[getJSON]
    GetJSON --> GatewayJSON[GET gateway/cid]
    GatewayJSON --> JSONData[JSON data]
  end

  subgraph FileUpload[File upload flow]
    UploadCall[upload file] --> PutFile[putFile]
    PutFile --> PinFile[POST /pinning/pinFileToIPFS]
    PinFile --> FileCID[CID]
  end

  subgraph FileDownload[File download flow]
    DownloadCall[download cid] --> GetFile[getFile]
    GetFile --> GatewayFile[GET gateway/cid]
    GatewayFile --> BlobData[Blob]
  end

  Meshkit --> StoreCall
  Meshkit --> RetrieveCall
  Meshkit --> UploadCall
  Meshkit --> DownloadCall
  PutJSON --> PinataProvider
  GetJSON --> PinataProvider
  PutFile --> PinataProvider
  GetFile --> PinataProvider
```

## Core Components

| Component          | Responsibility                                                                                                           |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| `Meshkit`          | Public SDK class. Provides `store`, `retrieve`, `upload`, `download`, `send`, `receive`, `revoke`, and `testConnection`. |
| `StorageProvider`  | Interface for JSON, file, delete, and auth operations.                                                                   |
| `PinataProvider`   | Current provider implementation. Calls Pinata pinning APIs and reads from an IPFS gateway.                               |
| `MeshkitRecord<T>` | Standard metadata wrapper returned by write operations.                                                                  |
| `MeshkitMessage`   | Message payload model used by `send()` and `receive()`.                                                                  |

## Provider Flow

### JSON Storage

```
meshkit.store(data)
  -> provider.putJSON(data)
    -> POST /pinning/pinJSONToIPFS
      -> returns IpfsHash
```

### JSON Retrieval

```
meshkit.retrieve(cid)
  -> provider.getJSON(cid)
    -> GET {gatewayUrl}/{cid}
      -> returns JSON
```

### File Upload

```
meshkit.upload(file)
  -> provider.putFile(file)
    -> POST /pinning/pinFileToIPFS
      -> returns IpfsHash
```

### File Download

```
meshkit.download(cid)
  -> provider.getFile(cid)
    -> GET {gatewayUrl}/{cid}
      -> returns Blob
```

## CID Normalization

For retrieval, download, and revoke operations, the Pinata provider accepts either a raw CID or a URL containing `/ipfs/`. Query strings and trailing slashes are removed before the provider calls the gateway or unpin endpoint.

## Current Provider Behavior

Although the `MeshkitConfig.provider` type includes `"pinata"`, `"filebase"`, and `"storacha"`, the current implementation always creates a `PinataProvider`.

Planned, not yet implemented:

* Filebase provider support
* Storacha provider support

## Related APIs

* [API Reference Overview](/meshkit-documentation/api-reference.md)
* [store()](/meshkit-documentation/api/store.md)
* [retrieve()](/meshkit-documentation/api/retrieve.md)
* [upload()](/meshkit-documentation/api/upload.md)
* [download()](/meshkit-documentation/api/download.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bittu-1.gitbook.io/meshkit-documentation/architecture.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
