Implement a Core, Features, and Shared project architecture
Split the codebase into three primary directories under src/app to ensure a clear separation of concerns:
- core: Contains global, non-business features and singletons (e.g., authentication services, interceptors, layout components). Avoid importing from the
featuresfolder intocore. - features: Contains business logic grouped by domain. Colocate all files related to a specific feature (components, stores, services) in the same folder. For domains with multiple routes, use a dedicated
<feature>.routes.tsfile. - shared: Contains reusable components, directives, pipes, and models. While features are grouped by domain, shared items can be grouped by technical type (e.g.,
shared/components/). Avoid importing fromcoreorfeaturesintoshared.
<project root>
├── src
│ ├── app
│ │ ├── core
│ │ │ ├── authentication
│ │ │ │ └── authentication.service.ts
│ │ │ ├── layout
│ │ │ │ └── nav-bar
│ │ │ │ └── nav-bar.component.ts
│ │ │ └── interceptors
│ │ │ └── error-handler.interceptor.ts
│ │ ├── features
│ │ │ ├── blog
│ │ │ │ ├── feed
│ │ │ │ │ └── blog-feed.component.ts
│ │ │ │ ├── post
│ │ │ │ │ └── blog-post.component.ts
│ │ │ │ └── blog.routes.ts
│ │ │ └── dashboard
│ │ │ └── dashboard.component.ts
│ │ └── shared
│ │ ├── components
│ │ │ │ └── form
│ │ │ │ └── color-picker
│ │ │ └── confirm-dialog
│ │ │ └── ...
│ │ │ ├── directives
│ │ │ ├── models
│ │ │ └── pipes