Skip to main content

A smart CLI for Django to help you create and manage microservices with consistent architecture

Project description

Django SmartCLI

A powerful Django command library inspired by modern CLIs like NestJS, AdonisJS, and Laravel. Django SmartCLI automates the creation of Django microservices with a complete and consistent structure.

🚀 Features

Complete Microservice Creation

  • create_module: Creates a new Django app with complete folder structure
  • create_model: Generates Django models with custom managers and UUID primary keys
  • create_serializer: Creates DRF serializers with proper field configuration
  • create_service: Generates business logic services with transaction support
  • create_factory: Creates factory_boy factories for testing
  • create_views: Generates DRF ViewSets with full CRUD operations

Standardized Architecture

  • Consistent folder structure across all modules
  • Automatic __init__.py file management
  • Organized test structure by category (models, serializers, services, views)
  • Automatic integration with Django settings

Best Practices Included

  • UUID primary keys for all models
  • Automatic timestamps (created_at, deleted_at)
  • Soft delete support
  • Custom model managers with useful methods
  • Atomic transactions in services
  • Comprehensive test templates

🎯 Dual Interface

  • Django Management Commands: Traditional python manage.py interface
  • Direct CLI Commands: Modern django-smartcli interface for faster workflow

📦 Installation

pip install django-smartcli

⚡ Quick Start

1. Add to your Django project

# settings.py
INSTALLED_APPS = [
    # ... other apps
    'smartcli',
]

2. Create your first microservice

Option A: Using Django Management Commands (Traditional)

# Create a new module with complete structure
python manage.py create_module users

# Create models, serializers, services
python manage.py create_model UserProfile users
python manage.py create_serializer UserProfileSerializer users
python manage.py create_service UserProfileService users

Option B: Using Direct CLI Commands (Modern)

# Create a new module with complete structure
django-smartcli create-module users

# Create models, serializers, services
django-smartcli create-model UserProfile users
django-smartcli create-serializer UserProfileSerializer users
django-smartcli create-service UserProfileService users

🛠️ Available Commands

create_module / create-module

Creates a complete Django app structure.

# Django management command
python manage.py create_module <module_name>

# Direct CLI command
django-smartcli create-module <module_name>

Features:

  • Creates all necessary directories
  • Generates apps.py and urls.py
  • Automatically adds to INSTALLED_APPS
  • Creates __init__.py files in all directories

create_model / create-model

Creates a Django model with best practices.

# Django management command
python manage.py create_model <model_name> <app_name>

# Direct CLI command
django-smartcli create-model <model_name> <app_name>

Generated Features:

  • UUID primary key
  • Automatic timestamps (created_at, deleted_at)
  • Custom manager with get_active() and get_by_id() methods
  • Soft delete support
  • Automatic factory creation
  • Model tests

create_serializer / create-serializer

Creates a DRF serializer.

# Django management command
python manage.py create_serializer <serializer_name> <app_name> [--model <model_name>]

# Direct CLI command
django-smartcli create-serializer <serializer_name> <app_name> [--model <model_name>]

Features:

  • ModelSerializer with proper field configuration
  • Automatic model detection
  • Read-only fields for timestamps
  • Serializer tests

create_service / create-service

Creates a business logic service.

# Django management command
python manage.py create_service <service_name> <app_name>

# Direct CLI command
django-smartcli create-service <service_name> <app_name>

Features:

  • Class with static methods
  • Atomic transaction support
  • CRUD operation templates
  • Service tests

create_factory / create-factory

Creates a factory_boy factory.

# Django management command
python manage.py create_factory <factory_name> <app_name>

# Direct CLI command
django-smartcli create-factory <factory_name> <app_name>

Features:

  • DjangoModelFactory
  • Automatic timestamp handling
  • Model association

create_views / create-views

Creates a DRF ViewSet.

# Django management command
python manage.py create_views <view_name> <app_name> [--model <model_name>]

# Direct CLI command
django-smartcli create-views <view_name> <app_name> [--model <model_name>]

Features:

  • Complete CRUD operations
  • Permission classes
  • Model, serializer, and service integration
  • View tests

🎯 CLI Interface

Getting Help

# Show all available commands
django-smartcli --help

# Show version information
django-smartcli --version

Command Examples

# Create a complete microservice
django-smartcli create-module products

# Create models
django-smartcli create-model Product products
django-smartcli create-model Category products

# Create serializers
django-smartcli create-serializer ProductSerializer products
django-smartcli create-serializer CategorySerializer products

# Create services
django-smartcli create-service ProductService products
django-smartcli create-service CategoryService products

# Create factories
django-smartcli create-factory ProductFactory products
django-smartcli create-factory CategoryFactory products

# Create views
django-smartcli create-views ProductViewSet products
django-smartcli create-views CategoryViewSet products

CLI Features

  • Modern Interface: Uses kebab-case commands (e.g., create-module instead of create_module)
  • Error Handling: Clear error messages and validation
  • Django Project Detection: Automatically detects if you're in a Django project
  • Help System: Built-in help and version information
  • Cross-Platform: Works on Windows, macOS, and Linux

🎯 Naming Conventions

Models

  • Format: PascalCase (e.g., UserProfile)
  • File: snake_case (e.g., user_profile.py)
  • Manager: <ModelName>Manager

Serializers

  • Format: PascalCase + "Serializer" (e.g., UserProfileSerializer)
  • File: snake_case + "_serializer" (e.g., user_profile_serializer.py)

Services

  • Format: PascalCase + "Service" (e.g., UserProfileService)
  • File: snake_case + "_service" (e.g., user_profile_service.py)
  • Methods: snake_case (e.g., create_user_profile)

Factories

  • Format: PascalCase + "Factory" (e.g., UserProfileFactory)
  • File: snake_case + "_factory" (e.g., user_profile_factory.py)

🧪 Testing

The library includes comprehensive test templates for all generated components:

# Run all tests
python manage.py test

# Run specific test categories
python manage.py test --models
python manage.py test --serializers
python manage.py test --services
python manage.py test --views

📋 Requirements

  • Python 3.8+
  • Django 4.2+
  • Django REST Framework 3.14+
  • factory_boy 3.3+

🔧 Development

Installation for development

git clone https://github.com/nathanrenard3/django-smartcli.git
cd django-smartcli
pip install -e ".[dev]"

Running tests

pytest

Code formatting

black smartcli/
flake8 smartcli/

Testing the CLI

# Test the CLI interface
django-smartcli --help
django-smartcli --version

# Test in a Django project
cd your-django-project
django-smartcli create-module test-module

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by modern CLIs like NestJS, AdonisJS, and Laravel
  • Built with Django and Django REST Framework
  • Uses factory_boy for test factories

📞 Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_smartcli-0.1.0.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_smartcli-0.1.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file django_smartcli-0.1.0.tar.gz.

File metadata

  • Download URL: django_smartcli-0.1.0.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for django_smartcli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d925bc53045fb5e752b4cc763a653fb1509b54d5f2de6139a9a9a52cdd1c5c4
MD5 aef2afc02f247fec5dab20833cc34a10
BLAKE2b-256 d3195102b61ef27a04525edecd855dfafe4d774866707f88970abd899483282f

See more details on using hashes here.

File details

Details for the file django_smartcli-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_smartcli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25977e8ab94faca6ffdf5c7cc2fa1264d21d2dee5631e5215c42c0c2c6588b04
MD5 5730a02e5caa02a003d184f539cd957c
BLAKE2b-256 17d6248362ef60dd1f280e2d411c358981d87b0c71f9e6ebefabfbf68654acc2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page