@plyaz/core 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +30 -293
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -36,316 +36,47 @@ import { createLogger } from '@plyaz/logger';
36
36
  │ │ ├── asset/ # Digital asset models and economics
37
37
  │ │ ├── transaction/ # Transaction domain and validation
38
38
  │ │ └── community/ # Community governance and interaction
39
+ │ │ └── featureFlags/ # Domain logic feature flag system
39
40
  │ ├── engine/ # Core computational engines
40
41
  │ │ ├── calculation/ # Mathematical computation algorithms
41
42
  │ │ ├── incentive/ # Reward and incentive systems
42
43
  │ │ ├── validation/ # Business rule validation engines
43
44
  │ │ └── insights/ # Data analysis and pattern recognition
44
- ├── feature-flags/ # Complete feature flag system
45
+ │ └── featureFlags/ # Egnine feature flag system
45
46
  │ ├── frontend/ # Frontend-specific implementations
47
+ │ │ └── featureFlags/ # Frontend hooks, providers of feature flag system
46
48
  │ ├── backend/ # Backend-specific implementations
49
+ │ │ └── featureFlags/ # Backend service, module, controller, repository of feature flag system. Generally in NestJs, but should be compatible without NestJs.
47
50
  │ ├── sdk/ # B2B SDK foundation
48
51
  │ └── contracts/ # External service contracts
