Skip to content

About

Web app for Kandypack - rail & road supply chain management

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

191 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KandyPack Logistics Platform

A comprehensive supply chain management system for logistics operations in Sri Lanka, featuring warehouse management, order tracking, route optimization, and fleet scheduling.

πŸš€ Quick Start

Prerequisites

  • Python 3.13+
  • Node.js 18+
  • MySQL 8.0+
  • npm or yarn

Backend Setup

# Copy env template and set your MySQL password + SECRET_KEY
cp Backend/.env.example Backend/.env
# Edit Backend/.env β€” set MYSQL_PASSWORD and SECRET_KEY

cd Backend
pip install -r requirements.txt

# Bootstrap DB (creates tables, sample data; then apply reporting procedures)
printf 'yes\n' | python3 reset_database.py
python3 apply_stored_procedures.py

# Start server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Backend will be running at: http://localhost:8000
API Documentation: http://localhost:8000/docs
Health check: http://localhost:8000/health

Frontend Setup

# Navigate to Frontend directory
cd frontend/UI

# Install dependencies
npm install

# Start development server
npm run dev

Frontend will be running at: http://localhost:5173


πŸ“š Documentation

Main Guides

Document Description Link
Setup Guide Complete database and backend setup with troubleshooting SETUP_GUIDE.md
Connection Guide Frontend-backend integration, API mapping, authentication flow FRONTEND_BACKEND_CONNECTION.md
Backend API Docs Endpoint specifications and API documentation BACKEND_DOCUMENTATION.md
Project Spec Original project requirements and specifications KandyPack.docx.pdf

πŸ—οΈ Architecture

kandypack-logistics-platform/
β”œβ”€β”€ Backend/                     # FastAPI backend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/                # API route handlers
β”‚   β”‚   β”œβ”€β”€ core/               # Core functionality (DB, auth, models)
β”‚   β”‚   └── main.py            # FastAPI application
β”‚   β”œβ”€β”€ schemas/               # SQL table definitions
β”‚   β”œβ”€β”€ migrations/            # Database migrations & procedures
β”‚   β”œβ”€β”€ scripts/               # Setup and utility scripts
β”‚   β”œβ”€β”€ reset_database.py      # DB reset + seed data
β”‚   └── apply_stored_procedures.py
β”‚
β”œβ”€β”€ frontend/                  # React Router v7 frontend
β”‚   └── UI/
β”‚       β”œβ”€β”€ app/
β”‚       β”‚   β”œβ”€β”€ components/    # React components
β”‚       β”‚   β”œβ”€β”€ routes/        # Page routes
β”‚       β”‚   β”œβ”€β”€ services/      # API service layer
β”‚       β”‚   └── hooks/         # Custom React hooks
β”‚       β”œβ”€β”€ .env              # Environment configuration
β”‚       └── package.json
β”‚
└── Documentation/             # Project documentation
    β”œβ”€β”€ SETUP_GUIDE.md
    └── FRONTEND_BACKEND_CONNECTION.md

πŸ” Test Credentials

After running reset_database.py, all seeded users and customers use password password123.

Staff/Admin Users

Username Password Role Access
admin password123 SystemAdmin Full system access
sysadmin password123 SystemAdmin System administration
management1 password123 Management Full system access
store_manager1 password123 StoreManager Assigned warehouse
warehouse_staff1 password123 WarehouseStaff Assigned warehouse

Customer Accounts

Username Password Type
john_perera password123 Customer
ama_silva password123 Customer
kamal_fernando password123 Customer

πŸ› οΈ Technology Stack

Backend

  • Framework: FastAPI
  • Database: MySQL 8.0
  • ORM: SQLAlchemy with PyMySQL
  • Authentication: JWT (JSON Web Tokens)
  • Server: Uvicorn (ASGI)

Frontend

  • Framework: React 19
  • Router: React Router v7
  • Build Tool: Vite
  • UI Library: Radix UI + Tailwind CSS
  • Charts: Recharts
  • Maps: Leaflet + React-Leaflet
  • Language: TypeScript

Database

  • DBMS: MySQL
  • Tables: 18 core tables
  • Stored Procedures: 8 reporting procedures
  • Sample Data: Pre-populated test data

✨ Features

🏒 Warehouse Management

  • Multiple warehouse support
  • Inventory tracking
  • Warehouse staff assignment
  • Role-based warehouse access

πŸ“¦ Order Management

  • Order creation and tracking
  • Status management (Placed, In Progress, Completed, Cancelled, In Warehouse)
  • Warehouse assignment (for Management)
  • Customer order history

🚚 Fleet Management

  • Trucks: Management and scheduling
  • Trains: Railway logistics integration
  • Drivers: Working hour tracking
  • Assistants: Schedule management

πŸ—ΊοΈ Route Optimization

  • Route creation and management
  • Distance calculation
  • City-to-city routing
  • Railway station integration

πŸ“Š Analytics & Reports

  • Quarterly sales reports
  • City-wise sales analysis
  • Route-wise sales tracking
  • Driver/Assistant working hours
  • Truck usage per month
  • Top ordered items
  • Customer order history

πŸ” Security

  • JWT-based authentication
  • Role-based access control (RBAC)
  • Password hashing (bcrypt)
  • Protected API endpoints
  • CORS configuration

🎯 User Roles & Permissions

Role Can View Can Create Can Update Can Delete Special Access
Management All data βœ… All βœ… All βœ… All Assign orders, View reports
SystemAdmin All data βœ… System config βœ… System config βœ… System config System management
StoreManager Warehouse-specific βœ… Limited βœ… Warehouse data ❌ Warehouse operations
WarehouseStaff Warehouse-specific ❌ βœ… Limited ❌ Daily operations
DriverAssistant Own schedules ❌ βœ… Status updates ❌ Route updates
Customer Own orders βœ… Own orders βœ… Own orders ❌ Order tracking

