Skip to content

🧠 Neuroglia Python Framework¢

Keywords: Python microservices, FastAPI framework, clean architecture Python, CQRS Python, domain-driven design Python, event-driven architecture, dependency injection Python, microservices patterns


⚠️ Documentation Philosophy & Critical Disclaimer¢

Eventual Accuracy & Critical Interpretation Required

This documentation is designed as an entry point for both human developers and AI agents, serving as a conceptual toolbox rather than prescriptive instructions.

🎯 Intended Interpretation¢

  • Eventual Accuracy: Content and illustrations represent patterns and concepts that evolve with real-world usage. Expect refinement over time.
  • No One-Size-Fits-All: These are patterns, not prescriptions. Your domain, constraints, and business context will require critical adaptation.
  • Toolbox Approach: Consider this a collection of architectural tools and techniques. Select, combine, and adapt based on your specific use case.
  • Critical Mindset Required: You must evaluate each pattern's applicability to your context. What works for a banking system may be overkill for a simple API.

πŸ—οΈ Clean Architecture Starts with Business ModelingΒΆ

Before writing code, proper clean architecture requires:

  1. Business Domain Understanding: Map your business processes, entities, and rules
  2. Ecosystem Perspective: Identify how your microservice(s) interact within the broader system
  3. Event-Driven Thinking: Consider autonomous services that emit and subscribe to persisted, queryable streams of CloudEvents
  4. Bounded Contexts: Define clear boundaries for your domain models and services
  5. Integration Patterns: Plan for eventual consistency, event sourcing, saga patterns, or CQRS based on actual requirements

The framework provides the mechanisms (CQRS, event sourcing, repositories, mediators), but you provide the domain insight to know when and how to apply them.

πŸ€– For AI AgentsΒΆ

This documentation is structured to enable AI-assisted development. Use it to:

  • Understand architectural patterns and their trade-offs
  • Generate code that respects clean architecture principles
  • Suggest implementations based on documented patterns
  • Critically evaluate when patterns should (or should not) be applied
  • Adapt examples to specific business domains and constraints

Remember: Even with AI assistance, human domain expertise and critical evaluation remain essential.


A lightweight, opinionated Python framework built on FastAPI that enforces clean architecture principles and provides comprehensive tooling for building production-ready microservices.

🎯 Perfect For¢

  • Microservices: Clean architecture for scalable service development
  • Event-Driven Systems: Built-in CloudEvents and domain event support
  • API Development: FastAPI-based with automatic OpenAPI documentation
  • Domain-Driven Design: Enforce DDD patterns and bounded contexts
  • Clean Code: Opinionated structure that promotes maintainable code

πŸš€ Quick Start OptionsΒΆ

πŸ“¦ Starter App Repository - Clone a production-ready template and start building immediately:

git clone https://github.com/bvandewe/starter-app.git my-project
cd my-project
# Follow the setup instructions in the repo

What's Included:

  • βœ… SubApp Architecture - REST API + Frontend separation
  • βœ… OAuth2/OIDC with RBAC - Complete authentication and authorization
  • βœ… Clean Architecture - DDD and CQRS patterns implemented
  • βœ… Modular Frontend - Vanilla JS/SASS/ES6 with modern tooling
  • βœ… OpenTelemetry - Automatic instrumentation for observability
  • βœ… Docker Compose - Ready for local development
  • βœ… Production Patterns - All common concerns pre-configured

Perfect for: Starting a new project with best practices baked in.


🎯 Option 2: Learn from Samples¢

Explore complete, production-ready sample applications to understand specific patterns.


🎯 Option 3: Build from Scratch¢

Follow the Getting Started Guide to understand every concept step-by-step.


πŸš€ What's IncludedΒΆ

πŸ—οΈ Framework CoreΒΆ

Clean architecture patterns with dependency injection, CQRS, event-driven design, and comprehensive testing utilities.

πŸ“¦ Production-Ready Sample ApplicationsΒΆ