49
52
  ```
50
53
 
51
- ## 🚀 Feature Flag System
54
+ ## 🚀 Currently Available Features
52
55
 
53
- The feature flag system is currently the most mature component of `@plyaz/core`:
56
+ ### Feature Flag System
57
+ - **Providers**: Memory (implemented), Redis/API/Database/File (stubs)
58
+ - **Frontend**: React hooks and context providers
59
+ - **Backend**: NestJS module with service, controller, and repository
60
+ - **Engine**: Rule-based evaluation with targeting and rollouts
61
+ - **Testing**: Override capabilities for test scenarios
54
62
 
55
- ### Backend Integration (NestJS)
63
+ ### Cache System
64
+ - **Strategies**: Memory with LRU eviction (implemented), Redis (stub)
65
+ - **Features**: TTL management, statistics, automatic cleanup
66
+ - **Integration**: Used internally by feature flag system
56
67
 
57
- ```typescript
58
- // app.module.ts
59
- import { FeatureFlagModule } from '@plyaz/core/backend';
60
-
61
- @Module({
62
- imports: [
63
- FeatureFlagModule.forRoot({
64
- provider: 'redis',
65
- isCacheEnabled: true,
66
- cacheTtl: 600,
67
- redisConfig: { url: 'redis://localhost:6379' }
68
- })
69
- ],
70
- })
71
- export class AppModule {}
72
-
73
- // my.service.ts
74
- import { FeatureFlagService } from '@plyaz/core/backend';
75
-
76
- @Injectable()
77
- export class MyService {
78
- constructor(private featureFlagService: FeatureFlagService) {}
79
-
80
- async processPayment(userId: string) {
81
- const isEnabled = await this.featureFlagService.isEnabled('NEW_PAYMENT_FLOW', {
82
- userId,
83
- environment: 'production'
84
- });
85
-
86
- if (isEnabled) {
87
- // New payment implementation
88
- } else {
89
- // Legacy payment implementation
90
- }
91
- }
92
- }
93
- ```
94
-
95
- ### Backend Integration (Express/Node.js)
96
-
97
- ```typescript
98
- // server.js
99
- import { MemoryFeatureFlagProvider } from '@plyaz/core/domain';
100
- import { FEATURES } from '@plyaz/config';
101
-
102
- // Initialize provider
103
- const featureFlagProvider = new MemoryFeatureFlagProvider({
104
- provider: 'memory',
105
- isCacheEnabled: true,
106
- cacheTtl: 300
107
- }, FEATURES);
108
-
109
- await featureFlagProvider.initialize();
110
-
111
- // Use in routes
112
- app.get('/api/features/:key', async (req, res) => {
113
- const evaluation = await featureFlagProvider.getFlag(req.params.key, {
114
- userId: req.user?.id,
115
- environment: process.env.NODE_ENV
116
- });
117
-
118
- res.json(evaluation);
119
- });
120
- ```
121
-
122
- ### Frontend Integration (React)
123
-
124
- ```typescript
125
- // App.tsx
126
- import { FeatureFlagAppProvider } from '@plyaz/core/frontend';
127
- import { FEATURES } from '@plyaz/config';
128
-
129
- function App() {
130
- return (
131
- <FeatureFlagAppProvider
132
- config={{
133
- provider: 'api',
134
- apiEndpoint: 'https://api.example.com/feature-flags',
135
- isCacheEnabled: true,
136
- cacheTtl: 300
137
- }}
138
- features={FEATURES}
139
- >
140
- <MyApplication />
141
- </FeatureFlagAppProvider>
142
- );
143
- }
144
-
145
- // Component.tsx
146
- import { useFeatureFlag, useFeatureFlagEnabled } from '@plyaz/core/frontend';
147
-
148
- function PaymentComponent() {
149
- // Full feature flag data with loading state
150
- const { value, isLoading, error } = useFeatureFlag('NEW_PAYMENT_FLOW');
151
-
152
- // Simple boolean check
153
- const isGoogleAuthEnabled = useFeatureFlagEnabled('AUTH_GOOGLE');
154
-
155
- if (isLoading) return <Spinner />;
156
-
157
- return (
158
- <div>
159
- {value && <NewPaymentFlow />}
160
- {isGoogleAuthEnabled && <GoogleSignInButton />}
161
- </div>
162
- );
163
- }
164
- ```
165
-
166
- ### Frontend Integration (Vanilla JavaScript)
167
-
168
- ```typescript
169
- import { MemoryFeatureFlagProvider } from '@plyaz/core/domain';
170
- import { FEATURES } from '@plyaz/config';
171
-
172
- // Initialize provider
173
- const provider = new MemoryFeatureFlagProvider({
174
- provider: 'memory',
175
- isCacheEnabled: true
176
- }, FEATURES);
177
-
178
- await provider.initialize();
179
-
180
- // Check feature flags
181
- async function renderPaymentButton() {
182
- const isEnabled = await provider.isEnabled('NEW_PAYMENT_FLOW', {
183
- userId: getCurrentUserId(),
184
- environment: 'production'
185
- });
186
-
187
- if (isEnabled) {
188
- document.getElementById('payment-btn').innerHTML = 'New Payment';
189
- } else {
190
- document.getElementById('payment-btn').innerHTML = 'Legacy Payment';
191
- }
192
- }
193
-
194
- // Subscribe to changes
195
- provider.subscribe(() => {
196
- renderPaymentButton();
197
- });
198
- ```
199
-
200
- ### Testing Support
201
-
202
- ```typescript
203
- import { MemoryFeatureFlagProvider } from '@plyaz/core/domain';
204
- import { FEATURES } from '@plyaz/config';
205
-
206
- // Initialize for testing with overrides
207
- const testProvider = new MemoryFeatureFlagProvider({
208
- provider: 'memory',
209
- isLoggingEnabled: false
210
- }, FEATURES);
211
-
212
- await testProvider.initialize();
213
-
214
- // Override specific flags for testing
215
- testProvider.setOverride('NEW_PAYMENT_FLOW', true);
216
- testProvider.setOverride('BETA_FEATURE', false);
217
-
218
- // Use in tests
219
- describe('Payment Flow', () => {
220
- it('should use new payment flow when enabled', async () => {
221
- const isEnabled = await testProvider.isEnabled('NEW_PAYMENT_FLOW');
222
- expect(isEnabled).toBe(true);
223
- });
224
- });
225
- ```
226
-
227
- ## 🗄️ Cache System
228
-
229
- The cache system provides intelligent caching strategies for business logic coordination:
230
-
231
- ### Basic Usage
232
-
233
- ```typescript
234
- import { CacheManager } from '@plyaz/core/cache';
235
-
236
- // Initialize with memory strategy
237
- const cache = new CacheManager({
238
- isEnabled: true,
239
- ttl: 300, // 5 minutes
240
- strategy: 'memory',
241
- memoryConfig: {
242
- maxSize: 1000,
243
- cleanupInterval: 60000 // 1 minute
244
- }
245
- });
246
-
247
- // Store data
248
- await cache.set('user:123', userData, 600); // Custom TTL of 10 minutes
249
-
250
- // Retrieve data
251
- const user = await cache.get<User>('user:123');
68
+ ### Engine Layer
69
+ - **Feature Flag Engine**: Complete evaluation logic with rules and conditions
70
+ - **Future Engines**: Calculation, Incentive, Validation, Insights (planned)
252
71
 
