Backend Development Guide
Welcome to the Backend Development Guide for CRADLE. This guide is tailored for backend developers working on our Django-powered API. It provides insights into the projectect structure and architecture of the CRADLE backend, and it explains how to set up and run the application locally.
Getting Started
Follow these steps to get the backend up and running:
Clone the Repository
git clone https://github.com/prodaft/cradle.git cd cradle/backend git submodule update --init --recursiveDatabase Setup Create the PostgreSQL database:
psql -U [your-postgres-username] CREATE DATABASE cradledb;Redis Setup Ensure Redis is installed and running:
# On Ubuntu: sudo apt install redis-server sudo systemctl start redisConfigure Environment Update your environment settings in
cradle/settings.pyto match your local setup. For example:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'cradledb', 'USER': '[your_user]', 'PASSWORD': '[your_password]', 'HOST': 'localhost', 'PORT': '5432', } } CELERY_BROKER_URL = 'redis://localhost:6379/0'Install Dependencies Install dependencies using Pipenv:
pip install pipenv pipenv installRun Migrations Apply database migrations:
pipenv run python manage.py migrateStart Services Launch the Django development server:
pipenv run python manage.py runserverIn a separate terminal, start the Celery worker:
pipenv run celery -A cradle worker -Q email,notes,publish,import -l INFO
Common Commands
# Run tests
pipenv run python manage.py test
# Create new migration
pipenv run python manage.py makemigrations
# Generate API documentation
cd docs && make html
# Monitor Celery tasks with Flower
pipenv run celery -A cradle flowerTroubleshooting
Database Connection Issues
- Ensure PostgreSQL is running.
- Verify the credentials in
settings.pymatch your local configuration.
Celery Task Issues
- Confirm Redis is running.
- Ensure the Celery worker is started.
- Use Flower to monitor task queues.
Topics Covered
This guide includes detailed sections on:
Happy coding and thank you for contributing to the CRADLE backend!