Learn by example with complete, runnable applications:

  • 🏦 OpenBank - Event Sourcing & CQRS banking system demonstrating:

  • Complete event sourcing with KurrentDB (EventStoreDB)

  • CQRS with separate write and read models
  • Domain-driven design with rich aggregates
  • Read model reconciliation and eventual consistency
  • Snapshot strategy for performance
  • Perfect for financial systems and audit-critical applications

  • 🎨 Simple UI - SubApp pattern with JWT authentication showing:

  • FastAPI SubApp mounting for UI/API separation

  • Stateless JWT authentication architecture
  • Role-based access control (RBAC) at application layer
  • Bootstrap 5 frontend with Parcel bundler
  • Perfect for internal dashboards and admin tools

  • πŸ• Mario's Pizzeria - Complete e-commerce platform featuring:

  • Order management and kitchen workflows
  • Real-time event-driven processes
  • Keycloak authentication integration
  • MongoDB persistence with domain events
  • Perfect for learning all framework patterns

οΏ½πŸ• Real-World SamplesΒΆ

Complete production examples like Mario's Pizzeria demonstrating every framework feature in realistic business scenarios.

πŸ“š Comprehensive DocumentationΒΆ

βš™οΈ CLI ToolingΒΆ

PyNeuroctl command-line interface for managing, testing, and deploying your applications with zero configuration.


Why Neuroglia?ΒΆ

Choose Neuroglia for complex, domain-driven microservices that need to be maintained for years to come.

🎯 The Philosophy¢

Neuroglia believes that software architecture matters more than speed of initial development. While you can build APIs quickly with vanilla FastAPI or Django, Neuroglia is designed for applications that will:

  • Scale in complexity over time with changing business requirements
  • Be maintained by teams with varying levels of domain expertise
  • Evolve and adapt without accumulating technical debt
  • Integrate seamlessly with complex enterprise ecosystems

πŸ—οΈ When to Choose NeurogliaΒΆ

Choose Neuroglia When Choose Alternatives When
βœ… Building domain-rich applications with complex business logic ❌ Creating simple CRUD APIs or prototypes
βœ… Long-term maintenance is a primary concern ❌ You need something working "yesterday"
βœ… Your team values architectural consistency ❌ Framework learning curve is a blocker
βœ… You need enterprise patterns (CQRS, DDD, Event Sourcing) ❌ Simple request-response patterns suffice
βœ… Multiple developers will work on the codebase ❌ Solo development or small, simple projects
βœ… Integration with event-driven architectures ❌ Monolithic, database-first applications

πŸš€ The Neuroglia AdvantageΒΆ

Compared to vanilla FastAPI:

  • Enforced Structure: No more "how should I organize this?" - clear architectural layers
  • Built-in Patterns: CQRS, dependency injection, and event handling out of the box
  • Enterprise Ready: Designed for complex domains, not just API endpoints

Compared to Django:

  • Microservice Native: Built for distributed systems, not monolithic web apps
  • Domain-Driven: Business logic lives in the domain layer, not mixed with web concerns
  • Modern Async: Full async support without retrofitting legacy patterns

Compared to Spring Boot (Java):

  • Python Simplicity: All the enterprise patterns without Java's verbosity
  • Lightweight: No heavy application server - just the patterns you need
  • Developer Experience: Pythonic APIs with comprehensive tooling

πŸ’‘ Real-World ScenariosΒΆ

Perfect for:

  • 🏦 Financial Services: Complex domain rules, audit trails, event sourcing
  • πŸ₯ Healthcare Systems: HIPAA compliance, complex workflows, integration needs
  • 🏭 Manufacturing: Resource management, real-time monitoring, process orchestration
  • πŸ›’ E-commerce Platforms: Order processing, inventory management, payment flows
  • 🎯 SaaS Products: Multi-tenant architectures, feature flags, usage analytics

Not ideal for:

  • πŸ“ Simple content management systems
  • πŸ”— Basic API proxies or data transformation services
  • πŸ“± Mobile app backends with minimal business logic
  • πŸ§ͺ Proof-of-concept or throwaway prototypes

