I'll show you how to run and test the complete full-stack Real Estate Chatbot application. Here's a comprehensive guide:
# Clone or create the backend directory
mkdir real-estate-backend
cd real-estate-backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env file with your configurations
# Run database migrations and seed data
python scripts/seed_data.py
# Start the backend server
uvicorn main:app --host 0.0.0.0 --port 8000 --reload# In a new terminal, navigate to frontend directory
cd real-estate-frontend
# Install dependencies
npm install
# or
yarn install
# Set up environment variables
cp .env.example .env.local
# Edit .env.local with backend URL:
# NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
# Start the frontend development server
npm run dev
# or
yarn devCreate a docker-compose.yml file in your root directory:
version: '3.8'
services:
# Backend API
api:
build:
context: ./real-estate-backend
target: development
ports:
- "8000:8000"
environment:
- ENVIRONMENT=development
- DATABASE_URL=sqlite+aiosqlite:///./real_estate.db
- DEBUG=true
- ALLOWED_ORIGINS=["http://localhost:3000"]
volumes:
- ./real-estate-backend:/app
command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
# Frontend
frontend:
build:
context: ./real-estate-frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
volumes:
- ./real-estate-frontend:/app
- /app/node_modules
depends_on:
- api
command: npm run dev
# Database seeding (run once)
seed:
build:
context: ./real-estate-backend
target: development
environment:
- ENVIRONMENT=development
- DATABASE_URL=sqlite+aiosqlite:///./real_estate.db
volumes:
- ./real-estate-backend:/app
command: python scripts/seed_data.py
depends_on:
- apiRun with Docker:
# Start all services
docker-compose up
# Run database seeding (first time only)
docker-compose run seed
# View logs
docker-compose logs -f api
docker-compose logs -f frontendcurl http://localhost:8000/healthExpected response:
{
"status": "healthy",
"version": "1.0.0"
}Visit: http://localhost:8000/docs (Swagger UI)
Visit: http://localhost:8000/redoc (ReDoc)
# Get all properties
curl http://localhost:8000/api/v1/properties/
# Get property by ID
curl http://localhost:8000/api/v1/properties/1
# Create new property
curl -X POST http://localhost:8000/api/v1/properties/ \
-H "Content-Type: application/json" \
-d '{
"title": "Test Property",
"description": "A test property",
"price": 100000,
"currency": "USD",
"property_type": "apartment",
"bedrooms": 2,
"bathrooms": 1,
"area": 80,
"location": "Test Location",
"is_available": true
}'
# Filter properties
curl "http://localhost:8000/api/v1/properties/?property_type=apartment&min_price=100000&max_price=500000"# Send chat message (English)
curl -X POST http://localhost:8000/api/v1/chat/ \
-H "Content-Type: application/json" \
-d '{
"message": "Hello, I am looking for an apartment",
"language": "en"
}'
# Send chat message (Arabic)
curl -X POST http://localhost:8000/api/v1/chat/ \
-H "Content-Type: application/json" \
-d '{
"message": "مرحبا، أبحث عن شقة",
"language": "ar"
}'
# Get suggestions
curl "http://localhost:8000/api/v1/chat/suggestions?language=en"# Login
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"password": "testpassword"
}'
# Verify token (replace TOKEN with actual token from login)
curl -X POST http://localhost:8000/api/v1/auth/verify \
-H "Authorization: Bearer TOKEN"Visit: http://localhost:3000
# Test complete chat flow
curl -X POST http://localhost:8000/api/v1/chat/ \
-H "Content-Type: application/json" \
-d '{"message": "I want to buy a villa", "language": "en"}' | jq
# Verify property data is available
curl http://localhost:8000/api/v1/properties/ | jq '.properties | length'
# Test filtering based on chat intent
curl "http://localhost:8000/api/v1/properties/?property_type=villa" | jq# Install Apache Bench
sudo apt-get install apache2-utils # Ubuntu/Debian
brew install httpie # macOS
# Test API performance
ab -n 100 -c 10 http://localhost:8000/api/v1/properties/
ab -n 50 -c 5 -p chat_payload.json -T application/json http://localhost:8000/api/v1/chat/# Check if database was created and seeded
python -c "
import sqlite3
conn = sqlite3.connect('real_estate.db')
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM properties')
print(f'Properties in database: {cursor.fetchone()[0]}')
cursor.execute('SELECT title, price FROM properties LIMIT 3')
for row in cursor.fetchall():
print(f'- {row[0]}: ${row[1]:,.2f}')
conn.close()
"cd real-estate-backend
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov=app --cov-report=html
# Run specific test files
pytest tests/test_property_service.py -v
pytest tests/test_chat_service.py -v
pytest tests/test_api_endpoints.py -vcd real-estate-frontend
# Run unit tests
npm test
# or
yarn test
# Run tests with coverage
npm run test:coverage
# or
yarn test:coverage
# Run E2E tests (if configured)
npm run test:e2e# View real-time logs
docker-compose logs -f api
# Check specific log levels
grep "ERROR" logs/app.log
grep "INFO" logs/app.log# View Next.js logs
docker-compose logs -f frontend
# Browser console logs
# Open browser DevTools → Console tab# Health check endpoint
curl http://localhost:8000/health
# Database connectivity
curl http://localhost:8000/api/v1/properties/ | jq '.total'# Check if frontend is responding
curl http://localhost:3000
# Check API connectivity from frontend
curl http://localhost:3000/api/health# Database connection issues
python -c "from app.core.database import DatabaseManager; import asyncio; asyncio.run(DatabaseManager().initialize())"
# Port already in use
lsof -ti:8000 | xargs kill -9
# Dependencies issues
pip install -r requirements.txt --force-reinstall# Node modules issues
rm -rf node_modules package-lock.json
npm install
# Port already in use
lsof -ti:3000 | xargs kill -9
# Environment variables
echo $NEXT_PUBLIC_API_BASE_URLhttp://localhost:8000http://localhost:3000http://localhost:8000/docsThe application should now be fully functional with enterprise-level architecture, complete testing coverage, and production-ready deployment configuration!
I'll provide you with a complete step-by-step guide to run both the backend and frontend locally on your machine.
First, create the project structure:
# Create main project directory
mkdir real-estate-chatbot
cd real-estate-chatbot
# Create backend and frontend directories
mkdir backend frontendcd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activateCreate requirements.txt:
fastapi==0.104.1
uvicorn[standard]==0.24.0
pydantic==2.5.0
pydantic-settings==2.1.0
sqlalchemy[asyncio]==2.0.23
aiosqlite==0.19.0
alembic==1.13.1
httpx==0.25.2
python-jose[cryptography]==3.3.0
python-multipart==0.0.6
pytest==7.4.3
pytest-asyncio==0.21.1
pytest-cov==4.1.0pip install -r requirements.txtCreate .env file in backend directory:
# Application Configuration
APP_NAME=Real Estate API
ENVIRONMENT=development
DEBUG=true
# Database Configuration
DATABASE_URL=sqlite+aiosqlite:///./real_estate.db
DATABASE_ECHO=false
# Security Configuration
SECRET_KEY=your-super-secret-key-change-this-in-production-12345
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# CORS Configuration
ALLOWED_ORIGINS=["http://localhost:3000","http://localhost:3001"]
# External API Configuration
EXTERNAL_API_BASE_URL=https://api.example.com
EXTERNAL_API_KEY=your-external-api-key
EXTERNAL_API_TIMEOUT=30
EXTERNAL_API_RETRY_ATTEMPTS=3
# Logging Configuration
LOG_LEVEL=INFO
ELK_ENDPOINT=
ELK_INDEX=real-estate-api
# Internationalization
DEFAULT_LANGUAGE=en
SUPPORTED_LANGUAGES=["en","ar"]Copy all the backend Python files from the previous code project into your backend directory. The structure should look like:
backend/
├── app/
│ ├── __init__.py
│ ├── api/
│ ├── core/
│ ├── models/
│ ├── schemas/
│ ├── services/
│ ├── utils/
│ └── middleware/
├── tests/
├── scripts/
├── main.py
├── requirements.txt
└── .env# Run the seed script to create database and add sample data
python scripts/seed_data.py# Start the FastAPI server
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadYou should see output like:
INFO: Will watch for changes in these directories: ['/path/to/backend']
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Started reloader process [12345] using StatReload
INFO: Started server process [12346]
INFO: Waiting for application startup.
INFO: Application startup complete.Open a new terminal and test:
# Test health endpoint
curl http://localhost:8000/health
# Test properties endpoint
curl http://localhost:8000/api/v1/properties/
# Visit API documentation
# Open browser: http://localhost:8000/docs# Go to frontend directory (open new terminal)
cd ../frontend
# Initialize Next.js project
npx create-next-app@latest . --typescript --tailwind --eslint --app --src-dir --import-alias "@/*"# Install required packages
npm install axios lucide-react class-variance-authority clsx tailwind-merge
# Install development dependencies
npm install -D @types/node @typescript-eslint/eslint-plugin @typescript-eslint/parser jest @testing-library/react @testing-library/jest-domCreate .env.local in frontend directory:
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
NEXT_PUBLIC_ELK_ENDPOINT=
NEXT_PUBLIC_ENVIRONMENT=developmentCopy all the frontend code from the previous code project into your frontend directory. Make sure to:
package.json with the dependenciesThe structure should look like:
frontend/
├── app/
│ ├── globals.css
│ ├── layout.tsx
│ ├── page.tsx
│ └── api/
├── components/
├── hooks/
├── services/
├── types/
├── utils/
├── constants/
├── __tests__/
├── package.json
├── .env.local
└── next.config.jsMake sure your package.json includes all necessary dependencies:
{
"name": "real-estate-chatbot",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint:fix": "next lint --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"type-check": "tsc --noEmit"
},
"dependencies": {
"next": "14.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"axios": "^1.6.0",
"lucide-react": "^0.294.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"tailwind-merge": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.9.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.53.0",
"eslint-config-next": "14.0.0",
"jest": "^29.7.0",
"@testing-library/react": "^13.4.0",
"@testing-library/jest-dom": "^6.1.4",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"typescript": "^5.2.2"
}
}npm installnpm run devYou should see output like:
▲ Next.js 14.0.0
- Local: http://localhost:3000
- Environments: .env.local
✓ Ready in 2.3sOpen your browser and visit: http://localhost:3000
You should see the Real Estate Chatbot interface.
In a new terminal:
cd backend
# Test API endpoints
curl http://localhost:8000/health
curl http://localhost:8000/api/v1/properties/
curl -X POST http://localhost:8000/api/v1/chat/ \
-H "Content-Type: application/json" \
-d '{"message": "Hello, I want to buy an apartment", "language": "en"}'
# Run backend tests
pytest tests/ -vIn another terminal:
cd frontend
# Run frontend tests
npm test
# Type checking
npm run type-check
# Linting
npm run linthttp://localhost:3000You'll need 3 terminal windows:
Terminal 1 - Backend:
cd backend
source venv/bin/activate # On Windows: venv\Scripts\activate
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadTerminal 2 - Frontend:
cd frontend
npm run devTerminal 3 - Testing/Commands:
# Use this for running tests, curl commands, etc.Create a start.sh script in your root directory:
#!/bin/bash
# Start backend
echo "Starting backend..."
cd backend
source venv/bin/activate
uvicorn main:app --host 0.0.0.0 --port 8000 --reload &
BACKEND_PID=$!
# Wait a moment for backend to start
sleep 3
# Start frontend
echo "Starting frontend..."
cd ../frontend
npm run dev &
FRONTEND_PID=$!
echo "Backend running on http://localhost:8000"
echo "Frontend running on http://localhost:3000"
echo "API Docs available at http://localhost:8000/docs"
# Wait for user input to stop
read -p "Press Enter to stop all services..."
# Kill processes
kill $BACKEND_PID
kill $FRONTEND_PIDMake it executable and run:
chmod +x start.sh
./start.shPort 8000 already in use:
# Find and kill process using port 8000
lsof -ti:8000 | xargs kill -9
# Or use a different port
uvicorn main:app --host 0.0.0.0 --port 8001 --reloadDatabase issues:
# Delete and recreate database
rm real_estate.db
python scripts/seed_data.pyImport errors:
# Make sure you're in the right directory and virtual environment is activated
pwd
which python
pip listPort 3000 already in use:
# Kill process on port 3000
lsof -ti:3000 | xargs kill -9
# Or use different port
npm run dev -- -p 3001Module not found errors:
# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm installAPI connection issues:
# Check if backend is running
curl http://localhost:8000/health
# Check environment variables
cat .env.localIf you get CORS errors, make sure your backend .env file has:
ALLOWED_ORIGINS=["http://localhost:3000","http://localhost:3001"]{"status": "healthy"}Once all items are checked, your full-stack Real Estate Chatbot application is running successfully locally! 🎉