A comprehensive Django-based backend service that allows freelancers to manage clients, track time, and generate professional invoices with PDF generation and Stripe payment integration.
- User Management: JWT-based authentication with multi-tenant data isolation
- Client Management: Full CRUD operations for client information
- Project Management: Organize work by projects with time tracking
- Time Tracking: Log billable hours with detailed descriptions
- Invoice Generation: Create professional PDF invoices from time entries
- Recurring Invoices: Schedule automatic invoice generation (weekly/monthly/quarterly)
- Email Integration: Send invoices directly to clients
- Stripe Integration: Accept online payments with Stripe checkout
- Background Tasks: Celery-powered scheduled tasks for automation
- RESTful API: Complete API with filtering, searching, and pagination
/invoice_generator/
βββ clients/ # Client management
βββ projects/ # Project management
βββ time_entries/ # Time tracking
βββ invoices/ # Invoice generation & PDF
βββ stripe_integration/ # Payment processing
βββ core/ # User management & base models
βββ templates/invoices/ # PDF & email templates
βββ static/ # Static files
βββ requirements.txt # Python dependencies
βββ docker-compose.yml # Development environment
βββ README.md # This file
- Backend: Django 5.0.2, Django REST Framework 3.14.0
- Database: PostgreSQL 15
- Authentication: JWT (djangorestframework-simplejwt)
- PDF Generation: WeasyPrint
- Payment Processing: Stripe
- Background Tasks: Celery + Redis
- Email: Django email backend
- Containerization: Docker & Docker Compose
- Python 3.11+
- Docker & Docker Compose
- PostgreSQL (if not using Docker)
-
Clone the repository
git clone <repository-url> cd invoice-generator
-
Set up environment variables
cp env.example .env # Edit .env with your configuration -
Start the services
docker-compose up -d
-
Run migrations
docker-compose exec web python manage.py migrate -
Create superuser
docker-compose exec web python manage.py createsuperuser -
Access the application
- App: http://localhost:8000/
- API: http://localhost:8000/api/
- Admin: http://localhost:8000/admin/
- API Documentation: http://localhost:8000/api-docs/
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp env.example .env # Edit .env with your configuration -
Set up database
python manage.py migrate python manage.py createsuperuser
-
Run the development server
python manage.py runserver
This project requires Python 3.11 or higher. If you encounter version-related errors:
-
Check your Python version:
python --version
-
If using Python 3.9 or earlier, upgrade to Python 3.11:
# On macOS with Homebrew brew install python@3.11 # Create virtual environment with Python 3.11 python3.11 -m venv venv source venv/bin/activate pip install -r requirements.txt
If you get "Couldn't import Django" errors even after activating your virtual environment:
-
Check if virtual environment is activated:
which python # Should show: /path/to/your/project/venv/bin/python -
If you have Python aliases that override your venv:
# Check for aliases type python # If it shows an alias, remove it unalias python # Reactivate your virtual environment deactivate source venv/bin/activate
-
Verify Django is installed in your venv:
python -m django --version # Should show: 5.0.2 -
If issues persist, recreate the virtual environment:
deactivate rm -rf venv python3.11 -m venv venv source venv/bin/activate pip install -r requirements.txt
If you encounter database connection errors:
-
For SQLite (default for development):
- The project is configured to use SQLite by default
- No additional setup required
-
For PostgreSQL:
- Install PostgreSQL
- Update your
.envfile with database credentials - Ensure PostgreSQL service is running
If you encounter migration errors:
-
Reset migrations (WARNING: This will delete your database):
rm db.sqlite3 # Only for SQLite find . -path "*/migrations/*.py" -not -name "__init__.py" -delete python manage.py makemigrations python manage.py migrate
-
If Django internal files are missing:
pip install --force-reinstall Django==5.0.2 python manage.py makemigrations python manage.py migrate
Create a .env file with the following variables:
# Django Settings
DEBUG=True
SECRET_KEY=your-secret-key-here
ALLOWED_HOSTS=localhost,127.0.0.1
# Database
DB_NAME=invoice_generator
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=localhost
DB_PORT=5432
# Redis
REDIS_URL=redis://localhost:6379/0
# Email
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-app-password
# Stripe (Optional)
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secretFor production, set up Celery with Redis:
# Start Celery worker
celery -A invoice_generator worker -l info
# Start Celery beat (for scheduled tasks)
celery -A invoice_generator beat -l infoAll API endpoints require JWT authentication except for registration.
# Register a new user
POST /api/register/
{
"email": "user@example.com",
"username": "username",
"password": "password123",
"password2": "password123",
"first_name": "John",
"last_name": "Doe"
}
# Login to get tokens
POST /api/token/
{
"email": "user@example.com",
"password": "password123"
}
# Use the access token in headers
Authorization: Bearer <access_token>POST /api/register/- Register new userPOST /api/token/- Get JWT tokensPOST /api/token/refresh/- Refresh access tokenGET /api/profile/- Get user profilePUT /api/profile/- Update user profilePOST /api/change-password/- Change passwordGET /api/dashboard/- User dashboard with statistics
GET /api/clients/- List clientsPOST /api/clients/- Create clientGET /api/clients/{id}/- Get client detailsPUT /api/clients/{id}/- Update clientDELETE /api/clients/{id}/- Delete client
GET /api/projects/- List projectsPOST /api/projects/- Create projectGET /api/projects/{id}/- Get project detailsPUT /api/projects/{id}/- Update projectDELETE /api/projects/{id}/- Delete projectGET /api/projects/by-client/{client_id}/- Get projects by client
GET /api/time-entries/- List time entriesPOST /api/time-entries/- Create time entryGET /api/time-entries/{id}/- Get time entry detailsPUT /api/time-entries/{id}/- Update time entryDELETE /api/time-entries/{id}/- Delete time entryPOST /api/time-entries/bulk-create/- Bulk create time entriesGET /api/time-entries/by-project/{project_id}/- Get time entries by projectGET /api/time-entries/summary/- Get time entry summary
GET /api/invoices/- List invoicesPOST /api/invoices/- Create invoiceGET /api/invoices/{id}/- Get invoice detailsPUT /api/invoices/{id}/- Update invoiceDELETE /api/invoices/{id}/- Delete invoicePOST /api/invoices/create-from-time-entries/- Create invoice from time entriesPOST /api/invoices/{id}/send/- Send invoice via emailGET /api/invoices/{id}/pdf/- Download invoice PDFPOST /api/invoices/{id}/mark-paid/- Mark invoice as paidGET /api/invoices/summary/- Get invoice summaryGET /api/invoices/overdue/- Get overdue invoices
GET /api/stripe/config/- Get Stripe configurationPOST /api/stripe/create-payment-intent/- Create payment intentPOST /api/stripe/create-checkout-session/- Create checkout sessionGET /api/stripe/payment-intents/- List payment intentsGET /api/stripe/payment-intent-status/{id}/- Get payment intent statusPOST /api/stripe/webhook/- Stripe webhook endpoint
# Create invoice from time entries
POST /api/invoices/create-from-time-entries/
{
"client": 1,
"project": 2,
"start_date": "2024-01-01",
"end_date": "2024-01-31",
"tax_rate": 8.5,
"notes": "January 2024 work"
}# Send invoice via email
POST /api/invoices/1/send/
{
"email_subject": "Invoice for January 2024",
"email_message": "Please find attached invoice for services rendered.",
"send_to_client": true,
"send_copy_to_user": true
}# Create payment intent for invoice
POST /api/stripe/create-payment-intent/
{
"invoice_id": 1
}The application includes several Celery tasks for automation:
- Recurring Invoices: Automatically generate invoices based on client/project settings
- Overdue Reminders: Send reminder emails for overdue invoices
- PDF Generation: Background PDF generation for invoices
- Email Sending: Asynchronous email sending
# Start Celery beat scheduler
celery -A invoice_generator beat -l info
# Start Celery worker
celery -A invoice_generator worker -l infoRun the test suite:
# Run all tests
python manage.py test
# Run specific app tests
python manage.py test clients
python manage.py test invoices- User: Custom user model with freelancer-specific fields
- Client: Client information with recurring invoice settings
- Project: Project management with time tracking
- TimeEntry: Time tracking with billable hours
- Invoice: Invoice generation with PDF support
- InvoiceItem: Line items for invoices
- StripePaymentIntent: Stripe payment processing
- StripeWebhookEvent: Webhook event tracking
- Environment Variables: Set
DEBUG=Falseand configure production settings - Database: Use production PostgreSQL instance
- Static Files: Configure static file serving
- Media Files: Set up media file storage (AWS S3 recommended)
- Email: Configure production email backend
- Stripe: Use production Stripe keys
- SSL: Enable HTTPS
- Monitoring: Set up logging and monitoring
# Build production image
docker build -t invoice-generator:prod .
# Run with production settings
docker run -d \
-e DEBUG=False \
-e DATABASE_URL=postgres://... \
-p 8000:8000 \
invoice-generator:prod- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Check the documentation
- Search existing issues
- Create a new issue with detailed information