# travelbank/duffel-api-javascript architecture

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

- Interactive diagram: https://gitdiagram.com/travelbank/duffel-api-javascript
- Repository: https://github.com/travelbank/duffel-api-javascript

## Overview

##### Main Components

a. Core Client Layer:
- It to the `Resource.ts` base class which handles common functionality

b. Feature Modules (Group these in logical sections):
##### Booking Module
- OfferRequests
- Offers
- Orders
- OrderChanges
- OrderCancellations
- SeatMaps
- Payments

##### Duffel Payments Module
- PaymentIntents
- Refunds

##### Places Module
- Suggestions

##### Supporting Resources Module
- Aircraft
- Airlines
- Airports

##### Interaction Flows

- External application → Client
- Client → Resource base class
- Resource base class → Feature modules
- Feature modules → Duffel API endpoints

##### Important Elements to Highlight

a. Type System:
- Types directory (`src/types`) as a shared resource

b. Testing Infrastructure:
- A testing layer showing mock data files
- Mock files to their respective modules

##### Architectural Patterns to Emphasize

- Resource-based architecture
- Type-safe implementations (TypeScript)
- Modular design with clear separation of concerns
- RESTful API client patterns

**┌─────────────────────────────────────────────┐**
- External Applications          │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Client (Entry Point)          │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Resource Base Class            │
- ┘
- ↓
**┌──────────┐    ┌──────────┐    ┌──────────┐**
- Booking  │    │ Payments │    │ Supporting│
- Module   │    │ Module   │    │ Resources │
- ┘    └──────────┘    └──────────┘
- ↓
**┌─────────────────────────────────────────────┐**
- Duffel API                  │
- ┘

Additional Considerations:

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Layer
    subgraph External
        APP[External Applications]
    end

    %% Core Layer
    subgraph Core
        CLIENT["Client"]:::core
        RESOURCE["Resource Base Class"]:::core
    end

    %% Booking Module
    subgraph BookingModule["Booking Module"]
        OFFERS["Offers"]:::booking
        OFFERREQ["Offer Requests"]:::booking
        ORDERS["Orders"]:::booking
        ORDERCHANGES["Order Changes"]:::booking
        ORDERCANCEL["Order Cancellations"]:::booking
        SEATMAPS["Seat Maps"]:::booking
        BOOKINGPAY["Payments"]:::booking
    end

    %% Duffel Payments Module
    subgraph PaymentsModule["Duffel Payments Module"]
        PAYINTENTS["Payment Intents"]:::payment
        REFUNDS["Refunds"]:::payment
    end

    %% Places Module
    subgraph PlacesModule["Places Module"]
        SUGGESTIONS["Suggestions"]:::places
    end

    %% Supporting Resources Module
    subgraph SupportingModule["Supporting Resources"]
        AIRCRAFT["Aircraft"]:::support
        AIRLINES["Airlines"]:::support
        AIRPORTS["Airports"]:::support
    end

    %% Types System
    subgraph TypeSystem["Type System"]
        CLIENTTYPES["Client Types"]:::types
        SHAREDTYPES["Shared Types"]:::types
    end

    %% External API
    subgraph DuffelAPI["Duffel API"]
        API["API Endpoints"]:::api
    end

    %% Connections
    APP --> CLIENT
    CLIENT --> RESOURCE
    RESOURCE --> BookingModule
    RESOURCE --> PaymentsModule
    RESOURCE --> PlacesModule
    RESOURCE --> SupportingModule
    BookingModule --> API
    PaymentsModule --> API
    PlacesModule --> API
    SupportingModule --> API
    TypeSystem -.-> Core
    TypeSystem -.-> BookingModule
    TypeSystem -.-> PaymentsModule
    TypeSystem -.-> PlacesModule
    TypeSystem -.-> SupportingModule

    %% Click Events
    click CLIENT "https://github.com/travelbank/duffel-api-javascript/blob/main/src/Client.ts"
    click RESOURCE "https://github.com/travelbank/duffel-api-javascript/blob/main/src/Resource.ts"
    click OFFERS "https://github.com/travelbank/duffel-api-javascript/blob/main/src/booking/Offers/Offers.ts"
    click OFFERREQ "https://github.com/travelbank/duffel-api-javascript/blob/main/src/booking/OfferRequests/OfferRequests.ts"
    click ORDERS "https://github.com/travelbank/duffel-api-javascript/blob/main/src/booking/Orders/Orders.ts"
    click ORDERCHANGES "https://github.com/travelbank/duffel-api-javascript/blob/main/src/booking/OrderChanges/OrderChanges.ts"
    click ORDERCANCEL "https://github.com/travelbank/duffel-api-javascript/blob/main/src/booking/OrderCancellations/OrderCancellations.ts"
    click SEATMAPS "https://github.com/travelbank/duffel-api-javascript/blob/main/src/booking/SeatMaps/SeatMaps.ts"
    click BOOKINGPAY "https://github.com/travelbank/duffel-api-javascript/blob/main/src/booking/Payments/Payments.ts"
    click PAYINTENTS "https://github.com/travelbank/duffel-api-javascript/blob/main/src/DuffelPayments/PaymentIntents/PaymentIntents.ts"
    click REFUNDS "https://github.com/travelbank/duffel-api-javascript/blob/main/src/DuffelPayments/Refunds/Refunds.ts"
    click SUGGESTIONS "https://github.com/travelbank/duffel-api-javascript/blob/main/src/Places/Suggestions/Suggestions.ts"
    click AIRCRAFT "https://github.com/travelbank/duffel-api-javascript/blob/main/src/supportingResources/Aircraft/Aircraft.ts"
    click AIRLINES "https://github.com/travelbank/duffel-api-javascript/blob/main/src/supportingResources/Airlines/Airlines.ts"
    click AIRPORTS "https://github.com/travelbank/duffel-api-javascript/blob/main/src/supportingResources/Airports/Airports.ts"
    click CLIENTTYPES "https://github.com/travelbank/duffel-api-javascript/blob/main/src/types/ClientType.ts"
    click SHAREDTYPES "https://github.com/travelbank/duffel-api-javascript/blob/main/src/types/shared.ts"

    %% Styling
    classDef core fill:#2374ab
    classDef booking fill:#57a773
    classDef payment fill:#ff8c42
    classDef places fill:#937b63
    classDef support fill:#708090
    classDef types fill:#484848
    classDef api fill:#c70d3a

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Booking Components"]:::booking
        L3["Payment Components"]:::payment
        L4["Places Components"]:::places
        L5["Supporting Resources"]:::support
        L6["Type Definitions"]:::types
        L7["API Layer"]:::api
    end
```
