# Quick Start Guide ## ✅ Backend is Ready! Your complete Express.js backend with PostgreSQL is now running on **http://localhost:4000** ## 🚀 What's Been Done 1. ✅ **Database Setup** - Created 7 tables with proper relationships - Added indexes for performance - Seeded with sample data 2. ✅ **API Endpoints Working** - Parties API: `/api/parties` - Mirchi Types API: `/api/mirchi-types` - Lots API: `/api/lots` - Transactions API: `/api/transactions` 3. ✅ **Sample Data Loaded** - 5 Parties (Ramesh Traders, Suresh & Co, etc.) - 5 Mirchi Types (Teja, Byadgi, Guntur Sannam, etc.) - 3 Active Lots with stock - 1 Sample Transaction ## 🔧 Available Commands ```bash cd backend # Start server (currently running) npm start # Development mode with auto-reload npm run dev # Database management npm run migrate # Create tables npm run seed # Add sample data npm run reset # Drop all tables (⚠️ use with caution) ``` ## 📡 Test the API **Health Check:** ```bash curl http://localhost:4000/health ``` **Get All Parties:** ```bash curl http://localhost:4000/api/parties ``` **Get All Mirchi Types:** ```bash curl http://localhost:4000/api/mirchi-types ``` **Get All Transactions:** ```bash curl http://localhost:4000/api/transactions ``` ## 🔗 Connect Frontend Update your frontend's `db.ts` file: - The API_BASE is already set to `http://localhost:4000/api` - All endpoints are ready to use - No changes needed in frontend code! ## 📊 Database Schema **Tables:** 1. `parties` - Customer/supplier management 2. `mirchi_types` - Chili pepper varieties 3. `lots` - Inventory with stock tracking 4. `transactions` - Purchase/sales bills 5. `transaction_items` - Line items 6. `expenses` - Transaction expenses 7. `payments` - Payment records ## 🎯 Next Steps 1. Keep the backend server running 2. Start your frontend: `cd frontend && npm run dev` 3. Test the complete application! ## 💡 Features - ✅ Full CRUD operations for all entities - ✅ Automatic stock management (lots) - ✅ Party balance tracking - ✅ Payment tracking with multiple modes - ✅ Support for returns (purchase/sales) - ✅ Transaction filtering by party, type, etc. - ✅ Proper error handling and validation ## 🐛 Troubleshooting **Server not starting?** - Check if port 4000 is available - Verify PostgreSQL connection in `.env` **Database errors?** - Run `npm run reset` then `npm run migrate` and `npm run seed` **API not responding?** - Check server logs in terminal - Verify server is running on port 4000