πŸ”§ Configuration

Backend Environment Variables

# Database
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_mysql_password_here
MYSQL_DATABASE=kandypack_db

# JWT
SECRET_KEY=your-secret-key-here
ACCESS_TOKEN_EXPIRE_MINUTES=30

Frontend Environment Variables

# API Configuration
VITE_API_BASE_URL=http://localhost:8000

# App Settings
VITE_APP_NAME="KandyPack Logistics"
VITE_APP_VERSION="1.0.0"

# Feature Flags
VITE_ENABLE_MAP=true
VITE_ENABLE_REPORTS=true

πŸ“‘ API Endpoints

Authentication

  • POST /users/login - Staff/user authentication
  • POST /customers/login - Customer authentication

Orders

  • GET /orders - List all orders
  • GET /orders/{id} - Get order details
  • POST /orders - Create new order
  • PUT /orders/{id} - Update order
  • DELETE /orders/{id} - Delete order
  • POST /orders/{id}/assign-warehouse - Assign to warehouse

Resources

  • Cities: /cities
  • Railway Stations: /railway-stations
  • Stores/Warehouses: /stores
  • Products: /products
  • Routes: /routes
  • Trains: /trains
  • Trucks: /trucks
  • Drivers: /drivers
  • Assistants: /assistants

Reports (Management Only)

  • /reports/sales/quarterly - Quarterly sales
  • /reports/sales/by-city - Sales by city
  • /reports/sales/by-route - Sales by route
  • /reports/work-hours/drivers - Driver working hours
  • /reports/work-hours/assistants - Assistant working hours
  • /reports/truck-usage - Truck utilization

Full API documentation: http://localhost:8000/docs


πŸ§ͺ Testing

Test the Backend

# Test root endpoint
curl http://localhost:8000/

# Test login
curl -X POST http://localhost:8000/users/login `
  -H "Content-Type: application/x-www-form-urlencoded" `
  -d "username=admin&password=password123"

# Test authenticated endpoint
curl http://localhost:8000/orders `
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

Test the Frontend

  1. Open http://localhost:5173
  2. Click "Login"
  3. Enter credentials (e.g., admin/password123 or store_manager1/password123)
  4. Navigate through dashboard
  5. Test creating/viewing orders
  6. Check warehouse assignment (Management role)

πŸ“Š Database Schema

Core Tables (18 total)

User Management:

  • users - System users with roles
  • customers - Customer accounts

Geography:

  • cities - Cities in Sri Lanka
  • railway_stations - Railway station locations

Facilities:

  • stores - Warehouses/distribution centers

Orders:

  • orders - Customer orders
  • order_items - Order line items
  • products - Product catalog

Routing:

  • routes - Defined routes between cities
  • route_orders - Route-order assignments

Rail Transport:

  • trains - Train fleet
  • train_schedules - Train schedules
  • rail_allocations - Order-to-train allocations

Road Transport:

  • trucks - Truck fleet
  • truck_schedules - Truck schedules
  • truck_allocations - Order-to-truck allocations

Personnel:

  • drivers - Driver information
  • assistants - Driver assistants

πŸ”„ Development Workflow

Backend Development

# Make code changes
# Server auto-reloads with --reload flag

# Test in Swagger UI
# Open http://localhost:8000/docs

# Check logs in terminal

Frontend Development

# Make code changes
# Vite auto-reloads on save

# Test in browser
# Check Network tab in DevTools

# View console for errors

Database Changes

# Update SQL files in Backend/schemas/
# Re-run bootstrap
cd Backend
printf 'yes\n' | python3 reset_database.py
python3 apply_stored_procedures.py

πŸ› Troubleshooting

Backend won't start

  • Check MySQL is running
  • Verify MYSQL_PASSWORD (and other MYSQL_* vars) in Backend/.env
  • Check port 8000 is available
  • Confirm SECRET_KEY is set when DEBUG=false

Frontend can't connect to backend

  • Verify backend is running on port 8000
  • Check .env file exists in frontend/UI/
  • Ensure VITE_API_BASE_URL=http://localhost:8000
  • Check browser console for CORS errors

Authentication fails

  • Verify credentials match test accounts
  • Check password is correct (case-sensitive)
  • Ensure database has sample users
  • Check JWT token in localStorage

Database errors

  • Re-run bootstrap: printf 'yes\n' | python3 reset_database.py then python3 apply_stored_procedures.py
  • Check MySQL credentials in Backend/.env
  • Verify database exists: SHOW DATABASES;
  • Check tables exist: USE kandypack_db; SHOW TABLES;

πŸ“– Additional Resources

Documentation

Tools

  • Swagger UI: Interactive API docs at /docs
  • ReDoc: Alternative API docs at /redoc
  • Postman: API testing and collections
  • MySQL Workbench: Database management

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

See LICENSE file for details.


πŸ“ž Support

For issues or questions:

  • Check documentation in /docs
  • Review troubleshooting section
  • Check API docs at http://localhost:8000/docs
  • Review sample credentials

βœ… Status

🟒 FULLY OPERATIONAL

  • βœ… Database setup complete
  • βœ… Backend API running
  • βœ… Frontend connected
  • βœ… Authentication working
  • βœ… CORS configured
  • βœ… Sample data loaded
  • βœ… Stored procedures deployed
  • βœ… Documentation complete

Version: 1.0.0
Last Updated: October 19, 2025
Status: Production Ready βœ…


Built with ❀️ for efficient logistics management

About

Web app for Kandypack - rail & road supply chain management

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages