Python · Boilerplate Automation

Create a Whole Project Folder Structure from a Python Dictionary

TL;DR

Define your folders and files as a nested dictionary in folders.py, run it, and the whole project skeleton appears on disk - safe to re-run because nothing is overwritten.

Updated 1 min read

Pythonos.makedirsClean ArchitectureDDD

Abstract

The problem

Starting a project means manually creating dozens of nested folders and __init__.py files, which leads to inconsistent naming across projects.

The solution

A recursive engine that translates a high-level dictionary blueprint into a real directory tree on disk.

The result

Instant, error-free initialisation that keeps every new app on the same architectural standard.

Input & Output

Input
  • structure dictionary and project_root name inside folders.py
Output
  • A new project folder with the full hierarchy of directories and empty files
Optional output
  • Automatic __init__.py package markers for immediate importability

System Diagram

How It Works

Dictionary-defined

Nested dicts are sub-directories, lists are files, empty strings are root files.

Recursive creation

Depth-first traversal with OS-independent path handling.

Idempotent

exist_ok=True means re-runs never error or overwrite.

Clean Architecture template

src/core, src/domain, src/data and src/ui are pre-configured.

Configuration

OptionPurpose
project_rootName of the project folder to create.
structureThe blueprint dictionary – edit it to change the layout.

How to Run

Customise the blueprint
structure = {"api": ["routes.py", "models.py"], "docs": {"manual": ["install.md"]}, "config.yaml": ""}
Run it
python folders.py

Impact & Benefits

Idea to a structured codebase in under 5 seconds.
Identical folder layout across every microservice or app.
Learning aid that shows juniors a physical architecture template.

Screenshots

1/3 The single scaffolding script
2/3 Running the scaffolder
3/3 The generated project skeleton

Frequently Asked Questions

How do I create nested folders in Python from a dictionary?

A recursive create_structure() function walks the dict: nested dicts become folders, lists become files, empty strings become root files.

Will running it twice overwrite my files?

No. It uses exist_ok=True, so existing folders are left alone.

Does it support Clean Architecture?

The default blueprint includes src/core, src/domain, src/data and src/ui following Clean Architecture and DDD.

Related

© 2026 Thuyavan Sivarasa. Script code is MIT licensed.