Skip to content

Commit 554c386

Browse files
committed
feat: modularized routing and configuration in frontend
1 parent 090fdd6 commit 554c386

40 files changed

+1224
-132
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Configuration Architecture
2+
3+
This document outlines the new modular configuration architecture for the Industry Core Hub Frontend.
4+
5+
## Overview
6+
7+
The configuration is now organized based on usage patterns:
8+
9+
- **Shared Configuration**: Used by multiple features or the base application
10+
- **Feature-Specific Configuration**: Used by only one feature
11+
12+
## Configuration Structure
13+
14+
```
15+
src/
16+
├── config/ # Shared configuration
17+
│ ├── index.ts # Main config exports
18+
│ ├── types.ts # Shared types and interfaces
19+
│ └── base.ts # Base application configuration
20+
└── features/
21+
├── part-discovery/
22+
│ └── config.ts # Part discovery specific config
23+
├── catalog-management/
24+
│ └── config.ts # Catalog management specific config
25+
├── partner-management/
26+
│ └── config.ts # Partner management specific config
27+
└── serialized-parts/
28+
└── config.ts # Serialized parts specific config
29+
```
30+
31+
## Shared Configuration (`src/config/`)
32+
33+
### Base Configuration (`base.ts`)
34+
- Application-wide settings
35+
- API base URL
36+
- Participant ID
37+
- Security configuration
38+
- Common utilities
39+
40+
### Types (`types.ts`)
41+
- Shared interfaces and types
42+
- Re-exports from EnvironmentService
43+
- Base configuration interfaces
44+
45+
## Feature-Specific Configuration
46+
47+
Each feature module now contains its own `config.ts` file with:
48+
49+
### API Configuration
50+
- Feature-specific endpoints
51+
- URL builders
52+
- Request/response configurations
53+
54+
### Validation Rules
55+
- Form validation patterns
56+
- Business rules
57+
- Data constraints
58+
59+
### UI Configuration
60+
- Table settings (page sizes, columns)
61+
- Form configurations
62+
- Component-specific settings
63+
64+
### Feature-Specific Policies
65+
- Governance policies (Part Discovery)
66+
- DTR policies (Part Discovery)
67+
- Feature flags
68+
69+
## Examples
70+
71+
### Using Shared Configuration
72+
```typescript
73+
import { baseConfig, configUtils } from '../../config';
74+
75+
// Get base API URL
76+
const apiUrl = baseConfig.apiUrl;
77+
78+
// Build full URL
79+
const fullUrl = configUtils.buildApiUrl('/my-endpoint');
80+
81+
// Check feature flag
82+
const isEnabled = configUtils.isFeatureEnabled('myFeature');
83+
```
84+
85+
### Using Feature Configuration
86+
```typescript
87+
import { partDiscoveryConfig } from './config';
88+
89+
// Get feature-specific endpoint
90+
const url = partDiscoveryConfig.api.buildUrl('CATALOG_PART_MANAGEMENT');
91+
92+
// Get governance policies
93+
const policies = partDiscoveryConfig.governance.getDtrPoliciesConfig();
94+
95+
// Get pagination settings
96+
const pageSize = partDiscoveryConfig.pagination.defaultPageSize;
97+
```
98+
99+
## Migration Benefits
100+
101+
1. **Modularity**: Each feature owns its configuration
102+
2. **Maintainability**: Easier to find and update feature-specific settings
103+
3. **Reusability**: Shared configuration prevents duplication
104+
4. **Type Safety**: Better TypeScript support with typed configurations
105+
5. **Performance**: Only load configuration needed by active features
106+
107+
## Configuration Guidelines
108+
109+
### When to Use Shared Configuration
110+
- Settings used by 2+ features
111+
- Application-wide defaults
112+
- Core infrastructure configuration
113+
- Common utilities and helpers
114+
115+
### When to Use Feature Configuration
116+
- Settings specific to one feature
117+
- Feature-specific validation rules
118+
- Component-specific configurations
119+
- Feature flags and toggles
120+
121+
### Adding New Configuration
122+
123+
1. **For shared settings**: Add to `src/config/base.ts`
124+
2. **For feature settings**: Add to `src/features/{feature}/config.ts`
125+
3. **Update exports**: Ensure proper exports in index files
126+
4. **Document**: Update this file with new configuration options
127+
128+
## Environment Variables
129+
130+
Environment variables are still centralized in `EnvironmentService.ts` but are now consumed through the configuration modules:
131+
132+
- `VITE_ICHUB_BACKEND_URL``baseConfig.apiUrl`
133+
- `VITE_PARTICIPANT_ID``baseConfig.participantId`
134+
- `VITE_GOVERNANCE_CONFIG``partDiscoveryConfig.governance`
135+
- Feature flags: `VITE_FEATURE_{NAME}_ENABLED`
136+
137+
This approach maintains backward compatibility while providing a cleaner, more organized configuration architecture.

