# olamilekan-oluwayomi/guardrail-dapp architecture

> Architecture diagram of the GitHub repository olamilekan-oluwayomi/guardrail-dapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/olamilekan-oluwayomi/guardrail-dapp
- Repository: https://github.com/olamilekan-oluwayomi/guardrail-dapp

## Overview

#### Purpose and Runtime

This repository is a client-side Next.js dashboard for an `AgentExpenseGuardrail` Vyper smart contract deployed on Arc Testnet. It lets MetaMask users inspect contract state and invoke role-gated owner/agent operations.

Primary application entry points:
- `app/page.tsx` — dashboard logic, wallet/contract interaction, and UI state.
- `app/layout.tsx` — Next.js root layout.
- `app/globals.css` — global visual styling.

#### Application Shell

Next.js App Router provides the page runtime and document shell. Tailwind CSS is used for styling, with likely custom/global styles layered in the app stylesheet.

Paths:
- `app/layout.tsx`
- `app/page.tsx`
- `app/globals.css`
- `tailwind.config.ts`

#### Wallet and Network Boundary

The browser Ethereum provider is accessed through MetaMask. The app connects the active account, requests/switches to Arc Testnet chain ID `5042002`, and reacts to wallet-supplied identity/network state.

The provider type boundary is declared locally rather than supplied by a wallet SDK:
- `types/ethereum.d.ts`
- `app/page.tsx`

External dependency: MetaMask/EIP-1193 provider and an Arc RPC endpoint configured in the page implementation.

#### Contract Integration

The dashboard binds a configured deployed contract address to the ABI and uses RPC/provider calls for reads and signed transactions. The ABI is kept as a repository artifact, while the page is the integration orchestrator.

Paths:
- `AgentExpenseGuardrail_abi.json`
- `app/page.tsx`

The deployed address is intentionally environment/deployment-specific and must be updated in `app/page.tsx`; no contract source or deployment scripts are included.

#### Role-Based Control Surfaces

After connection, the UI determines whether the wallet is the contract owner, configured agent, or another account. This role result controls which transaction actions are exposed:

- Owner: update daily limit, replace agent, toggle paused state.
- Agent: execute `spend(recipient, amount, memo)`.
- Any caller: deposit funds, where exposed by the interface.

The contract is the authorization boundary; UI role checks are presentation and workflow guards, not the source of enforcement.

Paths:
- `app/page.tsx`
- `AgentExpenseGuardrail_abi.json`

#### State Read and Refresh Flow

`app/page.tsx` reads guardrail state from the contract—such as owner/agent configuration, limits, paused status, and balances/spending data—and refreshes it on a five-second interval. Wallet connection or completed transactions should trigger the same reload path so the dashboard converges on chain state.

Flow: MetaMask account/provider → Arc RPC/contract read calls → React page state → role-specific dashboard panels.

#### Transaction Flow and Failure Boundary

User input is converted into contract-call arguments, submitted through MetaMask for signing, then broadcast to Arc Testnet. The UI must handle provider rejection, RPC/chain errors, pending confirmation, and post-transaction refresh.

Flow: form action in `app/page.tsx` → contract ABI encoding from `AgentExpenseGuardrail_abi.json` → MetaMask signature → Arc network transaction → refreshed contract reads.

#### Build and Deployment Context

The project is a Node.js/Next.js application, suitable for standard Next.js hosting. It has no backend service, database, indexer, or API route in the supplied tree; browser-to-chain communication is the core runtime architecture.

Paths:
- `package.json`
- `next.config.js`
- `app/page.tsx`

