markdown

Project: My Django E-commerce Platform

Workflow Definition Goal

The goal of this prompt is to establish a clear, end-to-end development and deployment workflow for a Django project using a modern, declarative toolchain. The workflow must cover local development environment setup, code quality checks, testing, and deployment automation to a live server.

Technologies and Tools

  • Operating System (Local/Dev): NixOS with Nix flakes (for reproducible environments)
  • Environment Management: direnv (automatic environment loading)
  • Package Management (Python): uv (for lightning-fast dependency management and isolation)
  • Configuration File: pyproject.toml (central source of truth for dependencies and tool configs)
  • Python/Django Versions: Python 3.12+, Django 5.0+, Django REST Framework, Django Ninja, Django Oscar, Django Waffle, Django CRM, Django Allauth, Django Haystack with Whoosh.
  • Code Quality Tools:
    • ruff (linter)
    • ruff-format (formatter)
    • djlint (Django template linter/formatter)
  • Version Control Integration:
    • pre-commit hooks (enforce quality locally)
    • coderabbit (AI-powered code review assistant for GitHub)
  • CI/CD (Deployment):
    • GitHub Actions (.github/workflows/deploy.yml)
    • Deployment target: Linode VPS (Ubuntu)
    • Server stack: Apache2 and uWSGI
    • Deployment script: project_manager.sh project_name deploy

Workflow Stages

1. Local Environment Setup (Nix + direnv)

  • Define the structure for flake.nix and flake.lock to create a reproducible development shell.
  • The nix develop shell must provide all necessary system dependencies (e.g., Python interpreter, database libraries) and integrate with direnv.
  • When a developer enters the project directory, direnv should automatically load the Nix-defined environment.
  • Use uv within this environment to manage the Python dependencies specified in pyproject.toml.

2. Dependency Management and pyproject.toml

  • All project dependencies (production, development, testing) are managed exclusively in pyproject.toml.
  • The workflow requires generating a locked requirements.txt file specifically for the deployment phase using uv pip freeze (or similar uv command) based on the pyproject.toml definition. This file must be fresh for every deployment.

3. Local Code Quality and Testing

  • Configure pre-commit to run automatically before every commit.
  • The hooks must execute:
    • ruff (linting)
    • ruff-format (code formatting)
    • djlint (template linting)
  • Define how Django unit tests are run locally using manage.py test and specify that tests must pass before a pull request can be merged.

4. Continuous Integration (CI) and Code Review

  • Describe the use of coderabbit to automatically review code quality and adherence to standards in GitHub pull requests.
  • The CI pipeline should mirror the local quality checks (ruff, djlint, tests).

5. Deployment Process (GitHub Actions to Linode VPS)

  • The deploy.yml GitHub Actions workflow is triggered on pushes to the main branch.
  • The workflow steps must include:
    1. Checkout the repo.
    2. Set up the Nix environment (if running in self-hosted runner, otherwise just run commands).
    3. Generate the fresh requirements.txt using uv.
    4. SSH into the Linode Ubuntu VPS.
    5. Execute the remote deployment script: ./project_manager.sh project_name deploy.
  • The deployment script handles environment synchronization (e.g., pip install -r requirements.txt), static file collection, database migrations, and restarting the uwsgi service via systemctl.

Prompt to the AI Assistant

"Based on the 'Workflow Definition Goal' and 'Technologies and Tools' provided above, generate a detailed, step-by-step guide and accompanying configuration file snippets for a developer to implement this exact workflow. The response should provide:

  1. flake.nix and direnv configuration examples.
  2. A robust pyproject.toml template including all specified dependencies and tool configurations (ruff, djlint).
  3. A .pre-commit-config.yaml file.
  4. The structure for the .github/workflows/deploy.yml GitHub Actions file.
  5. A high-level outline of the project_manager.sh deployment script logic.

The instructions must be clear, actionable, and prioritize the use of uv and nix as the foundational environment tools."