This is the frontend application for the interactive Knowledge Graph visualization, built with React, TypeScript, and D3.js. It provides a Neo4j-style graph interface with physics-based node interactions, real-time editing, and seamless data persistence.
- Framework: React 18 with TypeScript
- Visualization: D3.js with Force Simulation
- Styling: Tailwind CSS
- Build Tool: Vite
- HTTP Client: Axios
- State Management: React Hooks (useState, useEffect, useCallback)
frontend/
โโโ src/
โ โโโ components/ # React components
โ โ โโโ GraphCanvas.tsx # Main D3 visualization
โ โ โโโ GraphView.tsx # Main container component
โ โ โโโ Toolbar.tsx # Search and controls
โ โ โโโ PropertiesPanel.tsx # Node/edge editing
โ โ โโโ ConfirmModal.tsx # Delete confirmations
โ โ โโโ ErrorBoundary.tsx # Error handling
โ โโโ api/ # API communication
โ โ โโโ apiClient.ts
โ โโโ types/ # TypeScript definitions
โ โ โโโ graph.d.ts
โ โ โโโ constants.ts
โ โโโ styles/ # CSS styles
โ โ โโโ index.css
โ โโโ App.tsx # Root component
โ โโโ main.tsx # Entry point
โโโ public/
โโโ package.json
โโโ vite.config.ts
โโโ tailwind.config.js
โโโ tsconfig.json
- Node.js (v18 or higher)
- npm or yarn
- Running backend API server (see backend repository)
-
Clone this repository:
git clone https://github.com/devsaad05858/Knowledge-Graph-Frontend.git
-
Install dependencies:
npm install
-
Environment Setup:
Create a
.env
file in the root directory:touch .env
Add the following configuration:
# API Configuration VITE_API_BASE_URL=http://localhost:5000/api # For production deployment (Heroku backend) # VITE_API_BASE_URL=https://knowledge-graph-backend-app-0dd39e8bfcd4.herokuapp.com/api
-
Make sure the backend is running:
The frontend requires the backend API to be running. See the backend repository for setup instructions.
-
Start the development server:
npm run dev
The application will be available at http://localhost:5173
# Build for production
npm run build
# Preview production build
npm run preview
- Physics Simulation: D3 force-directed layout with customizable physics
- Drag & Drop: Smooth node dragging with real-time position updates
- Zoom & Pan: Mouse wheel zoom and click-drag panning
- Auto-centering: Automatic centering on new nodes and search results
- Create: Click empty space to create new nodes
- Edit: Click nodes to edit properties in side panel
- Delete: Delete nodes with automatic edge cleanup
- Types: Multiple node types with color coding
- Create: Right-click and drag between nodes to create connections
- Edit: Click edges to modify labels and properties
- Delete: Remove connections via context menu or properties panel
- Directional: Support for both directed and undirected edges
- Real-time Search: Instant search with auto-highlighting
- Auto-centering: Search results automatically center in view
- Fit to Screen: One-click view optimization
- Visual Feedback: Highlighted search matches
- Auto-save: Position changes saved automatically with debouncing
- Real-time Updates: Immediate reflection of all changes
- Error Handling: Graceful error recovery and user feedback
- Background: Dark theme with gray-900 base
- Nodes: Color-coded by type (frontend, backend, database, etc.)
- Edges: Gray with directional arrows
- UI: Glass-morphism with backdrop blur effects
frontend-framework
: Blue (#3B82F6)backend-framework
: Green (#10B981)programming-language
: Purple (#8B5CF6)database
: Orange (#F59E0B)runtime
: Red (#EF4444)visualization-library
: Pink (#EC4899)component
: Cyan (#06B6D4)architecture
: Indigo (#6366F1)concept
: Yellow (#EAB308)css-framework
: Emerald (#059669)build-tool
: Teal (#0D9488)cloud-database
: Amber (#D97706)orm
: Rose (#F43F5E)graph-database
: Violet (#7C3AED)default
: Gray (#6B7280)
The D3 force simulation uses optimized parameters for smooth, stable interactions:
const PHYSICS_CONFIG = {
CHARGE_STRENGTH: -300, // Node repulsion
LINK_DISTANCE: 80, // Edge length
COLLISION_RADIUS: 20, // Node collision
ALPHA_DECAY: 0.02, # Simulation cooling
VELOCITY_DECAY: 0.3 // Drag coefficient
}
- Click empty space: Create new node
- Click node: Select and edit properties
- Click edge: Select and edit relationship
- Drag node: Move with physics simulation
- Right-click node: Show connection menu
- Mouse wheel: Zoom in/out
- Click + drag background: Pan view
- Escape: Close properties panel
- Delete: Delete selected item (when panel open)
# Development server with hot reload
npm run dev
# Type checking
npm run build
# Production preview
npm run preview
# Linting
npm run lint
- Performance: Highly optimized force simulation
- Flexibility: Complete control over physics parameters
- Compatibility: Works seamlessly with React
- Ecosystem: Rich ecosystem of extensions and examples
- Neo4j Similarity: Similar physics behavior to Neo4j Browser
- GraphView: Main container managing state and API calls
- GraphCanvas: Pure D3 visualization with React integration
- Toolbar: Search and navigation controls
- PropertiesPanel: Sliding panel for editing
- ErrorBoundary: Graceful error handling
- Local State: React hooks for UI state
- API State: Direct API calls with error handling
- Physics State: D3 simulation manages node positions
- Debouncing: Position updates debounced to reduce API calls
- useCallback: Memoized event handlers
- Efficient Updates: Minimal re-renders with proper dependencies
- SVG Optimization: Efficient D3 selections and updates
- Debounced Updates: Position changes batched
- Request Caching: Axios interceptors for logging
- Error Recovery: Automatic retry logic
- Optimized Parameters: Balanced performance vs. visual quality
- Conditional Rendering: Simulation only runs when needed
- Memory Management: Proper cleanup of D3 resources
- Check backend API is running on correct port
- Verify
VITE_API_BASE_URL
in.env
- Check browser console for network errors
- Nodes flying apart: Reduce
CHARGE_STRENGTH
- Slow performance: Increase
ALPHA_DECAY
- Unstable movement: Adjust
VELOCITY_DECAY
- Ensure backend
/api/search
endpoint is accessible - Check for JavaScript errors in console
- Verify search query formatting
The application is optimized for desktop use but includes responsive considerations:
- Minimum Width: 1024px recommended
- Touch Support: Basic touch events for tablets
- Mobile: Limited functionality on mobile devices
- Input Sanitization: All user inputs validated
- XSS Prevention: Proper React rendering practices
- API Security: HTTPS in production, CORS configuration
- Error Handling: No sensitive data exposed in errors
npm run build
# Creates dist/ folder with optimized static files
VITE_API_BASE_URL=https://knowledge-graph-backend-app-0dd39e8bfcd4.herokuapp.com/api
- Frontend (Vercel): https://frontend-cuevpw3mf-saadaslam010s-projects.vercel.app
- Backend (Heroku): https://knowledge-graph-backend-app-0dd39e8bfcd4.herokuapp.com
- Vercel, Netlify, GitHub Pages
- AWS S3 + CloudFront
- Docker containerization supported
This frontend connects to a Node.js/Express backend deployed on Heroku: Backend URL: https://knowledge-graph-backend-app-0dd39e8bfcd4.herokuapp.com
The backend API provides the following endpoints:
GET /api/graph
- Complete graph dataPOST /api/nodes
- Create nodesPUT /api/nodes/:id
- Update nodesDELETE /api/nodes/:id
- Delete nodesPOST /api/edges
- Create edgesPUT /api/edges/:id
- Update edgesDELETE /api/edges/:id
- Delete edgesGET /api/search?q=term
- Search nodes
The production deployment is configured to use the Heroku backend automatically.