Main entry points: [`app/page.tsx`](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx) (Guardrail dashboard), [`app/layout.tsx`](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/layout.tsx) (Root layout), [`app/globals.css`](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/globals.css) (Global styles), [`AgentExpenseGuardrail_abi.json`](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/AgentExpenseGuardrail_abi.json) (Guardrail ABI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_next["Next.js client"]
  node_package["Node.js project<br/>build manifest<br/>[package.json]"]
  node_next_config["Next configuration<br/>framework config<br/>[next.config.js]"]
  node_layout["Root layout<br/>App Router shell<br/>[layout.tsx]"]
  node_dashboard["Guardrail dashboard<br/>client page<br/>[page.tsx]"]
  node_styles["Global styles<br/>stylesheet<br/>[globals.css]"]
  node_tailwind["Tailwind styling<br/>CSS configuration<br/>[tailwind.config.ts]"]
  node_role_panels["Role-based panels<br/>dashboard UI<br/>[page.tsx]"]
  node_transaction_actions["Transaction actions<br/>write flow<br/>[page.tsx]"]
end

subgraph group_wallet["Wallet and network"]
  node_ethereum_types["Ethereum provider types<br/>TypeScript declarations<br/>[ethereum.d.ts]"]
  node_metamask{{"MetaMask provider<br/>EIP-1193 wallet"}}
  node_arc{{"Arc Testnet<br/>EVM network"}}
end

subgraph group_contract["Contract integration"]
  node_abi["Guardrail ABI<br/>contract interface"]
  node_guardrail{{"AgentExpenseGuardrail<br/>deployed Vyper contract"}}
  node_state_reads["State reads and refresh<br/>read flow<br/>[page.tsx]"]
end

node_package -->|"builds"| node_dashboard
node_next_config -->|"configures"| node_dashboard
node_layout -->|"hosts"| node_dashboard
node_styles -->|"styles"| node_layout
node_tailwind -->|"configures"| node_styles
node_ethereum_types -->|"types provider"| node_dashboard
node_dashboard -->|"connects and listens"| node_metamask
node_dashboard -->|"triggers reload"| node_state_reads
node_state_reads -->|"encodes reads with"| node_abi
node_state_reads -->|"reads state"| node_guardrail
node_guardrail -->|"deployed on"| node_arc
node_state_reads -->|"updates UI state"| node_role_panels
node_role_panels -->|"exposes allowed actions"| node_transaction_actions
node_transaction_actions -->|"encodes calls with"| node_abi
node_transaction_actions -->|"requests signature"| node_metamask
node_metamask -->|"switches and broadcasts"| node_arc
node_arc -->|"executes transaction"| node_guardrail
node_transaction_actions -->|"refreshes after confirmation"| node_state_reads

click node_package "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/package.json"
click node_next_config "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/next.config.js"
click node_layout "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/layout.tsx"
click node_dashboard "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx"
click node_styles "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/globals.css"
click node_tailwind "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/tailwind.config.ts"
click node_ethereum_types "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/types/ethereum.d.ts"
click node_abi "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/AgentExpenseGuardrail_abi.json"
click node_state_reads "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx"
click node_role_panels "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx"
click node_transaction_actions "https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx"

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_package,node_next_config,node_layout,node_dashboard,node_styles,node_tailwind,node_role_panels,node_transaction_actions toneBlue
class node_ethereum_types,node_metamask,node_arc toneAmber
class node_abi,node_guardrail,node_state_reads toneMint
```

## Components

### Next.js client

- [Node.js project](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/package.json): build manifest · `package.json`
- [Next configuration](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/next.config.js): framework config · `next.config.js`
- [Root layout](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/layout.tsx): App Router shell · `app/layout.tsx`
- [Guardrail dashboard](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx): client page · Orchestrates wallet, contract calls, UI state, and refreshes. · `app/page.tsx`
- [Global styles](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/globals.css): stylesheet · `app/globals.css`
- [Tailwind styling](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/tailwind.config.ts): CSS configuration · `tailwind.config.ts`
- [Role-based panels](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx): dashboard UI · Shows owner, agent, or general actions based on read contract state. · `app/page.tsx`
- [Transaction actions](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx): write flow · Prepares deposits, owner changes, and agent spend calls from form input. · `app/page.tsx`

### Wallet and network

- [Ethereum provider types](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/types/ethereum.d.ts): TypeScript declarations · `types/ethereum.d.ts`
- **MetaMask provider**: EIP-1193 wallet · Supplies account, chain state, signatures, and wallet errors.
- **Arc Testnet**: EVM network · Target chain ID 5042002 and RPC boundary.

### Contract integration

- [Guardrail ABI](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/AgentExpenseGuardrail_abi.json): contract interface · `AgentExpenseGuardrail_abi.json`
- **AgentExpenseGuardrail**: deployed Vyper contract · Authorization boundary for owner, agent, and caller operations.
- [State reads and refresh](https://github.com/olamilekan-oluwayomi/guardrail-dapp/blob/master/app/page.tsx): read flow · Reloads contract state on connection, transaction completion, and every five seconds. · `app/page.tsx`

## Connections

- Node.js project → Guardrail dashboard: builds
- Next configuration → Guardrail dashboard: configures
- Root layout → Guardrail dashboard: hosts
- Global styles → Root layout: styles
- Tailwind styling → Global styles: configures
- Ethereum provider types → Guardrail dashboard: types provider
- Guardrail dashboard → MetaMask provider: connects and listens
- Guardrail dashboard → State reads and refresh: triggers reload
- State reads and refresh → Guardrail ABI: encodes reads with
- State reads and refresh → AgentExpenseGuardrail: reads state
- AgentExpenseGuardrail → Arc Testnet: deployed on
- State reads and refresh → Role-based panels: updates UI state
- Role-based panels → Transaction actions: exposes allowed actions
- Transaction actions → Guardrail ABI: encodes calls with
- Transaction actions → MetaMask provider: requests signature
- MetaMask provider → Arc Testnet: switches and broadcasts
- Arc Testnet → AgentExpenseGuardrail: executes transaction
- Transaction actions → State reads and refresh: refreshes after confirmation
