Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: What is the "official" standard folder structure?

So I've been looking around to see what the most popular / standard folder structure is for Angular 2 apps and it doesn't seem like there is one. Is there anyone who is using in Angular 2 in production who can shed some light?

Here are some approaches I found:

1) Split by feature, with 1) a shared folder 2) a folder for each feature that contains all the files (whether component, or service, or whatever) directly inside that folder https://angular.io/docs/ts/latest/guide/style-guide.html#!#application-structure enter image description here

2) Angular 1 style (no nesting or separation by features, just components, pipes, services, models) enter image description here

For #1 would it feels weird not having a subfolder for components, subfolder for services, etc. Where would I put a service being used across all the routes?

BTW I'm using the Angular CLI generator: https://github.com/angular/angular-cli

like image 918
bigpotato Avatar asked Apr 24 '26 06:04

bigpotato


1 Answers

The style guide provides lots of does and don'ts about how to structure your app https://angular.io/styleguide

It says to maintain a flat hierarchy with a folder per feature and related files (component, template, style, ...) in the same folder.

like image 93
Günter Zöchbauer Avatar answered Apr 26 '26 20:04

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!