🎨 The Developer Experience¢

Neuroglia optimizes for code that tells a story:

# Your business logic is clear and testable
class PlaceOrderHandler(CommandHandler[PlaceOrderCommand, OperationResult[OrderDto]]):
    async def handle_async(self, command: PlaceOrderCommand) -> OperationResult[OrderDto]:
        # Domain logic is explicit and isolated
        order = Order(command.customer_id, command.items)
        await self.repository.save_async(order)
        return self.created(self.mapper.map(order, OrderDto))

# Infrastructure concerns are separated
class OrdersController(ControllerBase):
    @post("/orders", response_model=OrderDto)
    async def place_order(self, command: PlaceOrderCommand) -> OrderDto:
        return await self.mediator.execute_async(command)

The result? Code that's easy to understand, test, and evolve - even years later.

πŸš€ Key FeaturesΒΆ

  • πŸ—οΈ Clean Architecture: Enforces separation of concerns with clearly defined layers (API, Application, Domain, Integration)
  • πŸ’‰ Dependency Injection: Lightweight container with automatic service discovery and registration
  • 🎯 CQRS & Mediation: Command Query Responsibility Segregation with built-in mediator pattern
  • πŸ›οΈ State-Based Persistence: Alternative to event sourcing with automatic domain event dispatching
  • πŸ”§ Pipeline Behaviors: Cross-cutting concerns like validation, caching, and transactions
  • πŸ“‘ Event-Driven Architecture: Native support for CloudEvents, event sourcing, and reactive programming
  • 🎯 Resource Oriented Architecture: Declarative resource management with watchers, controllers, and reconciliation loops
  • πŸ”Œ MVC Controllers: Class-based API controllers with automatic discovery and OpenAPI generation
  • πŸ—„οΈ Repository Pattern: Flexible data access layer with support for MongoDB, Event Store, and in-memory repositories
  • πŸ“Š Object Mapping: Bidirectional mapping between domain models and DTOs
  • ⚑ Reactive Programming: Built-in support for RxPy and asynchronous event handling
  • πŸ”§ 12-Factor Compliance: Implements all 12-Factor App principles
  • πŸ“ Rich Serialization: JSON serialization with advanced features

🎯 Architecture Overview¢

Neuroglia promotes a clean, layered architecture that separates concerns and makes your code more maintainable:

src/
β”œβ”€β”€ api/           # 🌐 API Layer (Controllers, DTOs, Routes)
β”œβ”€β”€ application/   # πŸ’Ό Application Layer (Commands, Queries, Handlers, Services)
β”œβ”€β”€ domain/        # πŸ›οΈ Domain Layer (Entities, Value Objects, Business Rules)
└── integration/   # πŸ”Œ Integration Layer (External APIs, Repositories, Infrastructure)

πŸš€ Quick StartΒΆ

Coming soon: Get started with Neuroglia in minutes:

# Install the framework
pip install neuroglia-python

# Create your first app
pyneuroctl new myapp --template minimal
cd myapp

# Run the application
python main.py

Visit http://localhost:8000/docs to explore the auto-generated API documentation.

πŸ“š Learn MoreΒΆ

πŸŽ“ Learning PathsΒΆ

New to the Framework?

  1. Start with Getting Started - Build your first app in 30 minutes
  2. Follow the 9-Part Tutorial Series - Comprehensive hands-on guide
  3. Study Core Concepts - Understand the architectural patterns

Ready to Build?

  1. Explore Mario's Pizzeria Case Study - Complete real-world example
  2. Review Architectural Patterns - Design patterns with anti-patterns to avoid
  3. Browse Framework Features - Detailed feature documentation

Need Help?

  1. Check Guides & How-Tos - Practical procedures and troubleshooting
  2. See Sample Applications - More complete working examples
  3. Consult Reference Documentation - Technical specifications

πŸ“– Reference DocumentationΒΆ


Neuroglia Python Framework - Building better software through better architecture 🧠✨