Skip to content

Development

Architecture

The project is structured as follows:

  • api/: Contains the API route definitions.
  • controllers/: Contains the controllers for handling API requests.
  • models/: Contains the data models.
  • operations/: Contains the business logic and database operations.
  • middleware/: Contains middleware functions.
  • lib/: Contains utility functions.
  • db.js: Database connection and schema creation.
  • index.js: Entry point of the application.

Diagram

flowchart TD
    subgraph Initialization
        A[Initialize Environment Variables] --> B[Initialize Neat Client]
        B --> C[Create Device Table if not exists]
    end

    subgraph Neat Data Fetching
        D[Start Neat Process] --> E[Fetch All Devices from Neat]
        E --> F[Fetch Device Details]
        F --> J[Combine Device Data]
    end

    subgraph Data Processing
        J --> K[Add Timestamps/IDs]
        K --> L[Add Severity Info]
        L --> M[Normalize Serial Numbers]
        M --> N[Add Location Data via Geocoder]
        N --> P[Prepare for Database]
    end

    subgraph Database Operations
        P --> Q[Upsert Devices in Batch]
        Q --> R[Delete Obsolete Devices]
        R --> S[Update In-Memory Store]
    end

    style Initialization fill:#f0f4c3,stroke:#827717