- Prerequisites
- Backend Setup
- Frontend Setup
- Database Configuration
- Running Locally
- Docker Deployment
- Production Deployment
- Troubleshooting
- Python 3.9+
- Node.js 16+
- PostgreSQL 12+
- Redis 6+
- Git
cd backend
git clone <repository-url>python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtcp .env.example .envEdit .env file with your configuration:
SECRET_KEY=your-secure-secret-key-here
DEBUG=False
ALLOWED_HOSTS=localhost,127.0.0.1,yourdomain.com
DB_ENGINE=django.db.backends.postgresql
DB_NAME=productivity_db
DB_USER=postgres
DB_PASSWORD=your_secure_password
DB_HOST=localhost
DB_PORT=5432
REDIS_URL=redis://localhost:6379/0
CORS_ALLOWED_ORIGINS=http://localhost:3000
# Using PostgreSQL psql
createdb productivity_db
createuser postgres_userpython manage.py makemigrations
python manage.py migratepython manage.py createsuperuserpython manage.py shell < seed_data.pypython manage.py collectstatic --noinputcd ../frontendnpm installcp .env.example .envEdit .env:
REACT_APP_API_URL=http://localhost:8000/api
cd backend
source venv/bin/activate
python manage.py runserver 0.0.0.0:8000cd backend
source venv/bin/activate
celery -A config worker -l infocd backend
source venv/bin/activate
daphne -b 0.0.0.0 -p 8001 config.asgi:applicationcd frontend
npm startAccess the application at http://localhost:3000
redis-servercd backend
docker build -t productivity-tracker-backend .cd frontend
docker build -t productivity-tracker-frontend .docker-compose up -ddocker exec productivity-tracker-backend python manage.py migrate
docker exec productivity-tracker-backend python manage.py createsuperuser- OS: Ubuntu 20.04 LTS
- Instance Type: t3.medium or larger
- Storage: 30GB SSD
sudo apt update
sudo apt install -y python3.9 python3-pip postgresql postgresql-contrib redis-server nodejs npm nginx supervisor
# Create Python virtual environment
python3 -m venv /home/ubuntu/venv
source /home/ubuntu/venv/bin/activatecd /home/ubuntu
git clone <repository-url>
cd Productivity-Tracking-Systemcd backend
pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic --noinputCreate /etc/supervisor/conf.d/productivity-tracker.conf:
[program:django]
directory=/home/ubuntu/Productivity-Tracking-System/backend
command=/home/ubuntu/venv/bin/gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 4
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/django.log
[program:celery]
directory=/home/ubuntu/Productivity-Tracking-System/backend
command=/home/ubuntu/venv/bin/celery -A config worker -l info
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/celery.log
[program:daphne]
directory=/home/ubuntu/Productivity-Tracking-System/backend
command=/home/ubuntu/venv/bin/daphne -b 0.0.0.0 -p 8001 config.asgi:application
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/daphne.logCreate /etc/nginx/sites-available/productivity-tracker:
upstream django {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name yourdomain.com;
client_max_body_size 20M;
location /static/ {
alias /home/ubuntu/Productivity-Tracking-System/backend/staticfiles/;
}
location /media/ {
alias /home/ubuntu/Productivity-Tracking-System/backend/media/;
}
location / {
proxy_pass http://django;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /ws/ {
proxy_pass http://127.0.0.1:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}Enable site:
sudo ln -s /etc/nginx/sites-available/productivity-tracker /etc/nginx/sites-enabled/
sudo systemctl restart nginxsudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.comcd ../frontend
npm install
npm run buildServe with Nginx or deploy to CDN.
az group create --name productivity-tracker-rg --location eastus
az appservice plan create --name productivity-plan --resource-group productivity-tracker-rg --sku B2 --is-linux
az webapp create --resource-group productivity-tracker-rg --plan productivity-plan --name productivity-tracker --runtime "PYTHON|3.9"az webapp config appsettings set --resource-group productivity-tracker-rg --name productivity-tracker \
--settings \
DJANGO_SETTINGS_MODULE=config.settings \
SECRET_KEY="your-secret-key" \
DEBUG=False \
ALLOWED_HOSTS="yourdomain.azurewebsites.net"az webapp deployment source config-zip --resource-group productivity-tracker-rg --name productivity-tracker --src path/to/code.zipSECRET_KEY=<generate-with-django>
DEBUG=False
ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
DB_ENGINE=django.db.backends.postgresql
DB_NAME=productivity_prod
DB_USER=prod_user
DB_PASSWORD=<strong-password>
DB_HOST=<database-host>
DB_PORT=5432
REDIS_URL=redis://<redis-host>:6379/0
CORS_ALLOWED_ORIGINS=https://yourdomain.com,https://www.yourdomain.com
# Email Configuration
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=<your-email>
EMAIL_HOST_PASSWORD=<app-password>
EMAIL_USE_TLS=True
# AWS S3 (for media files)
AWS_ACCESS_KEY_ID=<your-key>
AWS_SECRET_ACCESS_KEY=<your-secret>
AWS_STORAGE_BUCKET_NAME=<bucket-name>
AWS_S3_REGION_NAME=us-east-1
# Check PostgreSQL is running
sudo systemctl status postgresql
# Check connection
psql -U postgres -h localhost -d productivity_db# Check Redis is running
redis-cli ping
# Should return: PONGpython manage.py collectstatic --noinput --clear- Ensure Daphne is running on port 8001
- Check CORS configuration
- Verify firewall allows WebSocket connections
Update .env:
CORS_ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com
Reduce number of Gunicorn workers:
gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 2# View logs
tail -f /var/log/django.log
tail -f /var/log/celery.log
# Restart services
sudo supervisorctl restart django celery daphne
# Check migrations
python manage.py showmigrations
# Create backup
pg_dump productivity_db > backup.sql
# Restore backup
psql productivity_db < backup.sql# Analyze and optimize tables
ANALYZE;
VACUUM ANALYZE;
# Check indexes
SELECT * FROM pg_stat_user_indexes;Enable Redis caching in settings:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': config('REDIS_URL'),
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
}
}
}Use AWS ALB or Nginx to distribute traffic across multiple instances.
- Deploy ELK stack
- Configure Django logging to send to Logstash
- Create dashboards in Kibana
LOGGING = {
'handlers': {
'watchtower': {
'level': 'INFO',
'class': 'watchtower.CloudWatchLogHandler',
'log_group': 'productivity-tracker',
},
},
}-
Daily Database Backups
0 2 * * * pg_dump productivity_db | gzip > /backups/db-$(date +\%Y\%m\%d).sql.gz
-
Media Files Backup
- Use AWS S3 with versioning enabled
- Daily sync to secondary bucket
-
Automated Backups
- AWS RDS automated backups
- Point-in-time recovery enabled
For issues and questions:
- Check logs in
/var/log/ - Review database schema
- Test API endpoints with Postman
- Check WebSocket connectivity