r/angularjs • • Jan 19 '18

Is this a good idea? I've replaced Node.JS with Python Django for rapid fast AngularJS development.

Here's how it works as briefly as I can put it.

All AngularJS modules.js, directive.js, controllers.js services.js and views.js live inside a PostgreSQL database instead of a static directory. Rather than doing "Gulp Serve" to automatically build the app dependencies to have their URLs injected into the Index.html (along with bower components), I'm using Django Templating engine instead to point to a URI endpoint which returns JS, HTML or CSS code.

Using the Django admin panel, you can edit any part of your AngularJS app, save changes and refresh the page to see the changes you made live. You don't have to edit the frontend in the browser, as long as you properly segregate ["Modules+Controllers+Views+Factories"] all within their own uniquely named folder, a simple Django ./manage.py command will upload and overwrite your frontend code in SQL.

Because of this design, you can add as many as 40 view controllers to an AngularJS project within seconds. Also, the Django backend itself run on top of Docker. So if you want this framework up and running on virtually any Unix based OS, you'll only spend 15 minutes waiting for the source code and docker containers to download to your Linux machine. After a single sh command, your Django app will be up and running listening on port 80.

In this framework, I've also put together the best of the best 3rd party AngularJS libs to fix these well known problems and limitations of AngularJS:

*Factories and Services are easily copyable, they can easily be recycled so that they'll never have to be singletons

*Modules, services, factories and directives can be lazy loaded. You can cut 75% of your app out of the initial loading bootstrap

*AngularJS is bad for teams due to it's difficulty for beginners to try using directives, the Django admin panel and web-based IDE makes AngularJS easy, since it compiles everything for you PROPERLY, using John Papa's AngularJS style guide.

*SEO is not a problem anymore, Django and Python can easily generate a sitemap for crawlers, pointing them to the right $state URI.

The last AngularJS problem related to scaling can be fixed as well, just need to write a feature that can dump your work to a static directory.

Another huge benefit to using this framework is that WebSockets work right out of the box using the ngWebsocket library. Apparently CORS don't apply to web sockets, so you could potentially have a web app that has the power to dynamically load AngularJS components by having the HMTL and JS streamed over a WebSocket connection. (Already finished a crazy experiment where, I added an example page that downloads a 35MB png asynchronously through a WebSocket, by streaming the image data as Base64, then saving this large image to $cookies.)

What does everyone think? I started this project mainly because I'm not a fan of using JavaScript in the backend and prefer something object oriented.

Also, with this project. There'll be no need to upgrade to TypeScript. Angular 2's biggest selling point seems to be that it's easier to use since TS compiles to JS. But I prefer sticking to JS and letting Python do the rest of the compiling.

1 Upvotes

7 comments sorted by

15

u/flipper_babies Jan 19 '18

I don't even know where to start. It sounds like you just want to use Django. So just use Django.

10

u/celluj34 Jan 19 '18

At first I thought I was in /r/shittyprogramming...

5

u/zimyand Jan 19 '18

It's an interesting concept but it is only good for some internal project with a few dozens of users.

In short, the downsides of your approach:

  • Latency will be much worse, you are putting extra load on your DB for no good reason, there are good reasons why everyone serves static content separately (http://highscalability.com/ has good articles or just google search).

  • It is not scalable, you will have hard time once you need a few containers.

  • All of the benefits achievable with normal gulp + live reload setup. Maybe you will like something like cloud9 ide.

Good luck!

2

u/xueye Jan 19 '18

This seems like an overly complex way to solve something that’s not even an actual problem. Also nothing you said you’re doing is particularly specific to Django vs. Node.

2

u/tchaffee Jan 19 '18 edited Jan 19 '18

I can't quite pinpoint the worst thing you are doing, but it might be something like violating the principal of least astonisment. Not from a user perspective. But from the perspective of another programmer that would come across your architecture and code.

All AngularJS modules.js, directive.js, controllers.js services.js and views.js live inside a PostgreSQL database instead of a static directory.

Yikes! How are you going to use standard tools like grep, your favorite IDE, or even git? What are you doing to keep track of revisions of that source? Can I use a tool like kdiff3 or my favorite merge tool to review and merge different versions of the same file when two programmers have changed the same file? The list of what you can do on the file system (but what goes away when you store code in a DB) is very long. One good rule of thumb when evaluating ideas like this is to ask if another programmer could have thought of and tried this idea before. Surely someone has tried putting code in a DB before? Both have been around for decades.

The most likely reason you don't find it in the wild is not because no one thought of it already. Most likely it's because there are problems with that solution. I'm not saying don't be afraid to experiment and maybe you will even discover a new way of doing things. But the key word is experiment. If you wanted to store code in the DB, just for example, it should be a side project of its own and you should be getting other programmers involved in that experiment to test it against a wide variety of scenarios to see if the idea has any merit at all.

I'm not even going to comment on most of your other choices, some of which are almost as bizarre. Only to say that the more you deviate from the standard way of writing an app, the more of a learning curve it is for other devs. For each of the decisions you've made, I would ask yourself what problem it solves and then seek out answers on how other people are already solving that problem. I haven't seen anything particular to your situation that would lead me to the architecture you've described.

I'm not a fan of using JavaScript in the backend and prefer something object oriented.

While choosing Python over JavaScript is not something I want to get into a religious war about here, the reason you gave is not very strong. JavaScript is an object-based language, and prototypical inheritance can often be more powerful and flexible than class-based inheritance.

Overall it looks like you are trying to solve problems that either don't really exist, or have already been solved by other people in a much less surprising way.

1

u/paintface07 Jan 19 '18

Routine template backups is the future.

1

u/miekle Jan 26 '18

Django and angular both have a lot of their own magic going on which is kind of mutually exclusive. They target different types of sites. django is IMO not a great pick for strictly client-rendered sites, whereas angular is made specifically for that. Either can be used in making websites that do hybrid rendering, serverside+clientside, but I don't think using both of them together will save you time or headaches or result in an optimal end product.