# fiware/tutorials.ngsi-ld architecture

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

- Interactive diagram: https://gitdiagram.com/fiware/tutorials.ngsi-ld
- Repository: https://github.com/fiware/tutorials.ngsi-ld

## Overview

##### Main Components

a) Core Components:
- NGSI-LD Context Broker (central component)
- IoT Agents Layer (handling JSON and Ultralight protocols)
- Identity Management System
- Historical Data Storage (QuantumLeap)
- Big Data Processing Systems (Flink and Spark)

b) Application Components:
- Frontend Web Application (views in Pug)
- Backend Express.js Application
- API Controllers Layer
- Data Models Layer
- Security Layer

##### Application Layer
- Controllers (app/controllers/)
- Routes (app/routes/)
- Models (app/models/)

##### Integration Layer
- IoT Controllers (app/controllers/iot/)
- Proxy Controllers (app/controllers/proxy/)
- NGSI-LD Controllers (app/controllers/ngsi-ld/)

##### Data Layer
- MongoDB (for buildings)
- Context Broker Storage
- Time Series Database

Use the following visual elements:

- Rectangles: Main services
- Hexagons: IoT components
- Rounded rectangles: APIs and interfaces

- Blue: Core FIWARE components
- Green: IoT-related components
- Yellow: Data storage
- Orange: Security components
- Grey: External services/APIs

c) Connection Types:

##### Data Flow Paths
- IoT Devices → IoT Agents → Context Broker
- Context Broker → Historical Storage
- Applications → Security Layer → Context Broker
- Context Broker → Big Data Processing

##### Integration Points
- External API connections (OpenWeatherMap, Twitter)
- IoT protocol translations (JSON, Ultralight, XML)
- Security middleware interactions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Presentation Layer"
        WV["Web Views"]:::frontend
        PA["Public Assets"]:::frontend
    end

    subgraph "Application Layer"
        BE["Backend Express"]:::backend
        RT["Routes"]:::backend
        CT["Controllers"]:::backend
        MD["Models"]:::backend
    end

    subgraph "Integration Layer"
        NGSI["NGSI-LD Context Broker"]:::core
        IOT["IoT Agents"]:::iot
        SEC["Security Layer"]:::security
        PROX["Proxy Controllers"]:::integration
    end

    subgraph "Data Layer"
        MONGO[("MongoDB")]:::database
        CB[("Context Broker DB")]:::database
        TS[("Time Series DB")]:::database
    end

    subgraph "Processing Layer"
        QL["QuantumLeap"]:::processing
        FLINK["Flink"]:::processing
        SPARK["Spark"]:::processing
    end

    subgraph "External Systems"
        EXT_API["External APIs"]:::external
        IOT_DEV["IoT Devices"]:::iot
    end

    %% Connections
    WV --> BE
    PA --> BE
    BE --> RT
    RT --> CT
    CT --> MD
    MD --> MONGO
    IOT_DEV -.-> IOT
    IOT --> NGSI
    NGSI --> CB
    NGSI --> QL
    QL --> TS
    TS --> FLINK
    TS --> SPARK
    PROX --> EXT_API
    SEC -.-> NGSI

    %% Styles
    classDef frontend fill:#f9f,stroke:#333
    classDef backend fill:#9cf,stroke:#333
    classDef core fill:#0073e6,stroke:#333,color:#fff
    classDef iot fill:#90EE90,stroke:#333
    classDef security fill:#FFA500,stroke:#333
    classDef integration fill:#DEB887,stroke:#333
    classDef database fill:#f9f9f9,stroke:#333
    classDef processing fill:#98FB98,stroke:#333
    classDef external fill:#D3D3D3,stroke:#333

    %% Click Events
    click WV "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/views/"
    click PA "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/public/"
    click BE "https://github.com/FIWARE/tutorials.NGSI-LD/blob/master/app/app.js"
    click RT "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/routes/"
    click CT "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/controllers/"
    click MD "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/models/"
    click NGSI "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/controllers/ngsi-ld/"
    click IOT "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/controllers/iot/"
    click SEC "https://github.com/FIWARE/tutorials.NGSI-LD/blob/master/app/controllers/security.js"
    click PROX "https://github.com/FIWARE/tutorials.NGSI-LD/tree/master/app/controllers/proxy/"
    click MONGO "https://github.com/FIWARE/tutorials.NGSI-LD/blob/master/app/lib/mongoDB-building.js"

    %% Legend
    subgraph Legend
        L1["Frontend Component"]:::frontend
        L2["Backend Component"]:::backend
        L3["Core FIWARE"]:::core
        L4["IoT Component"]:::iot
        L5["Security"]:::security
        L6["Integration"]:::integration
        L7[("Database")]:::database
        L8["Processing"]:::processing
        L9["External System"]:::external
    end
```
