|
1 | 1 | # 📂 Folder Structure |
2 | 2 |
|
3 | | -Project based on principle **Feature-based Architecture**, this approach provides reusable and consistant |
4 | | -features across the application. |
| 3 | +Project based on principle **Feature-based Architecture**: each feature owns its UI, routes, models, mappers, services, and store when needed. Shared and core code live outside features. |
5 | 4 |
|
6 | 5 | ```bash |
7 | 6 | 📦 src/ |
8 | | - ├── 📂 features/ # Каталог із функціональними модулями |
9 | | - │ ├── 📂 feature-name/ |
10 | | - │ │ ├── 📂 feature.component.ts/html/scss # Component with template and styles, and base logic file |
11 | | - │ │ ├── 📂 feature-service.ts # Service or Facade to provide data for NGXS |
12 | | - │ │ ├── 📂 feature.store.ts # NGXS Store for feature |
13 | | - │ │ ├── 📂 feature.entitity.ts # Feature Interface for data, Types, Enums |
14 | | - │ │ ├── 📂 feature.guards.ts # Guard's for feature routing and permissions |
15 | | - │ │ ├── 📂 feature.resolvers.ts # Resolvers for data fetching and preloading |
16 | | - │ │ ├── 📂 feature.utils.ts # Additinal utils for feature (formBuilders, converters, mappers) |
17 | | - │ │ ├── feature.module.ts # Optional, if standalone |
18 | | - │ │ ├── feature.routing.ts # Export of standalone components by path |
| 7 | + ├── 📂 app/ |
| 8 | + │ ├── 📂 features/ # Feature modules |
| 9 | + │ │ └── 📂 feature-name/ |
| 10 | + │ │ ├── 📂 components/ # Feature UI pieces |
| 11 | + │ │ ├── 📂 pages/ # Route-level pages (when used) |
| 12 | + │ │ ├── 📂 models/ # Feature-local *.model.ts types |
| 13 | + │ │ ├── 📂 mappers/ # Feature API ↔ domain mappers |
| 14 | + │ │ ├── 📂 services/ # Feature HTTP / facade services |
| 15 | + │ │ ├── 📂 store/ # Feature NGXS state (actions, model, state, selectors) |
| 16 | + │ │ ├── 📂 enums/ # Feature enums |
| 17 | + │ │ ├── 📂 constants/ # Feature constants |
| 18 | + │ │ ├── feature.routes.ts # Feature routes |
| 19 | + │ │ └── feature.component.ts # Feature shell / entry component |
| 20 | + │ │ |
| 21 | + │ ├── 📂 core/ # App-wide infrastructure |
| 22 | + │ │ ├── 📂 components/ # Shell UI (header, banners, …) |
| 23 | + │ │ ├── 📂 services/ # Global services |
| 24 | + │ │ ├── 📂 store/ # Core NGXS state (user, emails, …) |
| 25 | + │ │ ├── 📂 models/ # Core config / routing types |
| 26 | + │ │ ├── 📂 guards/ |
| 27 | + │ │ ├── 📂 interceptors/ |
| 28 | + │ │ ├── 📂 helpers/ |
| 29 | + │ │ └── 📂 provider/ |
| 30 | + │ │ |
| 31 | + │ ├── 📂 shared/ # Cross-feature reusable code |
| 32 | + │ │ ├── 📂 components/ # Shared UI |
| 33 | + │ │ ├── 📂 directives/ |
| 34 | + │ │ ├── 📂 pipes/ |
| 35 | + │ │ ├── 📂 services/ # Shared HTTP / helpers |
| 36 | + │ │ ├── 📂 stores/ # Shared NGXS domains |
| 37 | + │ │ ├── 📂 models/ # Shared domain + JSON:API models |
| 38 | + │ │ ├── 📂 mappers/ # Shared mappers |
| 39 | + │ │ ├── 📂 enums/ |
| 40 | + │ │ ├── 📂 guards/ |
| 41 | + │ │ └── 📂 helpers/ |
| 42 | + │ │ |
| 43 | + │ ├── app.component.ts |
| 44 | + │ ├── app.config.ts |
| 45 | + │ ├── app.config.server.ts # SSR app config |
| 46 | + │ ├── app.routes.ts |
| 47 | + │ └── app.routes.server.ts # SSR routes |
19 | 48 | │ |
20 | | - ├── 📂 core/ # Base module for global services, components, and state |
21 | | - │ ├── 📂 services/ # Global services (API, Auth, LocalStorage) |
22 | | - │ ├── 📂 components/ # Global components (Header, Footer, Sidebar) |
23 | | - │ ├── 📂 store/ # Core state management (Auth, Settings, Router) |
24 | | - │ ├── core.module.ts # Optional, but must have a provider for core. |
25 | | - │ |
26 | | - ├── 📂 shared/ # Shared module for common components, directives, pipes, and services |
27 | | - │ ├── 📂 ui/ # Shared UI components (Button, Input, Modal), or wrappers for 3rd party |
28 | | - │ ├── 📂 directives/ # Shared Directives (ClickOutside, Draggable) |
29 | | - │ ├── 📂 pipes/ # Shared Pipes (Filter, Sort, Format) |
30 | | - │ ├── 📂 services/ # Services, Facades for shared logic (Http, LocalStorage) |
31 | | - │ ├── 📂 store/ # Shared State management (Settings, Theme, Language) |
32 | | - │ |
33 | | - ├── app.routes.ts # General Entry point for routing |
34 | | - ├── main.ts # Providers Setup and Bootstrap |
35 | | - ├── package.json # Dependencies and Scripts |
| 49 | + ├── 📂 assets/ |
| 50 | + ├── 📂 environments/ |
| 51 | + ├── 📂 styles/ |
| 52 | + ├── 📂 testing/ # Test helpers, mocks, builders (@testing/*) |
| 53 | + ├── main.ts # Browser bootstrap |
| 54 | + ├── main.server.ts # SSR bootstrap |
| 55 | + ├── server.ts # Express / SSR server entry |
| 56 | + └── index.html |
| 57 | +``` |
| 58 | + |
| 59 | +--- |
36 | 60 |
|
| 61 | +## 📋 Models and mappers |
| 62 | + |
| 63 | +- Types live in `*.model.ts` files (interfaces/types, not classes). |
| 64 | +- Shared catalog: `shared/models/<domain>/` with optional `*-json-api.model.ts` twins. |
| 65 | +- Feature-local types: `features/<feature>/models/`. |
| 66 | +- Mappers convert JSON:API ↔ domain at the service boundary. |
| 67 | + |
| 68 | +See [Models Conventions](./models.md). |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## 🗃️ State |
| 73 | + |
| 74 | +- Shared domains: `shared/stores/<domain>/` |
| 75 | +- Feature domains: `features/<feature>/store/` |
| 76 | +- Core domains: `core/store/` |
| 77 | + |
| 78 | +See [NGXS State Management](./ngxs.md). |
37 | 79 |
|
38 | 80 | --- |
39 | | -``` |
40 | 81 |
|
41 | 82 | ## 🚀 Dynamic File Generation (Schematics) |
42 | 83 |
|
43 | | -Use Angular CLI to generate new feature components, services, and modules. |
| 84 | +Use Angular CLI for scaffolding: |
44 | 85 |
|
45 | 86 | ```sh |
46 | 87 | ng generate component feature-name/components/new-component |
| 88 | +``` |
47 | 89 |
|
48 | 90 | ### 📌 Other Schematics: |
49 | 91 |
|
50 | | -| **Entity** | **Command** | |
51 | | -|--------------|----------------------------------------------| |
52 | | -| 📌 **Service** | `ng g s feature-name/services/new-service` | |
53 | | -| 📦 **Module** | `ng g m feature-name` | |
54 | | -| 🔐 **Guard** | `ng g g feature-name/guards/auth-guard` | |
55 | | -| 🔄 **Pipe** | `ng g p shared/pipes/currency-format` | |
56 | | -| ✨ **Directive** | `ng g d shared/directives/highlight` | |
57 | | - |
58 | | - |
59 | | -``` |
| 92 | +| **Entity** | **Command** | |
| 93 | +| ---------------- | ------------------------------------------ | |
| 94 | +| 📌 **Service** | `ng g s feature-name/services/new-service` | |
| 95 | +| 🔐 **Guard** | `ng g g feature-name/guards/auth-guard` | |
| 96 | +| 🔄 **Pipe** | `ng g p shared/pipes/currency-format` | |
| 97 | +| ✨ **Directive** | `ng g d shared/directives/highlight` | |
0 commit comments