This guide covers three scenarios: Initial Setup, Development Workflow, and Running Again.
Follow these steps when setting up the project for the first time.
Windows:
- Download PostgreSQL from https://www.postgresql.org/download/windows/
- Run the installer (recommended version: 15 or 16)
- During installation:
- Set password for
postgresuser (remember this!) - Port:
5432(default) - Install Stack Builder when prompted
- Set password for
- In Stack Builder:
- Select "Spatial Extensions"
- Install PostGIS 3.x
Docker Alternative:
docker run --name postgis -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgis/postgis:15-3.3Windows:
- Download from https://www.mongodb.com/try/download/community
- Run the installer
- Choose "Complete" installation
- Install as Windows Service (port 27017)
Docker Alternative:
docker run --name mongodb -p 27017:27017 -d mongo:latestCloud Alternative (MongoDB Atlas):
- Create free account at https://www.mongodb.com/cloud/atlas
- Create free cluster
- Get connection string
# Check PostgreSQL
psql --version
# Check MongoDB
mongosh --version
# Check Python
python --version
# Should be 3.9 or higher# Connect to PostgreSQL
psql -U postgres
# Inside psql prompt:
CREATE DATABASE trip_verbalization;
\c trip_verbalization
CREATE EXTENSION postgis;
\qVerify PostGIS:
psql -U postgres -d trip_verbalization -c "SELECT PostGIS_version();"# Using mongosh
mongosh
> use trip_verbalization
> db.test.insertOne({test: "connection"})
> db.test.find()
> exit# Navigate to project directory
cd "d:\5th Sem\dbms"
# Create virtual environment
python -m venv venv
# Activate virtual environment
venv\Scripts\activate
# Upgrade pip (optional but recommended)
python -m pip install --upgrade pip
# Install dependencies
pip install -r requirements.txt
# Install async PostgreSQL driver
pip install asyncpgcopy .env.example .env
notepad .envpython -c "import secrets; print(secrets.token_hex(32))"Copy the output.
Update the following in .env:
# PostgreSQL - Update password if different
DATABASE_URL=postgresql://postgres:your_postgres_password@localhost:5432/trip_verbalization
# MongoDB - Local installation
MONGODB_URL=mongodb://localhost:27017/trip_verbalization
# MongoDB Atlas alternative
# MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/trip_verbalization
# JWT Secret - Paste the generated key here
JWT_SECRET_KEY=paste_your_generated_secret_here
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# External APIs (optional, leave empty for now)
GEOCODING_API_KEY=
LLM_API_KEY=
# Application Settings
APP_NAME=AI Trip Data Verbalization System
APP_VERSION=1.0.0
DEBUG=True
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:8000Save and close the file.
# Make sure virtual environment is activated
# You should see (venv) in your prompt
python init_db.pyExpected Output:
Initializing database...
Creating PostGIS extension...
Creating tables...
Database initialized successfully!
Creating default admin user...
Admin user created successfully!
Username: admin
Password: admin123
⚠️ Please change the password after first login!
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Expected Output:
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Started reloader process
Starting AI Trip Data Verbalization System v1.0.0
Debug mode: True
Initializing database...
Database initialized successfully
INFO: Application startup complete.
-
Open API Documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
-
Test the API:
- Click "Authorize" button in Swagger UI
- Login with:
- Username:
admin - Password:
admin123
- Username:
- Try creating a trip, searching trips, etc.
Edit app/models.py:
class NewModel(Base):
__tablename__ = "new_table"
id = Column(Integer, primary_key=True)
# ... add fieldsEdit app/schemas.py:
class NewModelCreate(BaseModel):
field: str
# ... add validatorsCreate app/routers/new_feature.py:
from fastapi import APIRouter, Depends
from ..auth import get_current_active_user
router = APIRouter(prefix="/new", tags=["New Feature"])
@router.post("/")
async def create_item(...):
passEdit app/main.py:
from .routers import auth, trips, config, feedback, new_feature
app.include_router(new_feature.router)# Drop and recreate (WARNING: Deletes all data!)
python init_db.py drop
python init_db.py
# Or use Alembic for migrations (recommended for production)# Restart the server (Ctrl+C, then)
uvicorn app.main:app --reloadThe development server (--reload flag) automatically restarts when you save files:
- Edit files in
app/directory - Save the file
- Server automatically reloads
- Test changes in browser at http://localhost:8000/docs
Files to edit:
- Models:
app/models.py(database tables) - Schemas:
app/schemas.py(validation) - Auth:
app/auth.py(authentication logic) - Routes:
app/routers/*.py(API endpoints) - Config:
app/config.py(settings)
# Activate virtual environment
venv\Scripts\activate
# Install new package
pip install package-name
# Update requirements.txt
pip freeze > requirements.txtUse these steps every time you want to run the application after initial setup.
# 1. Navigate to project
cd "d:\5th Sem\dbms"
# 2. Activate virtual environment
venv\Scripts\activate
# 3. Start the application
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000That's it! Open http://localhost:8000/docs in your browser.
Windows Service:
# Check status
Get-Service postgresql*
# Start if needed
Start-Service postgresql-x64-15 # Adjust version numberDocker:
docker start postgisWindows Service:
# Check status
Get-Service MongoDB
# Start if needed
Start-Service MongoDBDocker:
docker start mongodbIf you've pulled updates from Git:
# 1. Activate environment
venv\Scripts\activate
# 2. Update dependencies
pip install -r requirements.txt
# 3. Check for database changes
# If models.py changed, you may need to:
python init_db.py
# 4. Run application
uvicorn app.main:app --reload# When tests are implemented
pytest
# With coverage
pytest --cov=app tests/Solution:
# Ensure virtual environment is activated
venv\Scripts\activate
# Reinstall dependencies
pip install -r requirements.txtPostgreSQL:
# Check if running
psql -U postgres -d trip_verbalization
# Verify .env has correct credentials
notepad .env
# Test connection
psql -U postgres -d trip_verbalization -c "SELECT 1;"MongoDB:
# Check if running
mongosh
# Restart service
net stop MongoDB
net start MongoDBSolution:
psql -U postgres -d trip_verbalizationInside psql:
CREATE EXTENSION IF NOT EXISTS postgis;
\dx -- List installed extensions
\qSolution:
# Find process using port 8000
netstat -ano | findstr :8000
# Kill the process (replace PID with actual process ID)
taskkill /PID <PID> /F
# Or use a different port
uvicorn app.main:app --reload --port 8001Solution:
pip install asyncpgSolution:
- Logout from Swagger UI
- Generate new JWT secret:
python -c "import secrets; print(secrets.token_hex(32))"
- Update
.envwith new secret - Restart application
- Login again
Solution:
# Reinitialize database
python init_db.py# Start development session
cd "d:\5th Sem\dbms"
venv\Scripts\activate
uvicorn app.main:app --reload
# Stop server: Ctrl+C
# Deactivate virtual environment: deactivate# Connect to PostgreSQL
psql -U postgres -d trip_verbalization
# Common SQL commands
\dt # List tables
\d table_name # Describe table
SELECT * FROM users LIMIT 5;
# MongoDB
mongosh
> use trip_verbalization
> show collections
> db.collection_name.find()python init_db.py drop
python init_db.py- PostgreSQL installed with PostGIS
- MongoDB installed
- Database created (
trip_verbalization) - PostGIS extension enabled
- Virtual environment created
- Dependencies installed (
pip install -r requirements.txt) -
asyncpginstalled -
.envfile created and configured - JWT secret generated
- Database initialized (
python init_db.py) - Application runs successfully
- Can access http://localhost:8000/docs
- Navigate to project directory
- Activate virtual environment
- PostgreSQL running
- MongoDB running
- Start application (
uvicorn app.main:app --reload) - Access http://localhost:8000/docs
- Pull latest code
- Activate virtual environment
- Update dependencies (
pip install -r requirements.txt) - Check for model changes (reinit db if needed)
- Run application
Once your development environment is running:
- Change admin password via Swagger UI
- Create test users with different roles
- Test all API endpoints interactively
- Integrate LLM for trip verbalization
- Add geocoding service for address resolution
- Build frontend application
For detailed API documentation, see: README.md
For implementation details, see: walkthrough.md