# Create a Whole Project Folder Structure from a Python Dictionary

> 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.

URL: https://thuyavan.netlify.app/scripts/project-folder-scaffolder
Updated: 2026-10-07

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

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

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

## 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 flow
Blueprint dict (Dicts = folders, lists = files) -> create_structure() (Recursive, depth-first) -> Path joining (Windows / Linux / macOS) -> Project on disk (exist_ok=True · idempotent)

## 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
- `project_root`: Name of the project folder to create.
- `structure`: The 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
- 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.

## FAQ
**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.

