A comprehensive supply chain management system for logistics operations in Sri Lanka, featuring warehouse management, order tracking, route optimization, and fleet scheduling.
- Python 3.13+
- Node.js 18+
- MySQL 8.0+
- npm or yarn
# 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 8000Backend will be running at: http://localhost:8000
API Documentation: http://localhost:8000/docs
Health check: http://localhost:8000/health
# Navigate to Frontend directory
cd frontend/UI
# Install dependencies
npm install
# Start development server
npm run devFrontend will be running at: http://localhost:5173
| 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 |
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
After running reset_database.py, all seeded users and customers use password password123.
| 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 |
| Username | Password | Type |
|---|---|---|
| john_perera | password123 | Customer |
| ama_silva | password123 | Customer |
| kamal_fernando | password123 | Customer |
- Framework: FastAPI
- Database: MySQL 8.0
- ORM: SQLAlchemy with PyMySQL
- Authentication: JWT (JSON Web Tokens)
- Server: Uvicorn (ASGI)
- Framework: React 19
- Router: React Router v7
- Build Tool: Vite
- UI Library: Radix UI + Tailwind CSS
- Charts: Recharts
- Maps: Leaflet + React-Leaflet
- Language: TypeScript
- DBMS: MySQL
- Tables: 18 core tables
- Stored Procedures: 8 reporting procedures
- Sample Data: Pre-populated test data
- Multiple warehouse support
- Inventory tracking
- Warehouse staff assignment
- Role-based warehouse access
- Order creation and tracking
- Status management (Placed, In Progress, Completed, Cancelled, In Warehouse)
- Warehouse assignment (for Management)
- Customer order history
- Trucks: Management and scheduling
- Trains: Railway logistics integration
- Drivers: Working hour tracking
- Assistants: Schedule management
- Route creation and management
- Distance calculation
- City-to-city routing
- Railway station integration
- 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
- JWT-based authentication
- Role-based access control (RBAC)
- Password hashing (bcrypt)
- Protected API endpoints
- CORS configuration
| 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 |
# 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# 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=truePOST /users/login- Staff/user authenticationPOST /customers/login- Customer authentication
GET /orders- List all ordersGET /orders/{id}- Get order detailsPOST /orders- Create new orderPUT /orders/{id}- Update orderDELETE /orders/{id}- Delete orderPOST /orders/{id}/assign-warehouse- Assign to warehouse
- Cities:
/cities - Railway Stations:
/railway-stations - Stores/Warehouses:
/stores - Products:
/products - Routes:
/routes - Trains:
/trains - Trucks:
/trucks - Drivers:
/drivers - Assistants:
/assistants
/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
# 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"- Open http://localhost:5173
- Click "Login"
- Enter credentials (e.g., admin/password123 or store_manager1/password123)
- Navigate through dashboard
- Test creating/viewing orders
- Check warehouse assignment (Management role)
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
# Make code changes
# Server auto-reloads with --reload flag
# Test in Swagger UI
# Open http://localhost:8000/docs
# Check logs in terminal# Make code changes
# Vite auto-reloads on save
# Test in browser
# Check Network tab in DevTools
# View console for errors# Update SQL files in Backend/schemas/
# Re-run bootstrap
cd Backend
printf 'yes\n' | python3 reset_database.py
python3 apply_stored_procedures.py- Check MySQL is running
- Verify
MYSQL_PASSWORD(and otherMYSQL_*vars) inBackend/.env - Check port 8000 is available
- Confirm
SECRET_KEYis set whenDEBUG=false
- Verify backend is running on port 8000
- Check
.envfile exists infrontend/UI/ - Ensure
VITE_API_BASE_URL=http://localhost:8000 - Check browser console for CORS errors
- Verify credentials match test accounts
- Check password is correct (case-sensitive)
- Ensure database has sample users
- Check JWT token in localStorage
- Re-run bootstrap:
printf 'yes\n' | python3 reset_database.pythenpython3 apply_stored_procedures.py - Check MySQL credentials in
Backend/.env - Verify database exists:
SHOW DATABASES; - Check tables exist:
USE kandypack_db; SHOW TABLES;
- Swagger UI: Interactive API docs at
/docs - ReDoc: Alternative API docs at
/redoc - Postman: API testing and collections
- MySQL Workbench: Database management
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
See LICENSE file for details.
For issues or questions:
- Check documentation in
/docs - Review troubleshooting section
- Check API docs at http://localhost:8000/docs
- Review sample credentials
π’ 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