A sample project for the Software-Design Lab. Python is widely used and approachable. The project uses Django and provides a basic setup and structure as a starting point for own implementations.
Find a file
2025-12-19 15:29:12 +01:00
.vscode feat: added debug option 2025-08-14 14:38:21 +02:00
containers chore: minor corrections and documentation 2025-08-18 11:05:22 +02:00
core feat: simplify the logic and remove core.models, core.services. 2025-10-18 10:48:24 +02:00
customers chore: Comments, unused imports 2025-11-21 19:21:05 +01:00
orders feat: add model-tests for orders 2025-12-05 14:27:36 +01:00
products doc: added link to django models as a comment 2025-11-22 11:59:40 +01:00
static feat: simplify the logic and remove core.models, core.services. 2025-10-18 10:48:24 +02:00
swd_django_demo feat: simplify the logic and remove core.models, core.services. 2025-10-18 10:48:24 +02:00
.dockerignore feat: add container support via compose 2025-08-17 18:19:55 +02:00
.env_example chore: minor corrections and documentation 2025-08-18 11:05:22 +02:00
.gitignore chore: minor corrections and documentation 2025-08-18 11:05:22 +02:00
.python-version feat: use uv, version bump, minor refactorings 2025-08-12 14:00:00 +02:00
CLAUDE.md feat(AI): project information for Claude Code. 2025-10-17 19:49:21 +02:00
cli.ps1 feat(cli): add command adminuser 2025-09-10 21:26:02 +02:00
django_lasagne_overview.svg doc: add layered design picture. 2025-10-30 19:05:48 +01:00
generate_diagrams_py2puml.py feat: add class-diagram generation scripts 2025-12-19 15:29:12 +01:00
generate_diagrams_pyreverse.py feat: add class-diagram generation scripts 2025-12-19 15:29:12 +01:00
LICENSE chore: License file and Readme updates 2025-08-18 11:29:00 +02:00
manage.py Initial commit 2023-05-09 14:18:15 +02:00
pyproject.toml feat: add class-diagram generation scripts 2025-12-19 15:29:12 +01:00
README.md doc: correct the windows venv activation info. 2025-11-22 12:13:15 +01:00
uv.lock feat: add class-diagram generation scripts 2025-12-19 15:29:12 +01:00

Software Design Python - Django Demo

The project can be used as a reference for the SWD lab course and shows an example python project using Django as the web-development framework.

This project consists of several apps with a focus on loose coupling and dependency injection. A good article about separation of concerns in Django projects can be found https://emcarrio.medium.com/business-logic-in-a-django-project-a25abc64718c. Good Django tutorials can be found https://www.djangoproject.com/start/ or https://cs50.harvard.edu/web/2020/weeks/3/.

1. Requirements

1.1 Shell for CLI workflow

Software development needs to interact with the system. Therefor we will encounter an number of CLI (command line interface) tools. To do this effectively we need to use a shell.

In a Unix-like environments like Mac/Linux typically a good shell is available out of the box (bash, zsh) in combination with a terminal (terminal, iTerm, Konsole, gnome-terminal, ...).

For Windows a good combination of shell/terminal is PowerShell/Windows Terminal.

Tip

Powershell: For windows users it is quite helpful to set the execution-policy for powershell:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Tip

Windows NOTE: When you want to execute python in a shell and the Windows App-Store opens, you need to deactivate this Windows-Behavior: https://stackoverflow.com/questions/58754860/cmd-opens-windows-store-when-i-type-python

1.2 Python

What is python?

Note

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. (https://www.python.org/doc/essays/blurb/)

For this example the most recent python version is used https://peps.python.org/pep-0719/

  • python 3.13.x

To install python itself and as a python package manager we are using the tool uv - 'An extremely fast Python package and project manager, written in Rust.'

2. Development

Best practice for any python development is to start with a virtual environment. This approach and workflow is already integrated into uv - Project Environment

Note

You benefit from the virtual environment since packages can be installed confidently and will not interfere with another projects environment.

2.1 Usage

  1. Install dependencies with the projects main directory: uv sync.
  2. Activate the virtual environment: Mac/Linux source .venv/bin/activate / Windows (powershell) ./.venv/Scripts/activate.ps1
  3. Create the database tables: uv run python manage.py migrate
  4. Create an admin user: uv run python manage.py createsuperuser
  5. Run unit tests: uv run python manage.py test -v 2
  6. Run the development server: uv run python manage.py runserver.
  7. Open the website in your browser: http://localhost:8000/admin, http://localhost:8000/products.

Or if you want to start with a fresh Django project from scratch:

  1. Initialize a new project: uv init --python 3.13.
  2. Add Django: uv add Django
  3. Install dependencies with the projects main directory: uv sync.
  4. Activate the virtual environment: source .venv/bin/activate / ./.venv/bin/activate.ps1
  5. Create a new Django project: uv run django-admin startproject django_project .
  6. Add Django applications: uv run manage.py startapp app_name

Tip

Windows: A realtime virus scanning engine like Windows Defender sometimes gets in the way during development. As a result common development actions (compilation, execution of scripts, ..) take ages. To speed up the process it can make sense to disable realtime-scanning during compilation or exclude paths in the scan engine (be aware that this has a security impact!)

2.2 IDE

There are a number of IDEs available for python development. You can choose between different variants like VSCode, PyCharm, VIM, ...

2.2.1 VSCode

This repository uses VSCode mainly. It also provides recommendations for extensions which can be installed to have a good development experience (.vscode/extensions.json). Unit-testing works and is configured in .vscode/settings.json as well as launch/debug capabilities of the Django application in .vscode/launch.json.

2.3 Dependency Injection

A very often used concept in software-design is dependency injection (or inversion of control). A very, very good intro-video regarding DI (dependency injection) can be found on youtube, "Dependency Injection, The Best Pattern". For Django projectsinitialization code is needed to work with the package dependency-injector --> https://python-dependency-injector.ets-labs.org/examples/django.html

3. Software-Design

The application implements a layerd design with models > services > views (sometimes call "Lasagne Architecture" when the layering goes too far 😅).

layered design