ichub-frontend/src/config/base.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/********************************************************************************
2+
* Eclipse Tractus-X - Industry Core Hub Frontend
3+
*
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
5+
*
6+
* See the NOTICE file(s) distributed with this work for additional
7+
* information regarding copyright ownership.
8+
*
9+
* This program and the accompanying materials are made available under the
10+
* terms of the Apache License, Version 2.0 which is available at
11+
* https://www.apache.org/licenses/LICENSE-2.0.
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
16+
* either express or implied. See the
17+
* License for the specific language govern in permissions and limitations
18+
* under the License.
19+
*
20+
* SPDX-License-Identifier: Apache-2.0
21+
********************************************************************************/
22+
23+
import { getIchubBackendUrl, getParticipantId } from '../services/EnvironmentService';
24+
import { BaseConfig, ApiEndpoints } from './types';
25+
26+
/**
27+
* Base application configuration used across all features
28+
*/
29+
export const baseConfig: BaseConfig = {
30+
apiUrl: getIchubBackendUrl(),
31+
participantId: getParticipantId(),
32+
};
33+
34+
/**
35+
* Shared API endpoints used by multiple features
36+
*/
37+
export const sharedApiEndpoints: ApiEndpoints = {
38+
// Base paths used by multiple features
39+
BASE_API: '/api/v1',
40+
HEALTH: '/health',
41+
AUTH: '/auth',
42+
};
43+
44+
/**
45+
* CORS and security configuration
46+
*/
47+
export const securityConfig = {
48+
requireHttps: () => {
49+
try {
50+
return import.meta.env.VITE_REQUIRE_HTTPS_URL_PATTERN !== 'false';
51+
} catch {
52+
return true; // Default to secure
53+
}
54+
},
55+
};
56+
57+
/**
58+
* Common configuration utilities
59+
*/
60+
export const configUtils = {
61+
/**
62+
* Build full API URL
63+
*/
64+
buildApiUrl: (endpoint: string): string => {
65+
return `${baseConfig.apiUrl}${endpoint}`;
66+
},
67+
68+
/**
69+
* Check if feature is enabled
70+
*/
71+
isFeatureEnabled: (feature: string): boolean => {
72+
const envVar = `VITE_FEATURE_${feature.toUpperCase()}_ENABLED`;
73+
return import.meta.env[envVar] !== 'false';
74+
},
75+
};

ichub-frontend/src/config/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/********************************************************************************
2+
* Eclipse Tractus-X - Industry Core Hub Frontend
3+
*
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
5+
*
6+
* See the NOTICE file(s) distributed with this work for additional
7+
* information regarding copyright ownership.
8+
*
9+
* This program and the accompanying materials are made available under the
10+
* terms of the Apache License, Version 2.0 which is available at
11+
* https://www.apache.org/licenses/LICENSE-2.0.
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
16+
* either express or implied. See the
17+
* License for the specific language govern in permissions and limitations
18+
* under the License.
19+
*
20+
* SPDX-License-Identifier: Apache-2.0
21+
********************************************************************************/
22+
23+
// Export all configuration modules
24+
export * from './types';
25+
export * from './base';
26+
27+
// Feature-specific configurations are exported from their respective features
28+
// e.g., import { catalogManagementConfig } from '../features/catalog-management';