253
- // Check existence
254
- const exists = await cache.has('user:123');
255
-
256
- // Remove specific key
257
- await cache.delete('user:123');
258
-
259
- // Clear all cache
260
- await cache.clear();
261
-
262
- // Get cache statistics
263
- const stats = await cache.getStats();
264
- console.log(`Cache hit ratio: ${stats.hitRatio}`);
265
- ```
266
-
267
- ### Redis Strategy
268
-
269
- ```typescript
270
- import { CacheManager } from '@plyaz/core/cache';
271
-
272
- const cache = new CacheManager({
273
- isEnabled: true,
274
- ttl: 300,
275
- strategy: 'redis',
276
- redisConfig: {
277
- url: 'redis://localhost:6379',
278
- keyPrefix: 'myapp:',
279
- db: 0
280
- }
281
- });
282
- ```
283
-
284
- ### Integration with Feature Flags
285
-
286
- ```typescript
287
- // Feature flags use the cache system internally
288
- const provider = new MemoryFeatureFlagProvider({
289
- provider: 'memory',
290
- isCacheEnabled: true, // Enables caching
291
- cacheTtl: 300 // Cache TTL in seconds
292
- }, FEATURES);
293
-
294
- // The provider automatically caches evaluations for performance
295
- ```
296
-
297
- ### Business Logic Caching Patterns
298
-
299
- ```typescript
300
- import { CacheManager } from '@plyaz/core/cache';
301
-
302
- class UserService {
303
- constructor(private cache: CacheManager) {}
304
-
305
- async getUser(userId: string): Promise<User> {
306
- // Try cache first
307
- const cacheKey = `user:${userId}`;
308
- const cached = await this.cache.get<User>(cacheKey);
309
-
310
- if (cached) {
311
- return cached;
312
- }
313
-
314
- // Fetch from database
315
- const user = await this.fetchUserFromDb(userId);
316
-
317
- // Cache for future requests
318
- await this.cache.set(cacheKey, user, 600); // 10 minutes
319
-
320
- return user;
321
- }
322
-
323
- async invalidateUser(userId: string): Promise<void> {
324
- await this.cache.delete(`user:${userId}`);
325
- }
326
- }
327
- ```
328
-
329
- ## 🔧 Key Features
72
+ ## 🔧 Key Capabilities
330
73
 
331
74
  - **Environment Isolation**: Complete separation of frontend and backend code
332
- - **Business Caching**: Intelligent caching strategies for cross-package data coordination
333
- - **Feature Flags**: Complete feature flag system with multiple providers
334
- - **Domain-Driven Design**: Clear bounded contexts for different business domains
335
- - **SDK Ready**: B2B partner integration capabilities
336
- - **Type Safe**: Full TypeScript support across all environments
337
-
338
- ## 🏛️ Microservice Strategy
339
-
340
- Install `@plyaz/core` into individual microservices and import only needed functionality:
341
-
342
- ```typescript
343
- // User Service - only imports user-related functionality
344
- import { UserDomainService, UserCacheService } from '@plyaz/core/domain';
345
-
346
- // Asset Service - only imports asset-related functionality
347
- import { AssetDomainService, CalculationEngine } from '@plyaz/core';
348
- ```
75
+ - **Type Safety**: Full TypeScript support with strict boundaries
76
+ - **Domain-Driven Design**: Clear bounded contexts for business domains
77
+ - **Extensible Architecture**: Provider pattern for easy extension
78
+ - **Performance Optimized**: Built-in caching and efficient evaluation
79
+ - **Testing Support**: Override capabilities and test utilities
349
80
 
350
81
  ## 📚 Documentation
351
82
 
@@ -353,6 +84,12 @@ For detailed architecture information, implementation guides, and examples:
353
84
 
354
85
  **[📖 Full Documentation](https://plyaz.atlassian.net/wiki/spaces/SD/pages/37257227/Core+Package?atlOrigin=eyJpIjoiNmQxZmNhYTllYmZjNDU2Njk0YmRhYWI2M2JkNTA3NDMiLCJwIjoiYyJ9)**
355
86
 
87
+ ### 📄 Confluence Documentation
88
+
89
+ - **[Feature Flag System](https://plyaz.atlassian.net/wiki/spaces/SD/pages/44859395/Feature+Flag+System+plyaz+core?atlOrigin=eyJpIjoiNjEyMWY3N2ViZDUxNDIxZTgxNGRmZWMwNjQwMzhiOTQiLCJwIjoiYyJ9)** - Complete feature flag implementation guide
90
+ - **[Engine Layer](https://plyaz.atlassian.net/wiki/spaces/SD/pages/44892169/Engine+Layer+plyaz+core?atlOrigin=eyJpIjoiYTI5M2JhOTA5M2Q4NDY1ZjkzZjM2Yzk5M2U5MTZlMzUiLCJwIjoiYyJ9)** - Core computational engines documentation
91
+ - **[Cache System](https://plyaz.atlassian.net/wiki/spaces/SD/pages/44892180/Cache+System+plyaz+core?atlOrigin=eyJpIjoiNDU2MTU5MWU0NTQ1NDIyMzk0MzJkNjE3MDkyOWVkZDQiLCJwIjoiYyJ9)** - Caching strategies and implementation
92
+
356
93
  ## 🔗 Related Packages
357
94
 
358
95
  | Package | Purpose | Core Usage |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Shared core logic and utilities for Plyaz apps, services, and future SDKs – centralized, reusable, and scalable.",
5
5
  "type": "module",
6
6
  "keywords": [],