This guide will help you set up the CarHub application on your local machine.
Before starting, ensure you have the following installed:
- Python 3.9+ (recommended 3.11+)
- pip (Python package manager)
- Git
- A text editor or IDE (VSCode recommended)
# Clone the repository
git clone https://github.com/yourusername/carhub.git
# Navigate to the project directory
cd carhubIt's recommended to use a virtual environment to avoid package conflicts.
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
venv\Scripts\activate# Create a virtual environment
python -m venv venv
# Activate the virtual environment
source venv/bin/activate# Install required packages
pip install -r requirements.txt- Create a
.envfile in the project root:
cp .env.example .env- Edit the
.envfile with your configuration:
# Security
SECRET_KEY=your_generated_secret_key
# Email Configuration (Optional - for password reset emails)
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USE_TLS=True
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_DEFAULT_SENDER=your-email@gmail.com
# Google OAuth Configuration (Optional)
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-google-client-secret
# OpenAI Configuration (Required for Chatbot)
OPENAI_API_KEY=your-openai-api-keypython -c "import secrets; print(secrets.token_hex(32))"Copy the output to your .env file as the SECRET_KEY.
The application will automatically create the database on first run, but you can initialize it explicitly:
python app.pypython app.pyThe application will be available at: http://127.0.0.1:5000
You can use the provided test accounts, or create a new admin account:
# Start Python interactive shell
python
# In the Python shell:
from app import app, db, User
from werkzeug.security import generate_password_hash
with app.app_context():
admin = User(
username='admin',
email='your-admin-email@example.com',
password_hash=generate_password_hash('your-secure-password'),
role='admin',
is_verified=True
)
db.session.add(admin)
db.session.commit()
print("Admin account created successfully!")
# Exit the Python shell
exit()If using Gmail for password reset emails:
- Enable 2-Step Verification in your Google account
- Generate an App Password:
- Go to Google Account Security
- Under "Signing in to Google", select "App passwords"
- Select "Mail" and "Other" (Type "CarHub")
- Use the generated password in your
.envfile
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to "APIs & Services" > "Credentials"
- Create OAuth client ID (Web application)
- Set authorized redirect URIs:
- Add client ID and secret to your
.envfile
- Create an account at OpenAI
- Go to API keys section
- Generate a new API key
- Add the key to your
.envfile
- Ensure the
instancedirectory exists and is writable - If database errors occur, try deleting the database file and restarting:
rm instance/carhub.db python app.py
- Verify that all packages are installed:
pip install -r requirements.txt
- Check Python version compatibility
- Gmail requires an App Password, not your regular password
- Verify SMTP settings are correct
- Check API key format and validity
- Ensure you have sufficient credits in your OpenAI account
- Verify credentials and authorized domains
- Check for typos in client ID and secret
If you encounter issues:
- Check the Flask terminal output for errors
- Look in the browser console for frontend issues
- Verify all environment variables are set correctly
- Consult the CarHub development team
# Run all tests
python -m unittest discover
# Run specific test file
python -m unittest tests/test_authentication.pyFollow PEP 8 guidelines for Python code. Consider using linters:
# Install flake8
pip install flake8
# Run flake8
flake8 .- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes
- Test thoroughly
- Submit a pull request
You should now have a working installation of the CarHub application on your local machine. If you encounter any issues or have questions, please contact the development team.
Happy coding!✨