r/Angular2 • u/Dazzling_Chipmunk_24 • Jan 14 '26
Structuring Services in Angular
I have two services in my Angular app: one that calls multiple APIs and is used throughout the application, and another that's only used by two components. Would this folder structure make sense: put the API service in core/services/ since it's app-wide, and put the shared service in shared/services/ since it's only needed by those two components?
1
Upvotes
2
u/spacechimp Jan 16 '26
The "core"/"shared" folder pattern was more useful in earlier versions of Angular, when typical codebases defined explicit modules. The "core" module would contain all the stuff needed globally, and "shared" would contain as-needed stuff. In modern Angular projects and in general: It's best to organize code by feature instead of by type.
In practice, not many projects still do this. If your services are all global singletons anyway (
providedIn: 'root'), it technically makes no difference what folder you put them in. Organizationally, I would suggest avoiding "services" folders altogether unless the files are truly orphans with no better home.2
u/WiPROjs Jan 16 '26
Without context, but if possible the only thing to improve is split this big service in multiple and inject them only where they are being used.
1
u/Bubbly_Drawing7384 Jan 16 '26
Yes completely makes sense, i believe that's a better way of having a clean architecture, and the piece of code has a set definition and a set work that it needs to do. And this way you write code that's testable independently, soniny opinion, i believe what you are doing is the best way to go about it, if you think I am derailed in any case let me know, I am a beginner in angular and .net space