ichub-frontend/src/config/types.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/********************************************************************************
2+
* Eclipse Tractus-X - Industry Core Hub Frontend
3+
*
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
5+
*
6+
* See the NOTICE file(s) distributed with this work for additional
7+
* information regarding copyright ownership.
8+
*
9+
* This program and the accompanying materials are made available under the
10+
* terms of the Apache License, Version 2.0 which is available at
11+
* https://www.apache.org/licenses/LICENSE-2.0.
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
16+
* either express or implied. See the
17+
* License for the specific language govern in permissions and limitations
18+
* under the License.
19+
*
20+
* SPDX-License-Identifier: Apache-2.0
21+
********************************************************************************/
22+
23+
/**
24+
* Base configuration types and interfaces used across the application
25+
*/
26+
27+
export interface BaseConfig {
28+
apiUrl: string;
29+
participantId: string;
30+
}
31+
32+
export interface ApiEndpoints {
33+
[key: string]: string;
34+
}
35+
36+
export interface FeatureFlags {
37+
[feature: string]: boolean;
38+
}
39+
40+
// Re-export shared configuration types
41+
export * from '../services/EnvironmentService';

ichub-frontend/src/features/catalog-management/api.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ import axios from 'axios';
2424
import { getIchubBackendUrl } from '../../services/EnvironmentService';
2525
import { ApiPartData } from '../../types/product';
2626
import { CatalogPartTwinCreateType, TwinReadType } from '../../types/twin';
27+
import { catalogManagementConfig } from './config';
2728

28-
const CATALOG_PART_MANAGEMENT_BASE_PATH = '/part-management/catalog-part';
29-
const SHARE_CATALOG_PART_BASE_PATH = '/share/catalog-part';
30-
const TWIN_MANAGEMENT_BASE_PATH = '/twin-management/catalog-part-twin';
3129
const backendUrl = getIchubBackendUrl();
3230

3331
export const fetchCatalogParts = async (): Promise<ApiPartData[]> => {
34-
const response = await axios.get<ApiPartData[]>(`${backendUrl}${CATALOG_PART_MANAGEMENT_BASE_PATH}`);
32+
const response = await axios.get<ApiPartData[]>(`${backendUrl}${catalogManagementConfig.api.endpoints.CATALOG_PARTS}`);
3533
return response.data;
3634
};
3735

@@ -40,7 +38,7 @@ export const fetchCatalogPart = async (
4038
manufacturerPartId: string
4139
): Promise<ApiPartData> => {
4240
const response = await axios.get<ApiPartData>(
43-
`${backendUrl}${CATALOG_PART_MANAGEMENT_BASE_PATH}/${manufacturerId}/${manufacturerPartId}`
41+
`${backendUrl}${catalogManagementConfig.api.endpoints.CATALOG_PARTS}/${manufacturerId}/${manufacturerPartId}`
4442
);
4543
return response.data;
4644
};
@@ -64,7 +62,7 @@ export const shareCatalogPart = async (
6462
};
6563

6664
const response = await axios.post<ApiPartData>(
67-
`${backendUrl}${SHARE_CATALOG_PART_BASE_PATH}`,
65+
`${backendUrl}${catalogManagementConfig.api.endpoints.SHARE_CATALOG_PART}`,
6866
requestBody
6967
);
7068
return response.data;
@@ -74,7 +72,7 @@ export const registerCatalogPartTwin = async (
7472
twinData: CatalogPartTwinCreateType
7573
): Promise<TwinReadType> => {
7674
const response = await axios.post<TwinReadType>(
77-
`${backendUrl}${TWIN_MANAGEMENT_BASE_PATH}`,
75+
`${backendUrl}${catalogManagementConfig.api.endpoints.TWIN_MANAGEMENT}`,
7876
twinData
7977
);
8078
return response.data;

0 commit comments

Comments
 (0)