Getting Started
This guide will help you set up Habits Factory for local development.
Prerequisites
Before you begin, ensure you have the following installed:
- Python 3.10+ - For the Django backend
- Node.js 18+ - For the Vue.js frontend
- npm or yarn - Package manager for frontend dependencies
- Git - Version control
Clone the Repository
Backend Setup
1. Create a Virtual Environment
Activate the virtual environment:
2. Install Dependencies
3. Configure Environment Variables
Create a .env file in the backend directory:
DEBUG=True
SECRET_KEY=your-secret-key-here
DATABASE_URL=sqlite:///db.sqlite3
ALLOWED_HOSTS=localhost,127.0.0.1
CORS_ALLOWED_ORIGINS=http://localhost:5173
4. Run Migrations
5. Create a Superuser (Optional)
6. Start the Backend Server
The API will be available at http://localhost:8000.
Frontend Setup
1. Install Dependencies
Open a new terminal and navigate to the frontend directory:
2. Configure Environment Variables
Create a .env file in the frontend directory:
3. Start the Development Server
The application will be available at http://localhost:5173.
Docker Setup (Coming Soon)
A Docker Compose configuration is planned for simplified setup:
This will provide:
- Local development environment
- Production parity
- Isolated dependencies
Project Structure
habitsfactory-app/
├── backend/ # Django REST API
│ ├── api/ # API endpoints
│ ├── habits/ # Habit models and logic
│ ├── analytics/ # Correlation algorithms
│ └── manage.py
├── frontend/ # Vue.js application
│ ├── src/
│ │ ├── components/ # Vue components
│ │ ├── views/ # Page views
│ │ ├── stores/ # State management
│ │ └── api/ # Axios API client
│ ├── public/
│ └── vite.config.js
└── docker-compose.yml # (Coming soon)
Verifying the Installation
- Backend: Visit
http://localhost:8000/api/to see the API root - Frontend: Visit
http://localhost:5173to see the application - Admin: Visit
http://localhost:8000/admin/to access Django admin
Troubleshooting
CORS Errors
If you see CORS errors in the browser console:
- Verify
CORS_ALLOWED_ORIGINSin your backend.envfile - Ensure the frontend URL matches the allowed origin
- Restart the backend server after changes
Database Errors
If migrations fail:
Port Conflicts
If ports 8000 or 5173 are in use:
# Run backend on different port
python manage.py runserver 8001
# Run frontend on different port
npm run dev -- --port 3000
Update your .env files accordingly.
Next Steps
- Read the Architecture documentation to understand the system design
- Explore Features to learn what Habits Factory can do
- Check the API Reference for endpoint documentation