Skip to content

TheJisus28/dijkstra-pathfinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dijkstra Pathfinder Web Application

A modern web application that implements Dijkstra's shortest path algorithm with an interactive graph visualization interface.

πŸš€ Features

  • Interactive Graph Builder: Create custom graphs by adding nodes and edges dynamically
  • Real-time Visualization: Dynamic graph rendering with vis.js and custom styling
  • Shortest Path Calculation: Efficient Dijkstra algorithm implementation in Go
  • Modern UI: Beautiful, responsive interface built with Tailwind CSS
  • Smart Notifications: Toast notifications for user feedback and error handling
  • RESTful API: Clean HTTP API for graph operations
  • Professional Architecture: Well-structured Go backend with proper separation of concerns
  • CORS Support: Cross-origin requests enabled for frontend integration
  • Request Logging: Comprehensive logging middleware for monitoring

πŸ—οΈ Architecture

Backend (Go)

cmd/
  └── server/
      └── main.go           # Application entry point
pkg/
  β”œβ”€β”€ models/
  β”‚   β”œβ”€β”€ graph.go          # Graph data structures
  β”‚   β”œβ”€β”€ request.go        # Request/Response models
  β”‚   └── graph_test.go     # Graph tests
  β”œβ”€β”€ services/
  β”‚   β”œβ”€β”€ dijkstra.go       # Dijkstra algorithm implementation
  β”‚   └── dijkstra_test.go  # Algorithm tests
  β”œβ”€β”€ handlers/
  β”‚   └── graph.go          # HTTP request handlers
  └── middleware/
      β”œβ”€β”€ cors.go           # CORS middleware
      └── logging.go        # Request logging middleware

Frontend (JavaScript + Tailwind CSS)

statics/
  β”œβ”€β”€ index.html           # Main web interface with Tailwind CSS
  └── app.js              # Frontend logic and API integration

πŸ’» Technologies Used

Backend

  • Go 1.21+: Main programming language
  • Standard Library: HTTP server, JSON handling, logging
  • Container/Heap: Priority queue for Dijkstra's algorithm

Frontend

  • Tailwind CSS: Modern utility-first CSS framework
  • Vanilla JavaScript: Clean, dependency-free frontend logic
  • Font Awesome: Icon library for UI elements
  • vis.js: Network visualization library

Architecture Patterns

  • Clean Architecture: Separation of concerns with pkg structure
  • RESTful API: Standard HTTP methods and status codes
  • Middleware Pattern: CORS and logging middleware
  • MVC Pattern: Models, handlers (controllers), and services

πŸ› οΈ Installation & Setup

Prerequisites

  • Go 1.19 or higher
  • Modern web browser

Running the Application

  1. Clone the repository

    git clone https://github.com/TheJisus28/dijkstra-pathfinder.git
    cd dijkstra-pathfinder
  2. Choose your preferred method:

    Option A: Native Go (Recommended for development)

    go run cmd/server/main.go

    Or use the Makefile:

    make run

    Option B: Docker (Cross-platform, production-ready)

    # Build and run with Docker
    make docker-run

    Option C: Docker commands directly

    # Build image
    docker build -t dijkstra-pathfinder .
    
    # Run container
    docker run -p 8080:8080 dijkstra-pathfinder
  3. Access the application

πŸ§ͺ Testing

Run the comprehensive test suite to verify algorithm correctness:

make test             # Run all tests

πŸ’‘ Available Commands

For a complete list of available development commands:

make help             # Show all available Makefile commands

πŸ“– Usage

Web Interface

  1. Add Nodes: Enter node names and click "Add Node" - nodes appear as removable tags
  2. Create Connections: Select source and destination nodes, specify distance
  3. Find Path: Choose start and end nodes, click "Find Path"
  4. Visualize: View the interactive graph with highlighted shortest path in real-time
  5. Manage Graph: Remove nodes and connections with intuitive UI controls

API Usage

Endpoint: POST /solve

Request Body:

{
  "start": "NodeA",
  "end": "NodeC",
  "nodes": ["NodeA", "NodeB", "NodeC"],
  "edges": [
    {
      "from": "NodeA",
      "to": "NodeB",
      "distance": 5
    },
    {
      "from": "NodeB",
      "to": "NodeC",
      "distance": 8
    },
    {
      "from": "NodeA",
      "to": "NodeC",
      "distance": 20
    }
  ]
}

Response:

{
  "path": ["NodeA", "NodeB", "NodeC"],
  "distance": 13,
  "success": true,
  "message": "Shortest path found with distance 13"
}

πŸ”§ Configuration

Environment Variables

  • PORT: Server port (default: 8080)

Custom Configuration

You can modify the following constants in cmd/server/main.go:

  • defaultPort: Default server port
  • staticDir: Static files directory

🐳 Docker Deployment

The application is fully containerized and can run on any system with Docker installed.

Docker Features

  • Multi-stage build: Optimized image size (~10MB)
  • Security: Runs as non-root user
  • Health checks: Built-in container health monitoring
  • Cross-platform: Works on Linux, Windows, macOS

Available Docker Commands

# Development
make docker-build          # Build Docker image
make docker-run            # Build and run container
make docker-clean          # Clean Docker resources

# Production
docker build -t dijkstra-pathfinder .
docker run -d -p 8080:8080 --name dijkstra dijkstra-pathfinder

Environment Variables

  • PORT: Server port (default: 8080)

πŸ§ͺ API Endpoints

Method Endpoint Description
GET / Serve web interface
POST /solve Find shortest path
GET /health Health check

πŸƒβ€β™‚οΈ Performance

  • Algorithm Complexity: O((V + E) log V) where V = vertices, E = edges
  • Memory Usage: O(V + E) for graph storage
  • Concurrent Requests: Supported via Go's goroutines

πŸ›‘οΈ Error Handling

The API provides comprehensive error responses:

  • 400 Bad Request: Invalid input data
  • 405 Method Not Allowed: Unsupported HTTP method
  • 500 Internal Server Error: Server-side errors

πŸ“ˆ Future Enhancements

  • Persistent graph storage
  • Graph templates and presets
  • Export/Import functionality
  • Performance metrics dashboard

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

JesΓΊs Carrascal (@TheJisus28)

Built with ❀️ for academic and professional presentations.

🌟 Project Highlights

  • Clean Architecture: Professional Go backend structure with proper separation of concerns
  • Modern Frontend: Built with Tailwind CSS for a beautiful, responsive interface
  • Custom UI Components: Styled dropdowns, notifications, and interactive elements
  • Real-time Visualization: Interactive graph rendering with vis.js and path highlighting
  • User Experience: Toast notifications, hover effects, and intuitive controls
  • Production Ready: Includes logging, CORS support, error handling, and health checks
  • Zero Dependencies: Frontend uses only CDN resources (Tailwind CSS, Font Awesome, vis.js)
  • Educational Value: Perfect for demonstrating graph algorithms and web development skills

About

πŸš€ Modern web application implementing Dijkstra's shortest path algorithm with interactive graph visualization. Built with Go backend and Tailwind CSS frontend.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors