Skip to content

programmerisaac/project-structure-generator

Repository files navigation

🏗️ Directory Structure Builder

Convert text-based directory structures into actual folders and files instantly!

📦 Files Included

  1. simple_structure_builder.py - Simple, easy-to-use script (recommended)
  2. structure_builder.py - Feature-rich version with advanced parsing
  3. batch_structure_builder.py - Batch processing with templates

🚀 Quick Start

Option 1: Simple Interactive Mode

python simple_structure_builder.py

Then paste your structure and type END:

myproject/
    src/
        main.py
        utils.py
    tests/
        test_main.py
    README.md
END

Option 2: Use Predefined Templates

# List available templates
python batch_structure_builder.py --list-templates

# Create Django SaaS structure
python batch_structure_builder.py --template django-saas

# Create FastAPI structure
python batch_structure_builder.py --template fastapi

Option 3: From File

# Create structure from a text file
python batch_structure_builder.py structure.txt

📝 Input Format Examples

The scripts support multiple format styles:

Style 1: Simple Indentation

myproject/
    app/
        models.py
        views.py
    static/
        css/
            style.css
    README.md

Style 2: Tree-Style (with symbols)

myproject/
├── app/
│   ├── models.py
│   └── views.py
├── static/
│   └── css/
│       └── style.css
└── README.md

Style 3: Comments Supported

myproject/
    app/              # Main application
        models.py     # Database models
        views.py      # Views/controllers
    README.md         # Project documentation

🎯 Features

✅ What It Does

  • Smart Detection: Automatically detects files (with extensions) vs directories
  • Python Support: Auto-creates __init__.py in Python packages
  • Template Content: Adds basic content to common file types
  • Tree Parsing: Handles various tree-drawing formats
  • Preview Mode: Shows what will be created before doing it
  • Batch Creation: Create multiple projects at once
  • Built-in Templates: Django, FastAPI, Flask, React, and more

📄 File Type Detection

Files are detected if they have:

  • Extensions (.py, .js, .html, .css, etc.)
  • Common names: README, LICENSE, Makefile, Dockerfile, manage.py

Everything else is treated as a directory.

📚 Usage Examples

Example 1: Create Django Project Structure

python simple_structure_builder.py

Paste:

myproject/
    manage.py
    requirements.txt
    myproject/
        settings.py
        urls.py
        wsgi.py
    apps/
        core/
            models.py
            views.py
            urls.py
    static/
        css/
        js/
    templates/
END

Example 2: Use Django Template

python batch_structure_builder.py --template django-saas --output ~/projects/myapp

Example 3: Create from Your Structure File

Save this as structure.txt:

onehux-ai/
    manage.py
    requirements.txt
    core/
        models.py
        views.py
        urls.py
        templates/
            core/
                base.html
    accounts/
        models.py
        views.py
    static/
        css/
        js/

Then run:

python batch_structure_builder.py structure.txt

Example 4: Batch Create Multiple Projects

Create batch.txt:

Project1:
    src/
        main.py
    tests/
        test_main.py

Project2:
    app/
        index.js
    public/
        index.html

Run:

python batch_structure_builder.py batch.txt --batch

🛠️ Command Line Options

simple_structure_builder.py

python simple_structure_builder.py
# Interactive mode only

batch_structure_builder.py

# From file
python batch_structure_builder.py structure.txt

# Use template
python batch_structure_builder.py --template django-saas

# Custom output directory
python batch_structure_builder.py --template fastapi --output ~/myproject

# List all templates
python batch_structure_builder.py --list-templates

# Batch mode
python batch_structure_builder.py batch.txt --batch

📋 Available Templates

  • django-basic - Basic Django project
  • django-saas - Full Django SaaS structure (like your onehux-ai)
  • fastapi - FastAPI project with API structure
  • flask - Flask application
  • react - React frontend project
  • python-package - Python package with tests and docs

🎨 Template Content

Files are created with basic content:

File Type Content
.py Empty (ready for code)
.html Basic HTML5 template
.md Markdown heading
.json Empty JSON object
.gitignore Common Python ignores
.env Empty with comment

🔧 As a Python Module

You can also use it programmatically:

from simple_structure_builder import create_from_text

structure = '''
myproject/
    src/
        main.py
    README.md
'''

stats = create_from_text(structure, base_path='./output')
print(f"Created {stats['dirs']} directories and {stats['files']} files")

💡 Tips & Tricks

1. Skip __init__.py Creation

When prompted, answer 'n' to skip automatic __init__.py creation:

❓ Auto-create __init__.py? (y/n): n

2. Preview Before Creating

The script always shows a preview. Review it before confirming!

3. Use Relative or Absolute Paths

# Relative path
python batch_structure_builder.py --template django-saas --output ./myapp

# Absolute path
python batch_structure_builder.py --template django-saas --output ~/projects/myapp

4. Paste from Tree Command

You can paste output directly from the tree command:

tree myexisting project > structure.txt
# Edit structure.txt to remove unwanted files
python batch_structure_builder.py structure.txt

5. Create Your Own Templates

Edit batch_structure_builder.py and add to the TEMPLATES dict:

TEMPLATES = {
    'my-custom-template': '''
    myproject/
        src/
            main.py
        README.md
    ''',
}

🐛 Troubleshooting

Problem: Files created as directories

Solution: Make sure files have extensions (.py, .js, etc.)

Problem: Wrong indentation parsing

Solution: Use consistent indentation (all spaces or all tabs)

Problem: Script doesn't run

Solution: Make sure you have Python 3.6+

python --version
# or
python3 simple_structure_builder.py

Problem: Permission denied

Solution: Run with appropriate permissions or create in a writable directory

📖 Real-World Example

Let's recreate your onehux-ai structure:

python simple_structure_builder.py

Paste the structure from your document and type END. The script will:

  1. Show you a preview
  2. Ask for confirmation
  3. Create all folders and files
  4. Auto-generate __init__.py in Python packages
  5. Show a summary of what was created

🤝 Contributing

Feel free to modify these scripts for your needs! They're designed to be simple and hackable.

📄 License

Free to use and modify!


Made with ❤️ for developers who hate manual folder creation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages