Where to put business logic in Django?

At my workplace, Carbon Co-op, we have a 10-month-old Django monolith, which I broke ground on, and so I’ve been looking for other people’s approaches to this too. None of our engineering team (4 people) are super experienced with Django. I’m probably the most experienced and I’ve been working with it for about 2 years.

We’re not a big organisation and part of using a Python/Django/AWS stack is to use battle-tested and well-understood frameworks (basically the opposite of niche). We’re using Django in a very batteries-included way: we use crispy forms to create UIs and all that. So something like your API Domains guide @phalt is really inspiring but it doesn’t really fit for us.

dry-python is also a really interesting project, and it’s cool to see so many concepts from strongly-typed functional languages put into Python. But it’s a radically different way of writing code that isn’t that common in the Python or Django worlds so it’s a hard sell.

So really I’ve been looking for something that implements a “lite” version of clean architecture / hexagonal architecture, that gets you a good amount of the benefits without fundamentally rearchitecting your Django code and thus losing its anti-niche / batteries included status. The best thing I’ve found for this is from Hack Software - first I found their style guide and it turns out they also did a talk at EuroPython about it too. I’d recommend taking a look - the talk is a bit more informative than the styleguide taken by itself.

I imagine this sort of stuff really varies depending on the size, maturity and scale of your organisation, so YMMV - and probably will!

5 Likes