A system for managing and optimizing packet sizes for shipping.
This project includes a Docker Compose configuration to run both the backend and frontend services together.
- Docker and Docker Compose installed on your system
- Git (to clone the repository)
-
Clone the repository (SSH):
git clone git@github.com:dsha256/packer.git
-
Navigate to the repository root folder:
cd packer -
Start the services using Docker Compose:
docker-compose up -d
Or with Taskfile:
task compose_up
-
Access the application:
- Frontend: http://localhost:3001
- Backend API: http://localhost:3000
To stop the services:
docker-compose down --remove-orphansIf you make changes to the code, you'll need to rebuild the services:
docker-compose up -d --buildThe backend is a Go application that provides API endpoints for packet management.
The frontend is a Next.js application that provides a user interface for interacting with the backend.
The backend configuration is stored in config.yaml. This file is mounted as a volume in the Docker container.
If you encounter port conflicts, make sure no other services are using ports 3000 and 3001.
To check the logs:
docker-compose logs -fTo check the logs for a specific service:
docker-compose logs -f backend
docker-compose logs -f frontendThis project uses Taskfile for task automation. Here are the available commands:
task test- Run all tests with the race flag enabledtask lint- Run the Go linter to check code qualitytask format- Format all Go code using gofumpt and fieldalignmenttask benchmark_packer- Run the packer service benchmarks
task compose_up- Start the Docker Compose servicestask compose_down- Stop and remove Docker Compose servicestask compose_fresh_restart- Stop all services and restart them with a fresh build
The following tasks launch web UIs for different types of profiling (available at http://localhost:9090):
task pprof_allocs_web- Memory allocation profilingtask pprof_heap_web- Heap memory profilingtask pprof_goroutine_web- Goroutine profilingtask pprof_block_web- Blocking profilingtask pprof_threadcreate_web- Thread creation profilingtask pprof_trace_web- Execution tracingtask pprof_profile_web- CPU profilingtask pprof_symbol_web- Symbol lookup
Note: Profiling endpoints are only available when the Go application is running.
| Algorithm | Time Complexity | Space Complexity | Approach |
|---|---|---|---|
CalculateOptimalPacketsForItemsV1 |
O((items + maxPacketSize) * len(packetSizes)) |
O(items + maxPacketSize) |
Dynamic Programming (Backtracking) |
CalculateOptimalPacketsForItemsV2 |
O((items + maxPacketSize) * len(packetSizes) * log(items + maxPacketSize)) |
O(items + maxPacketSize) |
Dijkstra's Algorithm with Min-Heap |
| Factor | V1 (DP) | V2 (Min-Heap / Dijkstra) |
|---|---|---|
| Algorithm Type | Dynamic Programming | Priority Queue + Greedy Traversal (Dijkstra) |
| Main Data Structure | Arrays (dpPacks, prevPacket) |
Heap (MinHeap) + Maps (minNumPacks) |
| Backtracking | Uses prevPacket to reconstruct solution. |
Uses predecessor map to reconstruct solution. |
| Efficiency | Processes all totals up to maxSum. |
Prioritizes smaller totals with fewer packets first. |
- Benchmarks and other implementation details are given in this folder internal/packer
- Actual benchmarks' results can be found in this folder benchmark