1/15/2025 at 5:47:07 PM
This is an excellent article, and SaaS Pegasus is a great solution for people starting a project.But some of the advice here is dated. The architectural patterns are still valid, but the specifics have changed:
* Vite instead of create-react-app (which is unmaintained now) / webpack / babel / Parcel / etc.
* Django-ninja as a lightweight API service.
I think these are important to call out because they really simplify the frontend compared to the previous options.
by nilsbunger
1/15/2025 at 10:52:19 PM
I agree with you on Django Ninja, so refreshingly simple compared to DRF. I think Django core needs to adopt something like it.However, Vite is pretty complicated. I prefer just esbuild if I don't need all the extra features of Vite, which is usually true with Django. I wrote a post[0] with an example repo[1] if anyone wants to see how everything wires up.
With Solidjs, the minimum JS payload is around 9kb, and you get access to the whole JS ecosystem if you want it.
[0] https://blopker.com/writing/07-django-islands-part-1/ [1] https://github.com/blopker/typesafedjango
by blopker
1/16/2025 at 12:59:00 AM
> I agree with you on Django Ninja, so refreshingly simple compared to DRF. I think Django core needs to adopt something like it.I was going to ask about this with respect to DRF, but you answered it. I am re-learning Django after having been away from it and Python for ~4 years now, and my previous experience was with DRF in a somewhat toxic group so I had less than ideal feelings about it. I know PTSD is a real thing and I don't mean to sound glib about it, but I think I actually had the beginnings of it from that experience.
by michaelcampbell
1/15/2025 at 6:39:31 PM
What seems to differentiate django-ninja over Flask or FastAPI or any Starlette derivative? You mention lightweight as well, can you expand further?by bkovacev
1/15/2025 at 7:20:14 PM
Ninja lets you use django. There's less config vs DRFby nprateem
1/15/2025 at 7:36:14 PM
Aside from the obvious that ninja let's you use django.by bkovacev
1/15/2025 at 10:51:31 PM
The ability to use django is the main attractor. The other frameworks are great but make you reinvent Django if you require auth, orm, admin, etcby WD-42
1/16/2025 at 1:01:52 PM
That would have been my argument exactly - I am not saying that Django fits every use case, but with my limited exposure to projects that have ended up using non-Django Python API framework, they ended up recreating the batteries included approach, with probably way too many issues waiting to be discovered with manually rolled out auth, middlewares and ORM.by bkovacev
1/16/2025 at 2:06:38 PM
It's such a shame Pyramid isn't more popular. I think you'll find what they have recreated is not Django, it's Pyramid.The thing is, Django isn't just a web framework. Django is a CRUD app framework. It's great for building CRUD apps, but that's about it. In other words, it makes the easy stuff easy, but doesn't help with the hard stuff (in fact, it often hinders it).
I think the real reason for using Django is the "app" ecosystem. You wouldn't be able to get Django-style packages with Pyramid. It's possible with Django, though, because it's a CRUD app framework.
If you're not using "apps" then I guess the only other reason is the community support that you probably won't get from Pyramid + SQLAlchemy or similar.
by globular-toast
1/16/2025 at 3:00:49 PM
The apps are a major sell like with any ecosystem. But don't forget you also get a stable, mature project, excellent documentation, a pool of developers, etc.by nprateem
1/17/2025 at 10:02:01 AM
> But don't forget you also get a stable, mature project, excellent documentation, a pool of developers, etc.You get all of that with any of Pyramid, Flask, FastAPI etc.
As for "pool of developers", I would expect any backend web developer to be able to pick up anything in a couple of days at most.
by globular-toast
1/16/2025 at 7:45:30 AM
Oh but you wouldn't reinvent Django, you'd build a properly architected, simple system.by globular-toast
1/16/2025 at 8:18:54 AM
Of course you would.by WD-42
1/16/2025 at 12:13:26 PM
Adding to the pile that agrees with you on django-ninja.It's also worth noting that what Django brings to the table is getting less and less relevant in a world where frontend and backend are split.
For example, we use django-ninja. As we started using it, we migrated away from allauth and into authlib for authentication, which doesn't have a tie-in to Django.
We don't use templates, which means we don't use forms. We're moving away from external django apps because they consistently need to be extended, so we tend to copy the code into our codebase and extend directly.
The settings are untyped, which is a PITA; so we replaced them with pydantic-settings: That allows us to use .env files, type them, and we just expose them in settings.py into globals() through a couple lines of code.
Our management scripts make more sense as poetry script, so we don't go through manage.py but instead `poetry run <command>`, which is more standardized and doesn't depend on Django.
We don't even use the django dev server: In order to be more consistent between production and development, we're using uvicorn in "development" mode as a dev server which works just as well. `poetry run dev` is how we run it.
So what does that leave us with?
1. An ORM/data model definition system, which is mostly untyped and the source of many of our issues. This model system also contains weird quirks that have nothing to do with the sql model itself (for example you can't create a UUID field whose default is generated by the db; only in python). This also includes a pretty solid migrations system. 2. The great admin dashboard, which depends on the former.
I see the way the wind is blowing. And for #1, we have this now, which we haven't tested yet but makes complete sense: https://sqlmodel.tiangolo.com/
We still need migrations and and admin dashboard. Once we have those, we will likely migrate away from Django entirely and our stack will look like a few prepackaged bits of FastAPI, SQLModel, authlib, and maybe some standardized db tables.
by scrollaway
1/16/2025 at 2:51:49 PM
So you’re living out the trope of reinventing Django but lower quality :-)Maybe ask around about SQLModel. It sounds like the perfect solution, but I’ve never encountered someone that used it and didn’t have the opinion that it isn’t ready for production.
by halfcat
1/16/2025 at 8:44:17 PM
Why lower quality?Django suffers a lot from having packaged into itself the whole templating and forms systems. It solved a pain point years ago, but it's irrelevant now and it carries that legacy due to backwards compatibility.
Furthermore, Django also suffers due to its legacy of being database-agnostic... which was more relevant in a world where mysql was still seen as a serious competitor to postgres; but now, it's more annoying than anything else.
by scrollaway
1/17/2025 at 4:10:38 AM
Backward compatibility is great. Your team needs to learn one thing, and it will work with minor modifications and get security updates until after you’ve retired.SQLModel uses SQLAlchemy, which is database-agnostic. Not sure why this is a problem though. The benefit of the ORM is not being agnostic, it’s in managing schema changes under source control and automatic admin interface.
In my experience, the FastAPI-grab-bag always ends in regret, wishing we’d just used Django. It just works, and it has things you don’t even know you’ll need. If you get to the point where Django is the problem, you’re still glad you picked Django because you’ll be able to modify it to suit your needs. It brings convention without being enforced, and it’s pluggable. You can just not use forms (I never have), or templates (I like htpy), or not use the ORM, or use a different ORM. Django is just a request-response handler that’s already thought of everything you might need. If you want the FastAPI/pydantic approach you can use Django-ninja.
You can piece together your own car, but you’ll get a lot further if you just pick a Toyota Land Cruiser and drive it for a couple decades.
by halfcat
1/17/2025 at 12:58:35 PM
Being database-agnostic is not a problem per se. SQLAlchemy provides highly postgres-specific classes for the databases. The way Django implemented database-agnosticism is bad, because it's lowest-common-denominator which dragged all implementations down with it. They are pulling back from that now with a contrib.postgresql module but it's too late, there's a lot of old cruft now that forced design to be less-than-optimal on postgres.I've done all four approaches on four different startups. Pure Django; DRF+React; FastAPI+React; Django-Ninja+React. The last one is the best, but from my experience, it does seem like SQLModel/FastAPI/React will be the route to go towards, but with some solid libraries to replace the still-useful batteries in Django: Authentication, Administration, Migration.
by scrollaway
1/16/2025 at 4:21:06 AM
I use both at work. I'm not sure I see any reason why you would use Vite over Webpack, other then a sense that Vite is newer. Is there a reason? They both seem perfectly fine but Webpack is mature with lots of support.by Capricorn2481
1/16/2025 at 8:49:54 AM
All the different configuration you need for Webpack is built-in to Vite. This includes built-in support for a lot of stuff that would come as separate plugins in Webpack (CSS loading, Typescript support, asset bundling, minification, autoprefix/browserslist-based downleveling, env replacement, etc). But more importantly, it includes fairly optimal configuration.There's usually an optimal way to bundle your code, and one of the issues with Webpack was that finding that optimal way through a maze of documentation and third-party plugins. Vite does that work for you, because it's mostly a solved problem and it's not that hard. For example, rather than having a number of different CSS plugins that you need to enable and disable in different configurations — just use Vite, which will do hot-reloading of CSS in development and link to the CSS files as external files in production.
In my experience, there are typically two types of Webpack configurations: fairly basic ones that include some essentials but are fairly unoptimised (either while developing or in production), or complex ones that include everything but are brittle and painful to update. Vite gives you the power and optimisation of the latter with the configuration ease of the former.
Also, to be clear, I'm not trying to hype Vite up. There are other similar tools out there, and Vite isn't even the first tool to work like this — Parcel is older and also pretty good at doing zero/minimal-config builds that work how you expect out-of-the-box. Any of these tools are good, although Vite seems to be the most popular right now and so has the most support/documentation/information. But I would generally encourage any project using Webpack to migrate away from that where possible (and where time allows), because these low-config tools are such a timesaver in the long-run.
by MrJohz
1/16/2025 at 10:36:57 AM
> All the different configuration you need for Webpack is built-in to Vite. This includes built-in support for a lot of stuff that would come as separate plugins in Webpack (CSS loading, Typescript support, asset bundling, minification, autoprefix/browserslist-based downleveling, env replacement, etc). But more importantly, it includes fairly optimal configuration.We're just walking around in circles. Webpack originally came to be because the current (at the time) solutions were too opionated, and what was "fairly optimal configuration" changed so quickly that it seemed favorable to split out the parts that could change, so we could still use webpack but the specific areas within could move forward without waiting for the rest.
Of course this time, we really have found the optimal-optimal configuration that will surely never be updated, because this time we really did it properly.
> Also, to be clear, I'm not trying to hype Vite up.
If your comment contains all praise for a tool without bringing up any of the tradeoffs/drawbacks, then that pretty much labels your comment as "hype" for that particular tool. And if you find that you cannot find any of the tradeoffs/drawbacks, then it's clear as day that you've fully drank the koolaid :)
by diggan
1/16/2025 at 12:18:57 PM
Yes, exactly. It's not about popular use cases that make webpack better. The best way to claim that some other tool is better would be to have a side by side comparison of some not so straight forward configs.by veidelis
1/16/2025 at 9:37:09 AM
You must work on small projects or use top tier hardware exclusively because the development startup time of vite vs webpack is simply not comparable. The project I spend most of my time on maintained both build systems for a couple of years, and I used them interchangeably: under Webpack, the development build loaded in about two minutes (sometimes more), vite takes 3-5 seconds. Webpack configs have since been removed.I also agree with everything MrJohz said about zero (or close to zero) configuration required to use vite.
by homebrewer
1/16/2025 at 10:38:56 AM
> under Webpack, the development build loaded in about two minutes (sometimes more), vite takes 3-5 seconds.Now it was some time ago since I last used webpack, but if it takes 2 minutes for your build to load (or run?), something is severely wrong and it's not because of webpack.
Migrating your build tool because you're hitting some edge-case or bug you don't understand doesn't bode well for your future use of other tools.
by diggan
1/16/2025 at 1:17:29 PM
> Migrating your build tool because you're hitting some edge-case or bug you don't understand doesn't bode well for your future use of other tools.I suppose the patronizing attitude is the price for you sharing your wisdom with us.
FWIW I will also echo that webpack is very slow for me. For my current project, the initial build times were ~10 minutes and eventually balooned to 15+ after which I switched to rspack (~10seconds build times now). This comes with some caveats like I had ts typechecking vs swc (but I have ts watching separately, and it takes longer than rspack but is still around ~20s). For webpack 4, speed-measure-plugin used to work well (a long time ago I remember sass-loader being a bad bottleneck), but for v5 I've spent a decent amount of time trying to figure out issues, and it wasn't a simple process. The stats.json that gets generated was malformed for me, and I had to either modify it by hand, and even then it was pretty opaque. And I wasn't about to dive into profiling the node runtime to sort out the webpack issue because that time would be better spent on something like optimizing the chunks.
And I was using webpack because while the inital build times were slow, the incremental builds were really fast. Vite is horribly slow on refresh if there are a lot of files.
by preommr
1/16/2025 at 1:25:41 PM
> I suppose the patronizing attitude is the price for you sharing your wisdom with us.Beats passive aggressiveness I suppose?
> FWIW I will also echo that webpack is very slow for me.
Judging by your description, and surely missing even more context, it sounds like individual loaders/modules are/were slow, rather than webpack itself. But since you switched webpack for rspack (with assuming, the very same loaders/modules) and it got faster, that would seem webpack being the slow part, so who knows what the core problem is/was.
Personally I haven't hit any performance issues with webpack + lots of code, but then I mainly do JavaScript and try to stay away from TypeScript, maybe this could explain the difference in experience.
In the end, we use the tools that work best, and if that happen to be Vite instead of webpack (or vice-versa) for you, then there isn't really much to discuss :)
by diggan
1/16/2025 at 2:02:22 PM
> like individual loaders/modules are/were slow, rather than webpack itselftbh this is just nitpicking, I'm not a react developer to do CRA debugging for them. They're paid by Facebook a couple orders of magnitude more than what we're making here, and if they're fine with the intact CRA configuration being that slow, while a third-party alternative rips through the massive pile of shit I'm working on while not bringing any obvious downsides, I'll just switch to the alternative.
It's a well known problem: esbuild, which is the base of vite's HMR, boasts of speeds dozens to hundreds of times faster than webpack:
by homebrewer
1/16/2025 at 12:12:01 PM
Thank you, well said. I'd like to add that one should try to understand (not saying Homebrewer didnt) what was the cause/bottleneck. Such general statements about "performance" are of little value without deeper insights about some particular problem or use case.by veidelis
1/16/2025 at 1:40:43 PM
I don't think so, it's just a massive intranet project with tons of third-party dependencies¹ that spews out a 20 MB minified JS build. I don't think we even modified the original CRA configuration. No typechecking, no eslint or anything else during the build process, they were all run separately when they were needed.1: like support for various file formats that are constantly needed by every user and it makes no sense to lazy load them
by homebrewer
1/16/2025 at 5:44:28 AM
Isn't Vite faster and less complex? That's my impression.by hu3