Skip to content

Real-Dev-Squad/todo-backend

Repository files navigation

TODO Backend

Local development setup

  1. Install pyenv
  2. Install the configured python version (3.12.7) using pyenv by running the command
    • For Mac/Linux
      pyenv install
      
    • For Windows
      pyenv install 3.11.5
      
  3. Create virtual environment by running the command
    • For Mac/Linux
      pyenv virtualenv 3.11.5 venv
      
    • For Windows
      python -m pip install virtualenv
      python -m virtualenv venv
      
  4. Activate the virtual environment by running the command
    • For Mac/Linux
      pyenv activate venv
      
    • For Windows
      .\venv\Scripts\activate
      
  5. Install the project dependencies by running the command
    python -m pip install -r requirements.txt
    
  6. Create a .env file for environment variables:
    • Copy the example environment file:
      cp .env.example .env
      
    • Edit the .env file and update the values according to your setup:
      • SECRET_KEY: Generate a unique secret key for Django
      • MONGODB_URI: MongoDB connection string (default: mongodb://localhost:27017)
      • DB_NAME: Your database name
      • GOOGLE_OAUTH_CLIENT_ID and GOOGLE_OAUTH_CLIENT_SECRET: OAuth credentials for Google authentication
      • PRIVATE_KEY and PUBLIC_KEY: Generate RSA key pairs for JWT token signing
      • Other settings can be left as default for local development
  7. Install docker and docker compose
  8. Start MongoDB using docker
    docker compose up -d db
    
  9. Start the development server by running the command
    python manage.py runserver
    
  10. Go to http://127.0.0.1:8000/v1/health API to make sure the server it up. You should see this response
    {
        "status": "UP",
        "components": {
            "db": {
                "status": "UP"
            }
        }
    }
    

To simply try out the app

  1. Install docker and docker compose
  2. Start Django application and MongoDB using docker
    docker compose up -d
    
  3. Go to http://127.0.0.1:8000/v1/health API to make sure the server it up. You should see this response
    {
    "status": "UP"
    }
    
  4. On making changes to code and saving, live reload will work in this case as well

Command reference

  1. To run the tests, run the following command
    python manage.py test
    
  2. To check test coverage, run the following command
    coverage run --source='.' manage.py test
    coverage report
    
  3. To run the formatter
    ruff format
    
  4. To run lint check
    ruff check
    
  5. To fix lint issues
    ruff check --fix
    

Debug Mode with VS Code

Prerequisites

  • VS Code with Python extension installed
  • Docker and docker-compose

Debug Setup

  1. Start the application with debug mode:

    python manage.py runserver_debug 0.0.0.0:8000
    
  2. Available debug options:

    # Basic debug mode (default debug port 5678)
    python manage.py runserver_debug 0.0.0.0:8000
    
    # Custom debug port
    python manage.py runserver_debug 0.0.0.0:8000 --debug-port 5679
    
    # Wait for debugger before starting (useful for debugging startup code)
    python manage.py runserver_debug 0.0.0.0:8000 --wait-for-client
  3. Attach VS Code debugger:

    • Press F5 or go to Run > Start Debugging
    • Select Python: Remote Attach (Django in Docker) from the dropdown
    • Set breakpoints in your Python code
    • Make requests to trigger the breakpoints

Debug Features

  • Debug server port: 5678 (configurable)
  • Path mapping: Local code mapped to container paths
  • Django mode: Special Django debugging features enabled
  • Hot reload: Code changes reflected immediately
  • Variable inspection: Full debugging capabilities in VS Code

Troubleshooting

  • If port 5678 is in use, specify a different port with --debug-port
  • Ensure VS Code Python extension is installed
  • Check that breakpoints are set in the correct files
  • Verify the debug server shows "Debug server listening on port 5678"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 18