# manukj/guardfi architecture

> Architecture diagram of the GitHub repository manukj/guardfi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/manukj/guardfi
- Repository: https://github.com/manukj/guardfi

## Overview

##### Main Components
- Frontend (Next.js): The packages/nextjs directory contains a full Next.js application with a lot of UI elements (e.g., block explorer, debug screens, dashboard, login components, etc.), integration with scaffold-eth, and additional UI components. This is the user-facing application that displays risk metrics, insurance details, and interfaces for contract analysis.
- Smart Contracts & Blockchain Layer (Foundry): The packages/foundry directory is dedicated to Solidity contracts, deployments, scripts, and tests. This includes contracts for various insurance-related functionalities and protocols. It reflects the core on-chain logic and integration with tools like Mythril and Slither.
- AI & Risk Assessment Component (Flock): The packages/flock folder (notably with a “testnet-training-node-quickstart”) suggests an AI-powered component used for risk evaluation of smart contracts based on training data.
- Cross-Chain Verification & External Data (Flare & External Services): The README mentions using Flare’s Data Connector and external blockchain data services along with integrated static analysis tools.
- Infrastructure & CI/CD: The presence of GitHub workflows, Docker Compose configuration (docker-compose.yml), and yarn configuration files indicate an integrated development and deployment pipeline.

##### Relationships and Interaction Flows
- Frontend ⇄ Smart Contract Layer: Show how the Next.js application interacts with deployed contracts (via web3 services in packages/nextjs/services/web3). This communication involves user-triggered transactions and queries.
- Frontend ⇄ AI Risk Assessment: Illustrate how the UI sends contract code or transaction details for risk analysis. This could be an API endpoint (see packages/nextjs/app/api/analyze) that interfaces with the Flock training/test component.
- CI/CD and Infrastructure: Indicate components that handle code quality checks (e.g., GitHub workflows, husky, and lint-staged configurations) and containerized deployments (Docker Compose).

##### Architectural Patterns and Technologies
- Modularized Multi-Package Structure: Emphasize the separation into packages (nextjs, foundry, flock) which reflects clear domain boundaries – UI, smart contract backend, and AI risk assessment.
- Full-Stack Separation: The clear division into frontend (user interface, API endpoints) and backend (smart contracts and data services) should be highlighted.
- Security and Static Analysis: Note that the system integrates static analysis tools (e.g., Mythril, Slither) and risk analysis models as core design elements.
- Integration with External Libraries and Tools: Mention technologies like Tailwind CSS, Node.js, Foundry, and Solidity, as well as integrations with scaffold-eth for blockchain interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Next.js UI"]:::frontend
    end

    %% Logic & Processing Layer
    subgraph "Logic & Processing"
        SC["Foundry Smart Contracts"]:::blockchain
        AI["Flock AI Engine"]:::ai
    end

    %% Integration/Data Layer
    subgraph "Integration Layer"
        FD["Flare Data Connector"]:::external
    end

    %% CI/CD & Infrastructure
    subgraph "CI/CD & Infrastructure"
        CW["GitHub Workflows"]:::infrastructure
        DC["Docker Compose"]:::infrastructure
    end

    %% Connections between components
    UI -->|"API_calls"| SC
    UI -->|"Risk_analysis_requests"| AI
    AI -->|"Risk_metrics"| UI
    AI -->|"Risk_validation"| SC
    SC -->|"Cross-chain_verification"| FD

    %% CI/CD supported interactions (dashed lines)
    CW -.->|"deploys_and_tests"| UI
    CW -.->|"deploys_and_tests"| SC
    DC -.->|"deploys_services"| AI

    %% Click Events
    click UI "https://github.com/manukj/guardfi/tree/dev/packages/nextjs"
    click SC "https://github.com/manukj/guardfi/tree/dev/packages/foundry"
    click AI "https://github.com/manukj/guardfi/tree/dev/packages/flock"
    click FD "https://github.com/manukj/guardfi/tree/dev/packages/foundry/contracts/flare-periphery-contracts"
    click CW "https://github.com/manukj/guardfi/tree/dev/.github/workflows"
    click DC "https://github.com/manukj/guardfi/blob/dev/docker-compose.yml"

    %% Styles
    classDef frontend fill:#ffefd5,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef ai fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef external fill:#ffc0cb,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#fffacd,stroke:#333,stroke-width:2px;
```
