# Architecture

Heres is a multi-layer application composed of a Next.js frontend, Solana program, automation routes, Chainlink CRE workflows, MagicBlock execution integration, and an Android mobile app.

## Repository Map

| Path              | Purpose                                                             |
| ----------------- | ------------------------------------------------------------------- |
| `app/`            | Next.js app routes, pages, and API handlers.                        |
| `components/`     | Reusable UI components.                                             |
| `config/`         | Solana and RPC configuration.                                       |
| `constants/`      | Network, fee, MagicBlock, and app constants.                        |
| `lib/`            | Solana, CRE, dashboard, mobile, and backend service logic.          |
| `utils/`          | Validation, intent parsing, CRE crypto, and signed message helpers. |
| `heres_program/`  | Anchor smart contract for capsules.                                 |
| `idl/`            | Generated program IDL files.                                        |
| `heres-cre/`      | Chainlink CRE workflows for delivery and reminders.                 |
| `mobile-android/` | Native Android MVP.                                                 |
| `scripts/`        | Setup, test, dashboard, and operational scripts.                    |
| `tests/`          | Node test suite.                                                    |

## Main Components

### Web App

The web app provides:

* Landing page.
* Capsule creation.
* My Capsule redirect.
* Capsule detail page.
* Dashboard.
* API routes for mobile, CRE, Helius, cron, and capsule data.

### Solana Program

The Anchor program manages:

* Fee configuration.
* Capsule creation.
* Intent updates.
* Activity refresh.
* Execution.
* Distribution.
* MagicBlock delegation helpers.

Program ID in the checked-in Rust source:

```
AmiL7vEZ2SpAuDXzdxC3sJMyjZqgacvwvvQdT3qosmsW
```

Production deployments should verify the deployed program ID and IDL before publishing docs.

### MagicBlock ER/PER

MagicBlock integration supports:

* Capsule delegation.
* Private monitoring.
* Scheduled execution.
* Commit and undelegation flow.

### Chainlink CRE

CRE integration supports:

* Intent delivery registration.
* Dispatch after execution.
* HMAC protected callbacks.
* Reminder workflow support.
* Local mock CRE testing.

### Dashboard Indexing

The dashboard can use live RPC reads, Helius APIs, and optional prewarm or index jobs.

## High-Level Flow

```
User Wallet
  -> Next.js create flow
  -> Heres Solana program creates capsule and vault
  -> Optional MagicBlock delegation schedules execution
  -> Inactivity window passes
  -> execute_intent marks state as executed
  -> distribute_assets sends assets to beneficiaries
  -> reconcile-cre-delivery dispatches Chainlink CRE
  -> CRE delivers encrypted statement and sends callback
```


---

# Agent Instructions: 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:

```
GET https://doc.heresprotocol.com/developers/architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
