Skip to main content

A CLI tool for generating DDD/CQRS microservices applications

Project description

Nagraj

Tests PyPI version codecov License: MIT Python Version

Nagraj is a powerful CLI tool for generating Domain-Driven Design (DDD) and Command Query Responsibility Segregation (CQRS) based microservices applications in Python. It provides a robust project structure with best practices baked in.

Features

  • ๐Ÿ—๏ธ DDD Architecture: Built-in support for DDD patterns including:

    • Aggregates, Entities, Value Objects
    • Domain Events and Event Handlers
    • Repositories and Specifications
    • Domain Services and Facades
  • ๐Ÿ”„ CQRS Pattern: Clear separation of commands and queries with:

    • Command handlers and validators
    • Query handlers and DTOs
    • Event sourcing support
  • ๐Ÿ”’ Authentication & Authorization: Pre-configured auth bounded context with:

    • JWT-based authentication
    • Role-based authorization
    • Password hashing with Argon2
    • User management APIs
  • ๐Ÿ› ๏ธ Modern Tech Stack:

    • FastAPI for high-performance APIs
    • SQLModel for type-safe ORM
    • Pydantic for data validation
    • Alembic for database migrations
    • Poetry for dependency management
  • ๐Ÿงช Testing & Quality:

    • Pytest configuration with async support
    • Hurl for API testing
    • Coverage reporting
    • Ruff for linting and formatting

Installation

pip install nagraj

Quick Start

  1. Create a new project:
nagraj init --project-name my_cool_app
  1. Additional options:
nagraj init \
  --project-name my_cool_app \
  --project-description "My awesome microservice" \
  --project-author-name "John Doe" \
  --project-author-email "john@example.com" \
  --python-version 3.12 \
  --version 0.1.0

Project Structure

The generated project follows a clean DDD/CQRS architecture:

my_cool_app/
โ”œโ”€โ”€ my_cool_app/
โ”‚   โ”œโ”€โ”€ common/
โ”‚   โ”‚   โ”œโ”€โ”€ base/              # Base classes for DDD building blocks
โ”‚   โ”‚   โ”œโ”€โ”€ bounded_contexts/  # Shared bounded contexts (e.g., auth)
โ”‚   โ”‚   โ”œโ”€โ”€ core/             # Core functionality
โ”‚   โ”‚   โ””โ”€โ”€ exceptions/       # Exception hierarchy
โ”‚   โ””โ”€โ”€ example_domain_one/   # Domain-specific code
โ”‚       โ”œโ”€โ”€ bounded_contexts/ # Domain bounded contexts
โ”‚       โ”œโ”€โ”€ context_maps/    # Context mapping
โ”‚       โ””โ”€โ”€ interface/       # Domain interfaces
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ unit/
โ”‚   โ”œโ”€โ”€ integration/
โ”‚   โ””โ”€โ”€ apis/               # API tests using Hurl
โ”œโ”€โ”€ alembic.ini            # Database migration config
โ”œโ”€โ”€ pyproject.toml         # Project dependencies
โ””โ”€โ”€ .nagraj.yaml          # Project configuration

Configuration

The .nagraj.yaml file in your project root contains the complete configuration:

  • Project metadata and versioning
  • Base class configurations
  • Infrastructure settings
  • Common components
  • Domain configurations
  • Testing setup
  • Development tools

Development Workflow

  1. Add a New Domain:

    • Create domain folder structure
    • Define bounded contexts
    • Implement domain models
    • Add API interfaces
  2. Testing:

    # Run all tests
    pytest
    
    # Run API tests
    hurl tests/apis/*.hurl
    
  3. Database Migrations:

    # Create a new migration
    alembic revision --autogenerate -m "description"
    
    # Apply migrations
    alembic upgrade head
    

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Credits

Created and maintained by Abhishek Pathak (@krabhishek)

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

nagraj-0.1.1.tar.gz (52.3 kB view details)

Uploaded Source

Built Distribution

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

nagraj-0.1.1-py3-none-any.whl (131.2 kB view details)

Uploaded Python 3

File details

Details for the file nagraj-0.1.1.tar.gz.

File metadata

  • Download URL: nagraj-0.1.1.tar.gz
  • Upload date:
  • Size: 52.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for nagraj-0.1.1.tar.gz
Algorithm Hash digest
SHA256 47e451c3d9f3f3791b4f585a20fd31ac73073d0766167aa19a7ae0f7ec1e2a69
MD5 aee649836c99c8c4d2bc633d4a0c467d
BLAKE2b-256 2a5e33f81943b81b9d201fd4f549e27dd7c2410bfdf5751f3fefe0d3ae841fc8

See more details on using hashes here.

File details

Details for the file nagraj-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nagraj-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 131.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for nagraj-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c4d9fb5c2d7161d089ab89733e076223e7a92d2276f561fc2400c67a9fa01d5
MD5 8970f6f734eddf33b7e22dadbb1dc7d8
BLAKE2b-256 7d66d8e8bb1941e04a5b34c4b4b9631847ef4dab63ad05be52d888e00cb3af0a

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