Skip to main content

Overview

The Password Generator backend is built with Django 5.1 and Django REST Framework. It provides JWT authentication, password generation APIs, and user management.

Prerequisites

  • Python 3.10 or higher
  • PostgreSQL database (for production)
  • pip package manager
  • Git

Dependencies

The backend requires the following Python packages:
requirements.txt

Installation

1

Clone the repository

2

Create a virtual environment

3

Install dependencies

4

Configure environment variables

Create a .env file in the backend directory. See the Environment Configuration page for details.
.env

Database Setup

Development (SQLite)

For local development, Django uses SQLite by default:
settings.py

Production (PostgreSQL)

For production, configure PostgreSQL:
1

Install PostgreSQL

2

Create database and user

3

Set DATABASE_URL

Add to your .env file:

Database Migration

1

Run migrations

2

Create a superuser

Follow the prompts to create an admin account.
3

Collect static files

WSGI Configuration

The application uses WSGI for synchronous requests:
backend/wsgi.py

ASGI Configuration

For asynchronous support, the application includes ASGI configuration:
backend/asgi.py

Running the Server

Development Server

The API will be available at http://localhost:8000/api/.

Production with Gunicorn

1

Install Gunicorn

Already included in requirements.txt.
2

Run with Gunicorn (WSGI)

3

Run with Gunicorn (ASGI with Uvicorn workers)

For better async support:

Docker Deployment

The project includes a production-ready Dockerfile:
Dockerfile
1

Build the Docker image

2

Run the container

Fly.io Deployment

The project includes configuration for Fly.io:
fly.toml
1

Install Fly CLI

2

Login to Fly.io

3

Create a Fly.io app

4

Set secrets

5

Create a PostgreSQL database

6

Deploy

The release command will automatically run migrations.

Static Files Configuration

The project uses WhiteNoise for serving static files:
settings.py

Health Checks

Create a health check endpoint for monitoring:
apps/password_generator/views.py
Add to urls.py:

Monitoring and Logging

Configure Logging

Add to settings.py:

Troubleshooting

Database Connection Issues

If you encounter database connection errors:

Static Files Not Loading

CORS Errors

Verify CORS settings in .env:

Security Checklist

  • Set DEBUG=False in production
  • Use a strong, random SECRET_KEY
  • Configure ALLOWED_HOSTS properly
  • Use HTTPS (enable SECURE_SSL_REDIRECT)
  • Set up CORS correctly
  • Use PostgreSQL instead of SQLite
  • Enable database SSL (ssl_require=True)
  • Keep dependencies updated
  • Use environment variables for secrets
  • Set up rate limiting for APIs

Next Steps

Frontend Deployment

Deploy the Next.js frontend

Environment Configuration

Configure environment variables