# Quick Start Guide - Dubai DLD Analytics API ## Prerequisites โœ… - **Node.js** 16+ installed - **MySQL** 8.0+ installed and running - **Dubai DLD database** with provided schema ## Installation (3 Steps) ๐Ÿš€ ### Step 1: Install Dependencies ```bash npm install ``` ### Step 2: Configure Database Create a `.env` file in the project root: ```env DB_HOST=localhost DB_PORT=3306 DB_NAME=dubai_dld DB_USER=root DB_PASSWORD=your_password ``` Import the database schema: ```bash mysql -u root -p < 2.sql ``` ### Step 3: Start the Server ```bash npm run dev ``` The server will start on `http://localhost:3000` ## Testing the API ๐Ÿงช ### Health Check ```bash curl http://localhost:3000/health ``` ### Sample Query - Rental Trend ```bash curl -X POST http://localhost:3000/api/query \ -H "Content-Type: application/json" \ -d '{"query": "Give me the last 6 months rental price trend for Business Bay"}' ``` ### Predefined Queries ```bash # Top areas curl http://localhost:3000/api/queries/top-areas # Project summary curl http://localhost:3000/api/queries/project-summary # Commercial leasing curl http://localhost:3000/api/queries/commercial-leasing ``` ## Frontend Demo ๐ŸŽจ Open `public/index.html` in your browser to see the interactive dashboard with Chart.js visualizations. ## Available Endpoints ๐Ÿ“ก | Endpoint | Method | Description | |----------|--------|-------------| | `/api/query` | POST | Custom natural language queries | | `/api/queries/rental-trend/:area` | GET | Rental trends for area | | `/api/queries/top-areas` | GET | Top areas by transactions | | `/api/queries/project-summary` | GET | Project summaries | | `/api/queries/commercial-leasing` | GET | Commercial leasing analysis | | `/api/queries/residential-leasing` | GET | Residential leasing analysis | | `/health` | GET | Health check | | `/api/database/info` | GET | Database statistics | ## Common Queries ๐Ÿ’ก ### Rental Analysis - "Give me the last 6 months rental price trend for Business Bay" - "Show me rental prices for apartments in Downtown" - "What's the average rental price in Dubai Marina?" ### Project Analysis - "Brief about the Project" - "List of fast moving projects in last 6 months" - "Which areas have off-plan projects?" ### Area Performance - "Which area is having more rental transactions?" - "Top 5 areas for Commercial leasing and why?" - "Avg price of 3BHK apartment by area in last 6 months" ## Troubleshooting ๐Ÿ”ง ### Database Connection Error ```bash # Check if MySQL is running mysql -u root -p -e "SELECT 1" # Verify database exists mysql -u root -p -e "SHOW DATABASES LIKE 'dubai_dld'" ``` ### Port Already in Use ```bash # Change PORT in .env file PORT=3001 ``` ### Module Not Found ```bash # Reinstall dependencies rm -rf node_modules package-lock.json npm install ``` ## Project Structure ๐Ÿ“ ``` dubai-dld-analytics/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ app.js # Main application โ”‚ โ”œโ”€โ”€ models/ โ”‚ โ”‚ โ””โ”€โ”€ database.js # MySQL connection โ”‚ โ”œโ”€โ”€ services/ โ”‚ โ”‚ โ”œโ”€โ”€ nlpService.js # NLP parsing โ”‚ โ”‚ โ”œโ”€โ”€ sqlGenerator.js # SQL generation โ”‚ โ”‚ โ””โ”€โ”€ chartFormatter.js # Chart.js formatting โ”‚ โ”œโ”€โ”€ routes/ โ”‚ โ”‚ โ””โ”€โ”€ api.js # API routes โ”‚ โ””โ”€โ”€ middleware/ โ”‚ โ””โ”€โ”€ validation.js # Request validation โ”œโ”€โ”€ public/ โ”‚ โ””โ”€โ”€ index.html # Demo dashboard โ”œโ”€โ”€ tests/ โ”‚ โ””โ”€โ”€ api.test.js # API tests โ”œโ”€โ”€ package.json โ”œโ”€โ”€ 2.sql # Database schema โ””โ”€โ”€ README.md ``` ## Next Steps ๐ŸŽฏ 1. **Customize Queries**: Add your own query templates in `sqlGenerator.js` 2. **Extend NLP**: Improve parsing in `nlpService.js` 3. **Add More Charts**: Enhance chart visualization in `chartFormatter.js` 4. **Deploy**: Deploy to production (Vercel, Heroku, AWS, etc.) ## Need Help? ๐Ÿ’ฌ Check the full documentation in `README.md` or review the code examples in the services directory. Happy analyzing! ๐Ÿ“Š