AGENTS.md
This document provides guidance for any AI agent working with code in this repository. Agents are expected to contribute to the project effectively and safely, based on the information provided below.
Agent Roles and Responsibilities
- Understand and analyze the codebase.
- Implement bug fixes, new features, and propose/execute refactoring.
- Strictly adhere to existing coding conventions, styles, and architectural patterns.
- Maintain and improve test coverage.
- Clearly communicate changes and provide feedback to human developers as needed.
Project Overview
Plough is a Flutter package for creating interactive network graph visualizations with multiple layout algorithms and customizable appearance. The package uses Flutter's standard state management (ValueNotifier, InheritedWidget) and follows clean architecture principles.
Guidelines for Collaboration with Agents
- Clarification: If a task is unclear, please attempt to clarify it through specific questions.
- Plan Sharing: Before embarking on complex tasks, please share an outline of your plan.
- Progress Reporting: Regularly report on your work progress, especially regarding key milestones and challenges.
- Feedback Reception: Be open to feedback provided by human developers and adjust your changes as necessary.
- Autonomy and Confirmation: Small changes that align with existing patterns can be performed autonomously, but for large-scale changes or the introduction of new patterns, please seek prior confirmation.
Development Workflow and Tool Usage
Development Commands
Package Development
# Get dependencies
flutter pub get
# Run code generation for Freezed models
dart run build_runner build --delete-conflicting-outputs
# Analyze code
flutter analyze
# Run tests
flutter test
# Run specific test file
flutter test test/plough_test.dart
Example App Development (in example/ directory)
cd example
# Run on macOS
flutter run -d macos
# Run on iOS Simulator
flutter run -d ios
# Run on web
flutter run -d chrome
# Build for release
flutter build macos
flutter build ios
flutter build web
Git Workflow
- Branch Strategy: Typically, create new feature branches from
mainto isolate changes. - Commit Messages: Commit messages should be concise and clear, describing why the change was made and what was changed. Example:
feat: Add new layout strategy for tree graphs - Review Changes: When proposing changes, request human review through a pull request.
Recommendations for Agent Tool Usage
read_fileandsearch_file_content: Actively use these tools for codebase investigation to accurately understand file contents.replaceandwrite_file: Use these tools carefully for modifying files, maintaining consistency with existing code style. Forreplacespecifically, precision inold_stringandnew_stringis crucial.run_shell_command: This is a powerful tool; especially when executing commands that may affect the file system, clearly understand its purpose and potential impact, and explain it to the user if necessary.
Architecture Overview
Core Components Structure
-
Data Model Layer (
lib/src/graph/)Graph: Central data structure using ValueNotifier for reactive stateGraphNode&GraphLink: Core entities with factory patternGraphEntity: Base interface for nodes and linksGraphId: Type-safe identifiers using Freezed- All implementations use internal classes (suffixed with
Impl) for encapsulation
-
Layout System (
lib/src/layout_strategy/)GraphLayoutStrategy: Base class using Strategy pattern- Concrete strategies: ForceDirected, Tree, Manual, Random, Custom
- Each strategy calculates node positions based on graph structure
- Support for fixed node positions and padding
-
Rendering Layer (
lib/src/graph_view/&lib/src/renderer/)GraphView: Main widget orchestrating the visualizationGraphNodeView&GraphLinkView: Individual entity widgets- Behavior system for customizing appearance and interaction
- Default renderers with support for custom shapes
-
Interaction System (
lib/src/interactive/)GraphGestureManager: Central coordinator for all gestures- Specialized state managers for tap, drag, hover, and tooltips
- Event-driven architecture with type-safe events
- Support for selection, dragging, and custom behaviors
Key Design Patterns
- Reactive State: Uses Flutter standard ValueNotifier and InheritedWidget for efficient reactivity
- Factory Pattern: For creating nodes and links
- Strategy Pattern: For layout algorithms
- Composition: Behavior system allows mixing features
- Immutability: Freezed for data classes
State Management Flow
- Graph data changes → ValueNotifier notifications
- GraphView listens via InheritedWidget → Triggers rebuild
- Layout strategy calculates positions
- Widgets render with animations
- User interactions → Event emission → State updates → UI updates
State Management Implementation Details
The package uses Flutter's standard state management without external dependencies:
- GraphInheritedData: Core InheritedWidget that distributes graph data, build state, and behaviors throughout the widget tree
- ValueNotifier: Used for reactive properties like node positions, selection state, and animation states
- AnimatedBuilder: Efficiently rebuilds only when relevant data changes
- Batch Updates: Layout changes are batched to maintain 60FPS performance during animations
- Separation of Concerns: Layout changes and selection changes use separate listeners to minimize rebuilds
Key files:
lib/src/graph_view/inherited_data.dart: InheritedWidget implementationlib/src/graph/graph_base.dart: Core graph state with ValueNotifierlib/src/graph/node.dart&lib/src/graph/link.dart: Entity-level state management
Code Generation
The project uses Freezed for immutable data classes. Files requiring code generation:
graph_data.dart→graph_data.freezed.dartid.dart→id.freezed.dart,id.g.dartdata.dart(graph_view) →data.freezed.dartgeometry.dart→geometry.freezed.dartlink.dart(renderer/style) →link.freezed.dartnode.dart(renderer/style) →node.freezed.dart
Run code generation after modifying these files:
dart run build_runner build --delete-conflicting-outputs
Testing Approach
Tests are located in test/. The package uses standard Flutter testing:
- Unit tests for data models and layout algorithms
- Widget tests for UI components
- Integration tests for graph interactions
Development Guidelines
-
Linting: Project uses
very_good_analysispackage- Some rules are disabled in
analysis_options.yaml - Run
flutter analyzebefore commits
- Some rules are disabled in
-
API Design:
- Public APIs use factory constructors
- Internal implementations are private
- Extensive use of named parameters for clarity
-
Performance:
- ValueNotifier and InheritedWidget provide efficient updates
- Layout calculations are optimized for 60FPS with batch updates
- Animations use Flutter's animation system
- Designed to handle hundreds to thousands of entities efficiently
-
Extension Points:
- Custom layout strategies via
GraphCustomLayoutStrategy - Custom behaviors via
GraphViewBehavior - Custom shapes and renderers
- Custom layout strategies via
Working with the Example App
The example/ directory contains a full demonstration app showcasing:
- Different layout strategies
- Custom node/link rendering
- Interactive features
- Sample data generation
When testing changes, use the example app to verify functionality across different scenarios.
Architecture Details
A detailed description of the interaction system and other specific architectural components can be found in ARCHITECTURE.md.
For deep implementation specifics, agents should analyze the source code directly, particularly within the lib/src/ subdirectories corresponding to each component.
Ethics and Safety
- Protection of Sensitive Information: Do not hardcode credentials or sensitive data into the code, nor output them to logs.
- System Impact: Avoid making unnecessary changes to system settings or files outside the project directory.
- Prevention of Unintended Behavior: When making changes, ensure thorough testing to confirm there are no unintended side effects on existing functionalities.