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.
create_module
: Creates a new Django app with complete folder structurecreate_model
: Generates Django models with custom managers and UUID primary keyscreate_serializer
: Creates DRF serializers with proper field configurationcreate_service
: Generates business logic services with transaction supportcreate_factory
: Creates factory_boy factories for testingcreate_views
: Generates DRF ViewSets with full CRUD operations
- 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
- 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
- Direct CLI Commands: Use
django-smartcli
for all operations (recommended) - Django Compatibility: You can also use
python manage.py
if you prefer - Smart Naming: The CLI automatically adds suffixes (e.g.,
Product
becomesProductService
)
pip install django-smartcli
# settings.py
INSTALLED_APPS = [
# ... other apps
'smartcli',
]
# Create a new module with complete structure
django-smartcli create-module users
# Create models, serializers, services (smart naming)
django-smartcli create-model UserProfile users
django-smartcli create-serializer UserProfile users # β UserProfileSerializer
django-smartcli create-service UserProfile users # β UserProfileService
If you prefer, all commands are also available via Django:
python manage.py create_module users
python manage.py create_model UserProfile users
python manage.py create_serializer UserProfileSerializer users
python manage.py create_service UserProfileService users
Creates a complete Django app structure.
django-smartcli create-module <module_name>
Creates a Django model with best practices.
django-smartcli create-model <model_name> <app_name>
Creates a DRF serializer. The CLI automatically adds "Serializer" suffix.
django-smartcli create-serializer <name> <app_name> [--model <model_name>]
# Examples:
django-smartcli create-serializer Product products # β ProductSerializer
django-smartcli create-serializer UserProfile users # β UserProfileSerializer
Creates a business logic service. The CLI automatically adds "Service" suffix.
django-smartcli create-service <name> <app_name>
# Examples:
django-smartcli create-service Product products # β ProductService
django-smartcli create-service UserProfile users # β UserProfileService
Creates a factory_boy factory. The CLI automatically adds "Factory" suffix.
django-smartcli create-factory <name> <app_name>
# Examples:
django-smartcli create-factory Product products # β ProductFactory
django-smartcli create-factory UserProfile users # β UserProfileFactory
Creates a DRF ViewSet. The CLI automatically adds "ViewSet" suffix.
django-smartcli create-views <name> <app_name> [--model <model_name>]
# Examples:
django-smartcli create-views Product products # β ProductViewSet
django-smartcli create-views UserProfile users # β UserProfileViewSet
Runs Django tests with custom filters for organized test execution:
# Run all tests
django-smartcli test
# Run tests by category (only one filter at a time)
django-smartcli test --models # Run only model tests
django-smartcli test --services # Run only service tests
django-smartcli test --serializers # Run only serializer tests
django-smartcli test --views # Run only view tests
Available Test Filters:
--models
: Tests intests/models/
directories--services
: Tests intests/services/
directories--serializers
: Tests intests/serializers/
directories--views
: Tests intests/views/
directories
π‘ Note: You can only use one filter at a time. The command will automatically detect and run tests from the appropriate directories in your Django apps.
π‘ Tip: All these commands are also available with
python manage.py ...
if you prefer the classic Django syntax.
django-smartcli --help
django-smartcli --version
# Create a complete microservice with smart naming
django-smartcli create-module products
django-smartcli create-model Product products
django-smartcli create-serializer Product products # β ProductSerializer
django-smartcli create-service Product products # β ProductService
django-smartcli create-factory Product products # β ProductFactory
django-smartcli create-views Product products # β ProductViewSet
django-smartcli test --models
- Modern Interface: Uses kebab-case commands (e.g.,
create-module
instead ofcreate_module
) - Smart Naming: Automatically adds appropriate suffixes to class names
- 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
- Format: PascalCase (e.g.,
UserProfile
) - File: snake_case (e.g.,
user_profile.py
) - Manager:
<ModelName>Manager
- Format: PascalCase + "Serializer" (e.g.,
UserProfileSerializer
) - File: snake_case + "_serializer" (e.g.,
user_profile_serializer.py
) - CLI Input: Just the base name (e.g.,
UserProfile
βUserProfileSerializer
)
- Format: PascalCase + "Service" (e.g.,
UserProfileService
) - File: snake_case + "_service" (e.g.,
user_profile_service.py
) - CLI Input: Just the base name (e.g.,
UserProfile
βUserProfileService
)
- Format: PascalCase + "Factory" (e.g.,
UserProfileFactory
) - File: snake_case + "_factory" (e.g.,
user_profile_factory.py
) - CLI Input: Just the base name (e.g.,
UserProfile
βUserProfileFactory
)
The library includes comprehensive test templates for all generated components:
# Run all tests
django-smartcli test
# or
python manage.py test
# Run tests by category (only one filter at a time)
django-smartcli test --models # Model tests
django-smartcli test --services # Service tests
django-smartcli test --serializers # Serializer tests
django-smartcli test --views # View tests
# Same with manage.py
python manage.py test --models
python manage.py test --services
python manage.py test --serializers
python manage.py test --views
- Python 3.8+
- Django 4.2+ (including Django 5.2.3)
- Django REST Framework 3.14+
- factory_boy 3.3+
git clone https://github.com/nathanrenard3/django-smartcli.git
cd django-smartcli
pip install -e ".[dev]"
pytest
black smartcli/
flake8 smartcli/
django-smartcli --help
django-smartcli --version
cd your-django-project
django-smartcli create-module test-module
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by modern CLIs like NestJS, AdonisJS, and Laravel
- Built with Django and Django REST Framework
- Uses factory_boy for test factories
- Issues: GitHub Issues
- Documentation: GitHub Wiki
- Discussions: GitHub Discussions