# sandeep-equinix/flightdelay architecture

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

- Interactive diagram: https://gitdiagram.com/sandeep-equinix/flightdelay
- Repository: https://github.com/sandeep-equinix/flightdelay

## Overview

##### Project type and purpose
- This is a decentralized insurance‐style DApp (“FlightDelay”) built on Ethereum.
- Purpose: allow users to buy flight‐delay insurance policies, underwrite them via an external oracle (Oraclize), and automatically payout compensation on delayed arrivals.

##### System’s main components and flows
a. Smart Contract (Solidity)
– Deployed to Ethereum (Morden testnet & Mainnet).
– Manages policy creation, premiums, internal ledger, reentrancy guard, and payouts.
b. Oracle Service (Oraclize)
– Underwriting call: fetch probability of delay from flightstats API.
– Payout call: scheduled at underwriting; queries actual landing time & delay to calculate compensation; may re-schedule via Oraclize if flight not arrived.
c. Frontend DApp (Meteor + React/Blaze)
– Hosted at https://fdi.etherisc.com.
– Connects via MetaMask or Mist.
– Lets users browse flights, buy policies, view status, and receive notifications.
d. Ethereum Blockchain
– Acts as immutable ledger for all contract state and payments.
– Ether transfers in (premiums) and out (payouts).
e. External API (FlightStats)
– Provides flight probability & actual arrival data for Oraclize queries.

##### Relationships and interactions (data flows)
1. User uses front-end → triggers MetaMask transaction→ Ethereum smart contract (new policy)
2. Contract calls Oraclize (underwriting) → Oraclize queries FlightStats → returns delay probability → contract stores premium & schedule.
3. On flight landing schedule: contract schedules second Oraclize call → Oraclize queries FlightStats for actual arrival → callback to contract → contract calculates payout, updates ledger, and issues Ether.
4. Front-end listens to contract events ⇒ displays policy status and payouts.

##### Architectural patterns and design principles
- On-chain/off-chain separation: business logic in smart contract; heavy computations & data retrieval off-chain via Oraclize.
- Event‐driven: contract emits events (PolicyCreated, Underwritten, PayoutReady) that UI subscribes to.
- Security: reentrancy guard, simple contract, internal ledger for auditability.

##### Technologies & frameworks to call out
- Solidity (contract), Oraclize API, Ethereum clients (geth), Meteor.js frontend, MetaMask/Mist, FlightStats REST API.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User Layer"
        UI["Frontend DApp (Meteor.js)"]:::frontend
        BrowserExt["MetaMask/Mist"]:::frontend
    end

    subgraph "On-Chain Layer"
        Node["Ethereum Node/JSON-RPC\n(geth)"]:::onchain
        Contract["Smart Contract (Solidity)\nInternal Ledger\nReentrancy Guard"]:::onchain
    end

    subgraph "Oracle Layer"
        Oraclize["Oraclize Service\n(Underwrite & Payout)"]:::oracle
    end

    subgraph "External API Layer"
        FlightStats["FlightStats REST API"]:::external
    end

    subgraph "Project Resources"
        Docs["Project Documentation & Setup"]:::docs
        License["Licensing Information"]:::docs
    end

    UI -->|"transaction"| BrowserExt
    BrowserExt -->|"JSON-RPC call"| Node
    Node -->|"invoke newPolicy()"| Contract

    Contract -->|"Oraclize query (Underwriting)"| Oraclize
    Oraclize -->|"fetch delay probability"| FlightStats
    FlightStats -->|"response"| Oraclize
    Oraclize -->|"callback to contract"| Contract

    Contract -->|"schedule payout query"| Oraclize
    Oraclize -->|"fetch actual arrival"| FlightStats
    FlightStats -->|"response"| Oraclize
    Oraclize -->|"callback to contract"| Contract

    Contract -->|"events (PolicyCreated, Underwritten, PayoutReady)"| UI

    click Docs "https://github.com/sandeep-equinix/flightdelay/blob/master/README.md"
    click License "https://github.com/sandeep-equinix/flightdelay/tree/master/LICENSE"

    classDef frontend fill:#f9c1e0,stroke:#a1375a,stroke-width:1px
    classDef onchain fill:#c1d4f9,stroke:#375aa1,stroke-width:1px
    classDef oracle fill:#c1f9c1,stroke:#3a7a37,stroke-width:1px
    classDef external fill:#f9e6c1,stroke:#7a5a1f,stroke-width:1px
    classDef docs fill:#eeeeee,stroke:#666666,stroke-width:1px
```
