Neo4j Arrows

repository·main·Indexed 41 days ago

https://github.com/neo4j-labs/arrows.app

A web-based graph drawing tool and VS Code extension for creating visual representations of graphs. It supports the Neo4j Property Graph Model, allowing users to design graphs with nodes, relationships, properties, and labels, and export them as images or Cypher code. The ecosystem includes a visual canvas editor, a .arrows JSON file format, and the @arrows-code/format-json library for reading and writing graph data.

Tokens
27.5K
Snippets
90
Records
163
Agent score
51%

What's inside Arrows

  1. Overview of arrows.app

    main

    arrows.app is a web-based tool designed for drawing pictures of graphs for use in documents or presentations. It follows the Neo4j Property Graph Model, allowing users to draw nodes, relationships, properties, and labels with fine-grained control over styling (sizes, layouts, colors).

    Key Capabilities:

    • Intuitive Drawing: Quick, mouse-based graph creation.
    • Image Export: Export your drawings as images for use in external documents.
    • Cypher Export: Export your graph as Cypher code to recreate the graph in a Neo4j database.

    Important Distinctions:

    • Not a Database Visualizer: This tool is for drawing graphs, not for exploring or visualizing existing data in a database. For database visualization, use Neo4j Bloom or Neo4j Browser.
    • No Automated Layout: Users must manually position nodes; there is no automatic layout engine.
    • Manual Styling: Styling is not semantic. You cannot set styles based on labels (e.g., "all nodes with label X are red"); instead, you must select the nodes and apply styles manually.
  2. Overview of neo4j-arrows-app

    main

    neo4j-arrows-app is a web-based tool designed for drawing pictures of graphs. It is composed of two primary parts:

    1. Dependency-free JS code: Used for rendering graphs to Canvas and SVG.
    2. React-Redux application: A full application for creating and editing graph pictures.

    It is the logical successor to the original apcj/arrows project but is a complete rewrite with no shared code.

  3. Key features of neo4j-arrows-app

    main

    The tool provides the following capabilities:

    • Intuitive Drawing: Quick graph creation using a mouse.
    • Neo4j Property Graph Model Support: Explicit support for nodes, relationships, properties, and labels.
    • Fine-grained Styling: Precise control over sizes, positions, and colors.
    • Image Export: Ability to export graphs as images, primarily for use in documents or presentations.
    • Cypher Export: Ability to export the drawn graph as Cypher queries to recreate the graph in a Neo4j database.
  4. Use @arrows-code/format-json to handle .arrows files

    main

    The @arrows-code/format-json package provides utilities to read, write, and canonicalize the .arrows JSON format. It is designed to ensure structural equality and stability when working with graph data in this specific format.

    import { readGraph, writeGraph, canonicalize } from '@arrows-code/format-json';
    
    // Read a graph from a string
    const { graph, diagnostics } = readGraph(text);
    
    // Write a graph object back to a string
    const text = writeGraph(graph);
    
    // Get a normalized version of the graph
    const normalized = canonicalize(graph);
  5. Key features of Neo4j Arrows for VS Code

    main

    The extension provides several tools for graph modeling within your development environment:

    • Canvas Editor: Visual editing for .arrows files.
    • Two-way Sync: Real-time synchronization between the visual canvas and the underlying JSON file.
    • Exporting: Support for exporting graphs to Cypher or SVG.
    • Validation: A built-in validator that flags broken graphs in the VS Code Problems panel.
    • Refactoring: Project-wide rename functionality for labels and relationship types.
    • Sidebar: Access to workspace .arrows files and bundled examples.
  6. Task organization and path conventions for Google Drive Auth migration

    main

    Tasks within the migration specification follow a specific format and organizational structure:

    • Task Format: [ID] [P?] [Story] Description
    • Task Types: [P] tasks represent different files or tasks that have no dependency on other tasks within the same phase.
    • Traceability: The [Story] label maps a task to a specific User Story.
    • Testing: Each user story is designed to be independently testable per the "Independent Test" specification.
    • File Paths: All paths are relative to the repository root. The primary application is located at apps/arrows-ts/.
  7. Understand the Google Drive Authentication Data Model

    main

    The Google Drive authentication system relies on three primary entities: the Access Token, the Authorized State, and the Drive File association.

    1. Access Token (Credential)

    • access_token: An opaque string obtained via GIS requestAccessToken() following a user gesture. It must be passed as Authorization: Bearer <access_token> to Drive API v3 and to the Picker via setOAuthToken(accessToken).
    • expires_at: An optional Unix timestamp (ms) used for preemptive UI updates. Note that a 401 error from any Drive/Picker call is the authoritative signal that the token is invalid.
    • Lifecycle: Tokens are cleared upon receiving a 401 error, token expiry, or explicit sign-out.

    2. Authorized State

    • signedIn: A boolean indicating if the app holds a valid token and hasn't detected a 401, expiry, or sign-out. This controls UI states (e.g., "Authorize" vs "Signed in") and feature eligibility (open/save/picker/share).
    • apiInitialized: A boolean indicating that the GIS token client and required scripts are ready, enabling the "Authorize" action.

    3. Drive File (Diagram)

    • fileId: The opaque Google Drive file ID.
    • name: The user-visible file name.
    • Relationship: A diagram can be associated with one Drive file. Operations like Open (read), Save (create/overwrite), Rename, and Share use the current access token and specific scopes (drive.file, drive.install).
  8. Use the `.arrows` file format and conventions

    main

    The extension uses a plain JSON format identical to the web-based arrows.app. This allows for two-way synchronization: you can edit the visual canvas or the JSON text, and both will stay in sync.

    When modeling your graphs, follow these naming conventions to ensure compatibility with Neo4j Cypher exports:

    • Labels: PascalCase (e.g., User)
    • Relationship Types: SCREAMING_SNAKE_CASE (e.g., FOLLOWS_USER)
    • Properties: camelCase (e.g., firstName)
  9. Risk Mitigation Strategies for TypeScript Migration

    main

    When performing the incremental migration of the Arrows codebase, follow these best practices to minimize regression:

    • One slice at a time: Convert one reducer, its actions, its selectors, and its connected components as a single unit. This allows you to verify the app and tests after every logical change.
    • Continuous Testing: Run nx run arrows-ts:test and end-to-end (e2e) tests after every phase or Pull Request.
    • Branching Strategy: Use short-lived branches for each phase or feature area to keep the main branch buildable and green.
    • Library Integrity: When extending libraries (Phase 1), ensure new exports are covered by unit tests and pass CI builds.
  10. Update Redux State for Google Drive Authentication

    main

    Modify the Redux reducer (e.g., reducers/googleDrive.js) to manage the new authentication state:

    • State Keys: Add accessToken and optionally expiresAt to the state.
    • Derived State: The signedIn status should be derived from the presence of a valid accessToken.
    • Error Handling: If a 401 Unauthorized error is received from any Google Drive or Picker call, the application must clear the accessToken and set signedIn to false.
  11. Google Drive Implementation Structure in arrows-ts

    main

    The Google Drive integration is located within the apps/arrows-ts/ directory of the Nx monorepo. The following files handle the core logic for the modernized authentication and storage flow:

    • src/actions/googleDrive.js: Handles init, signIn, saveFile, and rename using the GIS token and Drive v3.
    • src/storage/googleDriveStorage.js: Manages fetchGraphFromDrive using the token from the application state.
    • src/reducers/googleDrive.js: Manages signedIn and apiInitialized states based on the token.
    • src/components/GoogleDrivePickerWrapper.js: Wraps the Google Picker and uses setOAuthToken with the GIS token.
    • src/components/GoogleDriveShareWrapper.js: Implements sharing via Drive API v3 permissions and copy-link functionality.
    • src/components/editors/GoogleSignInModal.jsx: Provides the UI to authorize and calls requestAccessToken().
    • src/config.ts: Contains the clientId, apiKey, and appId.