API Reference

Custom Scripts in Next-DRF

The Next-DRF framework includes several CLI scripts that streamline common tasks during development and deployment. These scripts are designed to save time by automating routine operations, including managing dependencies, running development servers, building the application, and managing database operations.

Below is an overview of the available custom scripts and examples on how to use them.


1. Development Scripts

1.1 Run Development Environment

  • Script: npm run dev
  • Description: This command runs both the Next.js frontend and the DRF backend simultaneously for development purposes.
  • Usage Example:
    npm run dev
    

1.2 Run Frontend Only

  • Script: npm run dev:frontend
  • Description: Runs only the Next.js frontend for development, useful when working on UI components.
  • Usage Example:
    npm run dev:frontend
    

1.3 Run Backend Only

  • Script: npm run dev:backend
  • Description: Runs only the DRF backend, useful for debugging API endpoints or making backend changes.
  • Usage Example:
    npm run dev:backend
    

2. Database Management Scripts

2.1 Make Migrations

  • Script: npm run dev:makemigrations
  • Description: Creates new Django database migrations based on the changes in the models.
  • Usage Example:
    npm run dev:makemigrations
    

2.2 Apply Migrations

  • Script: npm run dev:migrate
  • Description: Applies all outstanding migrations to the database, updating the schema to match the current models.
  • Usage Example:
    npm run dev:migrate
    

2.3 Create a New Django App

  • Script: npm run startapp
  • Description: Creates a new Django app within the backend to add new features or services.
  • Usage Example:
    npm run startapp my_new_app
    

3. Build and Deployment Scripts

3.1 Build Entire Project

  • Script: npm run build
  • Description: Builds both the frontend and backend for production deployment, optimizing assets and configurations.
  • Usage Example:
    npm run build
    

3.2 Build Frontend Only

  • Script: npm run build:frontend
  • Description: Builds only the Next.js frontend for production deployment.
  • Usage Example:
    npm run build:frontend
    

3.3 Build Backend Static Files

  • Script: npm run build:backend
  • Description: Collects all the static files from the Django backend for deployment.
  • Usage Example:
    npm run build:backend
    

3.4 Run Production Servers

  • Script: npm run start
  • Description: Starts both the frontend and backend in production mode.
  • Usage Example:
    npm run start
    

4. Setup and Installation Scripts

4.1 Setup Backend Dependencies

  • Script: npm run setup:backend
  • Description: Installs the dependencies required for the DRF backend, including Python packages listed in requirements.txt.
  • Usage Example:
    npm run setup:backend
    

5. Available Script List

Below is a complete list of scripts available in the Next-DRF project:

"scripts": {
    "setup:backend": "cd drf-backend && pip install -r requirements.txt",
    "migrate": "node scripts/migrate.mjs",
    "startapp": "node scripts/startapp.mjs",
    "dev": "node scripts/dev.mjs",
    "dev:frontend": "npm run dev --prefix next-frontend",
    "dev:backend": "cd drf-backend && env\Scripts\activate && python manage.py runserver",
    "dev:makemigrations": "cd drf-backend && env\Scripts\activate && python manage.py makemigrations",
    "dev:migrate": "cd drf-backend && env\Scripts\activate && python manage.py migrate",
    "build": "npm run build:frontend && npm run build:backend",
    "build:frontend": "npm run build --prefix next-frontend",
    "build:backend": "cd drf-backend && python manage.py collectstatic --noinput",
    "start": "concurrently \"npm run start:frontend\" \"npm run start:backend\"",
    "start:frontend": "npm run start --prefix next-frontend",
    "start:backend": "cd drf-backend && gunicorn drfBackend.wsgi:application --bind 0.0.0.0:8000"
}

Summary

The Next-DRF framework provides a variety of CLI scripts to help manage both the frontend and backend with ease. These scripts simplify the development and deployment workflow, allowing developers to focus on building features rather than manually executing repetitive commands. From setting up dependencies to running the production server, these scripts make working with Next-DRF efficient and developer-friendly.

Previous
Authentication API