AI-Augmented Software Engineering - The Series in Practice
Part 7: Development Setup and Initial Application Building
The development environment setup phase is crucial for agile software teams to get started on building high-quality products efficiently. However, this phase can often be tedious and error-prone without proper tools and documentation. LLM powered AI assistants have the potential to significantly improve this process. They can be leveraged to automatically generate documentation artifacts like environment setup guides, dependency diagrams, and configuration recipes. The AI can also provide intelligent feedback and suggestions to engineers when they encounter setup issues. Additionally, managers can utilize the AI to analyze setup processes across teams and identify opportunities for optimization and standardization. With their ability to quickly synthesize information and communicate in natural language, LLM based AI tools can make the development environment setup smooth, organized and productive - enabling teams to focus their efforts on building great products.
Development Environment Setup and Preparations
The development environment setup and preparation phase involves critical steps for engineers to get started building the product. Engineers need to create a code repository, likely on GitHub, and set up their IDEs and other development tools. Core services and frameworks like Django, Docker, Postgres need to be installed and configured. Configuration files enable Django to connect to the SQLite database. Key artifacts that need to be created include the Github repo itself, linter and formatter configs for black, flake8, etc, dependency files like poetry pyproject.toml, and server configuration files. Having these artifacts set up ensures engineers can begin feature development smoothly. Overall, the development environment setup paves the way for agile teams to start delivering business value iteratively.
Intelligent Feedback
We’ve determined we’re going to build the application using Django and Postgres. But what about everything else a developer uses to work on the application? What about choice of IDE, Linters, Formatters, Dev Tools, and Collaboration Tools? We would like to get some feedback about our team’s setup and optimal workflow tools before we begin. We need to find the latest trend and also get some intelligent feedback that’s more complex than a simple search. Let’s use Bing and the Alternative Approaches pattern to find some alternatives for dev setups.
Here is our input prompt:
Give me all of the alternative ways I could develop my Django to-do list application using common development tools. I need alternatives for, but not limited to IDEs, python tools, Django tools, Postgres tools, formatters, linters, command line tools, git tools, and anything else that will speed up development of the application. Describe how each approach works, and list the pros and cons of each solution. After each solution, ask me if I would like to use that solution (yes/no) before continuing on the the next offered solution. Before starting, ask me enough questions to arrive at the best solution.
And here would be the response output of that prompt (image used for brevity and clarity):
Based on your requirements, here are some development tools that you can use to speed up the development of your Django to-do list application:
1. IDEs: PyCharm, Visual Studio Code, Sublime Text, Atom, and Eclipse are some popular IDEs that you can use for developing your Django application. PyCharm is a powerful IDE that offers features such as code completion, debugging, and version control integration. Visual Studio Code is a lightweight and versatile IDE that supports multiple programming languages. Sublime Text is a fast and customizable text editor that supports multiple platforms. Atom is an open-source text editor that is highly customizable and extensible. Eclipse is a popular Java-based IDE that supports multiple programming language.
2. Python tools: Virtualenv, Pipenv, and Anaconda are some popular Python tools that you can use to manage your Python environment. Virtualenv allows you to create isolated Python environments for your projects. Pipenv is a package manager that simplifies dependency management for Python projects. Anaconda is a distribution of Python and R that includes many data science packages.
3. Django tools: Django Debug Toolbar, Django Extensions, and Django REST framework are some popular Django tools that you can use to enhance your Django application. Django Debug Toolbar provides detailed debugging information for your application. Django Extensions provides additional functionality such as management commands and database utilities. Django REST framework allows you to build RESTful APIs for your application.
4. Postgres tools: PgAdmin, DBeaver, and Postico are some popular Postgres tools that you can use to manage your Postgres database. PgAdmin is a web-based administration tool for Postgres databases. DBeaver is a universal database tool that supports multiple databases including Postgres. Postico is a native Mac app for managing Postgres databases.
5. Formatters: Black, YAPF, and Autopep8 are some popular Python code formatters that you can use to format your code according to PEP 8 guidelines.
6. Linters: Flake8, Pylint, and Pyflakes are some popular Python linters that you can use to check your code for errors and enforce coding standards.
7. Command line tools: Git Bash, PowerShell, and iTerm2 are some popular command line tools that you can use to interact with your operating system and run command line scripts.
8. Git tools: GitKraken, Sourcetree, and GitHub Desktop are some popular Git tools that you can use to manage your Git repositories.
These are just a few examples of the many development tools available for Python and Django development. Each tool has its own pros and cons depending on your specific needs.
Would you like me to provide more information about any of these solutions?
After this we asked Bing to provide even more detail, which it did about specific technologies. Based off the response we were given, We’ve chosen using Visual Studio Code as an IDE, Flake8 as a linter, Black as a formatter, A bash script that will launch our Virtualenv, PGAdmin to provide a UI tool for the Postgres database, and a Docker compose setup that will launch Postgres, PGAdmin, and out Django application for testing
Artifacts Created
As mentioned, throughout the process different phases will produce different artifacts and require different intelligent feedback. For the Development setup phase we will essentially be generating either scripts or configurations. So since this is so similar to writing code, we will use the same tool / pattern combination we would if we were writing code: ChatGPT-4 with the code interpreter turned on, and the PQD pattern.
IDE Settings
Description: A Visual Studio Code (VSCode) settings file is a configuration file that allows users to customize and configure the behavior and appearance of the VSCode editor.
Best Tool: ChatGPT-4 Code interpreter
Best Prompt Pattern: PQD
Our Pattern Input:
You are an expert python programmer. You are working on a Django web application with a Postgres backend. You are going to use VSCode as an IDE. You are going to use Flake8 as your linter and Black as your formatter.
Please build a settings.json file that uses these.
Comment each line of code.Include common flake8 and black plugins. Provide a few different solutions and explain the rational behind each.
Our Response Output: Certainly! Here's a settings.json file for VSCode that configures it for Django development with a Postgres backend, while integrating Flake8 as the linter and Black as the formatter.
Solution 1: Basic Setup
{
// Use the Python extension provided by Microsoft for Python development.
"python.pythonPath": "path_to_your_virtualenv", // Specify the path to your virtual environment.
// Use Flake8 for linting Python code.
"python.linting.flake8Enabled": true,
// Use Black for formatting Python code.
"python.formatting.provider": "black",
"python.formatting.blackPath": "path_to_black_executable", // If not in PATH, specify the path to the Black executable.
// Django template support (syntax highlighting and IntelliSense).
"files.associations": {
"**/templates/*.html": "django-html",
"**/templates/*": "django-txt",
"**/requirements{/**,*}.{txt,in}": "pip-requirements"
}
}
Solution 2: Extended Setup with Flake8 and Black Plugins{
// Basic Python and Django setup.
"python.pythonPath": "path_to_your_virtualenv",
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "path_to_black_executable",
"files.associations": {
"**/templates/*.html": "django-html",
"**/templates/*": "django-txt",
"**/requirements{/**,*}.{txt,in}": "pip-requirements"
},
// Additional Flake8 configurations, including some common plugins.
"python.linting.flake8Args": [
"--max-line-length=88", // Matches Black's default line length.
"--select=E,W,F", // Only show errors, warnings, and flake8-flask warnings.
"--ignore=E501,W503", // Commonly ignored Flake8 rules.
"--docstring-convention=google" // Use Google's docstring formatting convention.
],
"python.linting.flake8Plugins": ["flake8-bandit", "flake8-bugbear", "flake8-import-order"],
// Additional Black configurations.
"python.formatting.blackArgs": ["--line-length", "88"], // Matches Black's default line length.
"editor.formatOnSave": true // Automatically format the document upon saving.
}
Rationale:
Solution 1 provides a basic setup that gets a developer started with Django, Flake8, and Black. It's minimalistic and doesn't include any custom configurations or plugins.
Solution 2 is an extended setup. It includes common plugins for Flake8 like flake8-bandit for security checks, flake8-bugbear for additional lint checks, and flake8-import-order for import order checks. The configuration for Flake8 is adjusted to match Black's default line length of 88 characters. Additionally, files are automatically formatted with Black upon saving.
Adjust the paths (path_to_your_virtualenv and path_to_black_executable) to match your actual paths. The configurations provided should help ensure consistency in code quality and style across a team.
Linter / Formatter Config
Description: A .flake8 configuration file is used to define and customize rules for the flake8 tool, which checks Python code for compliance with PEP 8 and other coding standards. In the context of a `pyproject.toml` file, the Black formatter configuration specifies rules and preferences for automatically formatting Python code to adhere to the Black code style. We will supply the settings.json file to ChatGPT-4 code interpreter to help us generate the two configuration files we need.
Best Tool: ChatGPT-4 Code interpreter
Best Prompt Pattern: PQD
Our Pattern Input:
You are an expert python programmer. You are working on a Django web application with a Postgres backend. You have already made a settings.json file that incorporates settings for Flake8 linter and Black formatter.
You will now write 2 files: the .flake8 configuration file for the Flake8 settings and the pyproject.toml file for the Black settings.
Comment each line of code. Use the supplied settings.json file to help you with configuration settings. Make sure you follow modern python and PEP-8 standards. Follow Google python docstring style. Provide a few different solutions and explain the rational behind each. Here is the settings.json file you will work from:(settings.json created in the previous step pasted here)
Our Response Output:
Alright! Let's start by extracting the relevant information from the settings.json file and create the .flake8 and pyproject.toml files.
.flake8 Configuration File
We can create the .flake8 configuration file using the "python.linting.flake8Args" and "python.linting.flake8Plugins" sections of the settings.json.
# .flake8
# Set the maximum allowed line length to 88 characters.
# This matches the default line length used by Black.
max-line-length = 88
# Select which errors, warnings, and flake8-flask warnings to show.
select = E,W,F
# Ignore certain common Flake8 rules.
ignore = E501,W503
# Use Google's docstring formatting convention.
docstring-convention = google
# Plugins to use with Flake8.
# These plugins provide additional checks for potential vulnerabilities (bandit),
# common bugs (bugbear), and import ordering (import-order).
plugins =
flake8-bandit,
flake8-bugbear,
flake8-import-order
pyproject.toml Configuration File
We can set up the pyproject.toml file using the "python.formatting.blackArgs" section from the settings.json.
# pyproject.toml
# Configure Black - The Uncompromising Code Formatter.
[tool.black]
# Set the maximum line length to 88 characters.
# This matches the default line length used by both Black and our Flake8 configuration.
line-length = 88
# Automatically format the document upon saving.
format-on-save = true
Rationale:
1. flake8: This configuration file is for Flake8, which is a linter for Python. It checks your Python code against some style guide. The options set here are mainly based on the given settings.json and make sure the linting is in sync with Black, our formatter.
2. pyproject.toml: This configuration file is for Black, which is a code formatter. The settings we used make sure the code is formatted to a consistent style. The pyproject.toml format is a newer standard for configuration in the Python ecosystem and is widely adopted by modern Python tools.
Using both a linter (Flake8) and a formatter (Black) helps to ensure that the code is not only syntactically correct but also follows a consistent style, making it easier to read and maintain.
Virtualenv Script
Description: Python virtualenv is a tool used to create isolated Python environments, ensuring that a project has its own set of dependencies and won't conflict with system-wide libraries. A bash script to activate a virtual environment in the current directory and install dependencies would look like this:
source ./venv/bin/activate && pip install -r requirements.txt
.
Best Tool: ChatGPT-4 Code interpreter
Best Prompt Pattern: No Pattern even needed. Actually, even asking about that subject would generate a bash script. Since Bash scripts aren’t very logically complex (usually), they are the easiest programmatic thing you can ask an LLM to do. Using AI-powered LLM tools to quickly generate Bash scripts for redundant tasks is an absolute no-brainer for any engineer.
Our Pattern Input:
Write a bash script that would
activate a virtual environment in the current directory and install dependencies from a requirements.txt file
Our Response Output:
source ./venv/bin/activate && pip install -r requirements.txt.
(It doesn’t get any easier than that, does it?)
Docker Compose Configurations
Description: Docker Compose is a tool for defining and running multi-container Docker applications. It uses a configuration file, usually named `docker-compose.yml`, to define and configure the application's services. This setup simplifies local development by allowing developers to run multiple service containers related to their application without installing the services directly on their machines; furthermore, the containers can later be re-deployed to container platforms like Kubernetes or Amazon ECS for production.
Best Tool: ChatGPT-4 Code interpreter
Best Prompt Pattern: PQD
Our Pattern Input: You are an expert full-stack software engineer who knows containerization well. You are working on a Django web application with a Postgres backend. With this application you are also going to use PGAdmin for interfacing with the database.
Create a docker compose .yaml file to start up the Django application called as a service called “todo”, a service for the postgres database and a service for the pgadmin web UI. Create a local network called “todo” for the container services to run on. For the “todo” application, create the corresponding dockerfile that builds the requirements off of a requirements.txt after moving all the necessary files, and sets everything up in the container as you would for a normal containerized Django application.
Comment each line of code. For the Postgres and PGAdmin services just use publicly available images off of Dockerhub. Provide a few different solutions and explain the rational behind each.
Our Response Output:
Let's break this down step by step.
First, we'll create the Docker Compose YAML file (docker-compose.yml):
version: '3.8'
services:
todo: # Django application service
build:
context: .
dockerfile: Dockerfile
volumes:
- ./app:/app
ports:
- "8000:8000"
depends_on:
- db
networks:
- todo_net
db: # Postgres database service
image: postgres:latest
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: todo_db
networks:
- todo_net
pgadmin: # PGAdmin service for interfacing with the database
image: dpage/pgadmin4:latest
environment:
PGADMIN_DEFAULT_EMAIL: admin@todo.com
PGADMIN_DEFAULT_PASSWORD: adminpassword
ports:
- "8080:80"
networks:
- todo_net
networks:
todo_net:
driver: bridge
Here's the breakdown:
todo service is our Django application. It's built using a Dockerfile (which we
ill define next) and connects to the todo_net network. db service uses the official postgres image from DockerHub. pgadmin service uses the dpage/pgadmin4 image for the web UI. Next, let's create a Dockerfile for the todo service
(Dockerfile):
# Use an official Python runtime as the parent image
FROM python:3.8-slim
# Set environment variables for Django
ENV PYTHONUNBUFFERED 1
# Create and set the working directory
WORKDIR /app
# Copy the current directory contents into the container
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Run the command to start the Django development server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Conclusion
In summary, LLM powered AI assistants hold immense potential in improving the development environment setup process for agile teams. Key tools like VSCode, Flake8, and Black enable formatting, linting and streamline the coding workflow. Containerization with Docker and Docker Compose allows for easy deployment across environments. By automating repetitive tasks, generating documentation, and providing intelligent feedback, AI tools can free up precious engineering time to focus on core product development. Moving forward, these AI capabilities are only expected to become more robust and integrated into the software development lifecycle. Organizations that leverage LLMs for environment setup and beyond will gain a competitive advantage in building, deploying and iterating on products efficiently. With the right collaboration between humans and AI, we can transform software development to be more creative, impactful and enjoyable.