A robust and scalable FastAPI backend for the AI Stylist App that provides personalized fashion advice through an AI chat interface, wardrobe management, and user profile customization.
Front-End Of Lulu AI Fashion Stylist
- 🤖 AI Chat Interface: Personalized outfit suggestions and fashion tips using OpenAI integration
- 👕 Wardrobe Management: Digital wardrobe organization with image upload and categorization
- 👤 User Profile Management: Detailed user preferences and measurements storage
- 🔐 JWT Authentication: Secure access with refresh token support
- 📦 Microservices Architecture: Scalable design with separate services
- ☁️ Cloud Storage: AWS S3 integration for image storage
- 📊 Dual Database: PostgreSQL for structured data, MongoDB for chat history
- Backend Framework: FastAPI
- Databases:
- PostgreSQL (User data, Wardrobe items)
- MongoDB (Chat sessions, Messages)
- Cloud Services:
- AWS S3 (Image storage)
- OpenAI API (Chat intelligence)
- Development Tools:
- Docker & Docker Compose
- Alembic (Database migrations)
- GitHub Actions (CI/CD)
- Python 3.8+
- Docker and Docker Compose
- PostgreSQL
- MongoDB
- AWS Account (for S3)
- OpenAI API Key
- Clone the Repository:
git clone https://github.com/yourusername/ai-stylist-backend.git
cd ai-stylist-backend
- Environment Setup:
Create a
.env
file in the root directory with the following variables:
# Database Configuration
DATABASE_URL=postgresql://<username>:<password>@localhost:5432/ai_fashion_app
POSTGRES_USER=<username>
POSTGRES_PASSWORD=<password>
POSTGRES_DB=ai_fashion_app
# MongoDB Configuration
MONGODB_URL=mongodb://localhost:27017
MONGODB_DB_NAME=ai_chat
MONGODB_HOST=mongodb
# JWT Configuration
SECRET_KEY=<your-secret-key>
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7
REFRESH_SECRET_KEY=<your-refresh-secret-key>
# AWS Configuration
AWS_ACCESS_KEY_ID=<your-aws-access-key>
AWS_SECRET_ACCESS_KEY=<your-aws-secret-key>
AWS_REGION=us-east-1
AWS_S3_BUCKET=aifashion-images
# OpenAI Configuration
OPENAI_API_KEY=<your-openai-api-key>
OPENAI_MAX_TOKENS=8000
- Docker Deployment:
_# Build and start services_
docker compose up -d
_# Check logs_
docker compose logs -f
- Local Development Setup:
_# Create virtual environment_
python -m venv venv
source venv/bin/activate _# On Windows: venv\Scripts\activate_
_# Install dependencies_
pip install -r requirements.txt
_# Run migrations_
alembic upgrade head
_# Start the application_
uvicorn app.main:app --reload
├── app/
│ ├── auth/ # Authentication & authorization
│ ├── database/ # Database connections & models
│ ├── models/ # SQLAlchemy models
│ ├── routers/ # API routes
│ ├── schemas/ # Pydantic models
│ ├── services/ # Business logic
│ └── main.py # Application entry point
├── migrations/ # Alembic migrations
├── tests/ # Test files
├── docs/ # Documentation
├── .github/ # GitHub Actions workflows
├── docker-compose.yml # Docker composition
├── requirements.txt # Python dependencies
└── README.md
Access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
POST /api/register
- Register new userPOST /api/login
- User loginPOST /api/refresh
- Refresh access token
GET /api/users/me
- Get current user profilePUT /api/users/me/profile
- Update user profilePOST /api/users/me/profile-picture
- Upload profile picture
GET /api/wardrobe/items
- List wardrobe itemsPOST /api/wardrobe/items
- Add new itemGET /api/wardrobe/items/{item_id}
- Get item detailsPUT /api/wardrobe/items/{item_id}
- Update itemDELETE /api/wardrobe/items/{item_id}
- Delete itemPOST /api/wardrobe/items/{item_id}/image
- Upload item image
POST /api/chat/sessions
- Create chat sessionGET /api/chat/sessions
- List chat sessionsPOST /api/chat/{session_id}/message
- Send messageGET /api/chat/{session_id}
- Get chat history
pytest
_# Create a new migration_
alembic revision --autogenerate -m "description"
_# Apply migrations_
alembic upgrade head
The application uses GitHub Actions for CI/CD. On push to main:
- Tests are run
- Docker images are built
- Application is deployed to production
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit changes (
git commit -m 'Add AmazingFeature'
) - Push to branch (
git push origin feature/AmazingFeature
) - Open a Pull Request