Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My 3 Angular Rules #2

Open
Zooce opened this issue Sep 3, 2023 · 0 comments
Open

My 3 Angular Rules #2

Zooce opened this issue Sep 3, 2023 · 0 comments

Comments

@Zooce
Copy link
Owner

Zooce commented Sep 3, 2023

Disclaimer: These rules are what I currently believe to be generally applicable to Angular applications today (2023). These are based on my experience over the last year working with a large team on a large Angular application (at a well known global tech company), and are mostly in response to problems I witnessed during the development of this application.

In fairness to myself, even though I've only been working with Angular for about a year, I've been building software for over 10 years in various environments; embedded, mobile, desktop, and now web. This isn't my first "rodeo."

Also, I love building software. I love it. So I put a lot of my energy into deeply thinking through things, actually trying ideas out, being very critical of my own mental models around programming, and adjusting my values as I learn.

With that, take these rules as my personal set of rules. These are the rules that I myself stand by. Obviously, you are free to completely disagree and in any case I appreciate you even taking the time to read these.

Rules

Rule 1

Services should focus on the data while Components should focus on presenting that data.

Why?
The UI is complicated enough. No need to add business logic to that pile.

Rule 2

Services and Components should focus on one reasonable piece of data.

Why?
...Are you really asking? It's much easier to reason about code that focuses on one thing. And for the record, "one" doesn't have to mean that you break everything down into nano pieces - that's not reasonable. Be smart and intentional about choosing your "one" thing.

Rule 3

There are no "smart" or "dumb" Components; all Components do something specific and useful.

Why?
When you try to subcategorize in your architecture you get closer to just adding complexity with little to no value. Again, be reasonable.

Sub-Rules

Sub-Rule 1

Prefer Signals over Observables when applicable.

Why?
Both encourage declarative and (obviously) reactive code, but now that we have Signals the only sensible use for Observables is asynchronous work. Observables can be very complicated even in some simple cases. Signals can be very simple even in some complicated cases. Both are useful; be smart about which one you choose.

Sub-Rule 2

Prefer Standalone over Module-based Components.

Why?
One of the worst things about Angular is the "boilerplatiness" of it. Standalone Components makes this much less of an issue and provides some other benefits, namely the ability for a Component to manage its own dependencies instead of relying on a Module to manage the dependencies of many Components.

@Zooce Zooce changed the title Angular Architecture Angular Architecture Rules Sep 3, 2023
@Zooce Zooce changed the title Angular Architecture Rules My 5 Angular Rules Sep 3, 2023
@Zooce Zooce changed the title My 5 Angular Rules My 4 Angular Rules Sep 3, 2023
@Zooce Zooce changed the title My 4 Angular Rules My 3 Angular Rules Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant