https://github.com/zenkiet/ngx-feature-proxy
Angular feature flag library with Unleash integration, provides reactive programing, type-safe feature flag management with zero-configuration setup.
https://github.com/zenkiet/ngx-feature-proxy
angular bem dashboard feature-flags library reactive-programming rxjs scss tool unleash
Last synced: 6 days ago
JSON representation
Angular feature flag library with Unleash integration, provides reactive programing, type-safe feature flag management with zero-configuration setup.
- Host: GitHub
- URL: https://github.com/zenkiet/ngx-feature-proxy
- Owner: zenkiet
- License: mit
- Created: 2025-10-12T15:20:35.000Z (16 days ago)
- Default Branch: main
- Last Pushed: 2025-10-16T17:02:38.000Z (12 days ago)
- Last Synced: 2025-10-17T17:10:43.238Z (11 days ago)
- Topics: angular, bem, dashboard, feature-flags, library, reactive-programming, rxjs, scss, tool, unleash
- Language: SCSS
- Homepage:
- Size: 513 KB
- Stars: 13
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-angular - ngx-feature-proxy - Angular feature flag library with Unleash integration, provides reactive programming, type-safe feature flag management with zero-configuration setup. (Architecture and Advanced Topics / Feature Flags)
- awesome-angular - ngx-feature-proxy - Angular feature flag library with Unleash integration, provides reactive programming, type-safe feature flag management with zero-configuration setup. (Architecture and Advanced Topics / Feature Flags)
README
# ๐ ngx-feature-proxy

[](https://www.npmjs.com/package/ngx-feature-proxy)
[](https://www.npmjs.com/package/ngx-feature-proxy)
[](https://www.npmjs.com/package/ngx-feature-proxy)
[](https://www.npmjs.com/package/ngx-feature-proxy)
[](https://github.com/zenkiet/ngx-feature-proxy/issues)
[](https://github.com/zenkiet/ngx-feature-proxy/stargazers)
[](https://github.com/zenkiet/ngx-feature-proxy/actions)
[](LICENSE)
**๐ฏ Type-safe Angular Feature Flag Library with Unleash Integration**
_Reactive programming โข Zero-configuration setup โข Enterprise-ready_
[๐ฆ NPM](https://www.npmjs.com/package/ngx-feature-proxy) โข [๐ Quick Start](#-quick-start) โข [๐ฌ Discussions](https://github.com/zenkiet/ngx-feature-proxy/discussions)
[](https://youtu.be/K-2rLjG7qyQ)
---
## ๐ Table of Contents
- [๐ Features](#-features)
- [๐ What is Unleash?](#-what-is-unleash)
- [๐๏ธ Architecture](#๏ธ-architecture)
- [๐ Quick Start](#-quick-start)
- [๐ฆ Installation](#-installation)
- [โ๏ธ Basic Setup](#๏ธ-basic-setup)
- [๐ฏ Your First Feature Flag](#-your-first-feature-flag)
- [๐ฎ Usage Guide](#-usage-guide)
- [๐ง Service Usage](#-service-usage)
- [๐จ Directive Usage](#-directive-usage)
- [๐ฏ Simple Feature Check](#-simple-feature-check)
- [๐ฏ Complex Feature Check](#-complex-feature-check)
- [๐ก๏ธ Route Guards](#๏ธ-route-guards)
- [๐ช Advanced Guard Patterns](#-advanced-guard-patterns)
- [๐ณ Docker Setup with Unleash](#-docker-setup-with-unleash)
- [๐ณ Complete Docker Compose Setup](#-complete-docker-compose-setup)
- [๐ Access Your Unleash](#-access-your-unleash)
- [๐ค Contributing](#-contributing)
- [๐ Bug Reports](#-bug-reports)
- [โจ Feature Requests](#-feature-requests)
- [๐ ๏ธ Development Workflow](#๏ธ-development-workflow)
- [๐ Commit Convention](#-commit-convention)
- [๐ License](#-license)
- [๐ Acknowledgments](#-acknowledgments)
- [๐ Support](#-support)
- [๐ค Get Help \& Connect](#-get-help--connect)
- [๐ Project Stats](#-project-stats)
- [๐ Ready to get started?](#-ready-to-get-started)
---
## ๐ Features
| Feature | Description |
| -------------------------- | -------------------------------------------- |
| ๐ **Debug Tool** | Built-in debug info for easy troubleshooting |
| โจ **Type-Safe** | Full TypeScript support with strict typing |
| ๐ **Performance** | Optimized with caching and smart updates |
| ๐ก๏ธ **Route Protection** | Support for guards to protect routes |
| ๐จ **Template Directives** | Declarative feature flag usage in templates |
| ๐ง **Flexible** | Support for complex feature flag expressions |
| ๐ **Enterprise Ready** | Can be deployed in large-scale applications |
## ๐ What is Unleash?
Unleash is an open-source feature flag management platform that enables you to:
| Capability | Benefit |
| -------------------------- | ------------------------------------------------------------------ |
| ๐๏ธ **Toggle Features** | Enable/disable features instantly without deployments |
| ๐ฏ **Targeted Rollouts** | Gradual feature rollouts to specific user segments |
| ๐งช **A/B Testing** | Run experiments with different feature variants |
| ๐ **Analytics** | Track feature usage and performance metrics |
| ๐ **Enterprise Security** | Role-based access control and audit logs |
| ๐ **Multi-Environment** | Separate feature configurations for **develop/staging/production** |
---
## ๐๏ธ Architecture
```mermaid
graph TB
subgraph APP["๐ฑ Angular Application (Frontend)"]
COMP["๐งฉ Components"]
SERV["โ๏ธ FeatureProxyService
- Manage Feature Flags
- Check Access"]
DIR["โจ FeatureProxy Directive
- Show/Hide UI based on Flags"]
GUARD["๐ FeatureProxy Guards
- Protect Routes"]
SIGNAL["๐ Signal State
- Reactive Updates"]
end
subgraph UNLEASH["๐ Unleash Infrastructure"]
PROXY["๐ก Unleash Proxy
- HTTP/WebSocket
- Real-time Updates"]
SERVER["๐๏ธ Unleash Server
- Control Panel
- Manage Features"]
DB["๐พ PostgreSQL
- Data Storage
- Persistence"]
end
subgraph USERS["๐ฅ Users"]
ENDUSER["๐ค End Users
- Use Application"]
DEVOPS["โ๏ธ DevOps Team
- Manage Flags"]
end
%% Application Internal Flow
COMP -->|"use"| SERV
COMP -->|"use"| DIR
COMP -->|"use"| GUARD
SERV -->|"update"| SIGNAL
DIR -->|"check"| SERV
GUARD -->|"verify"| SERV
%% Communication with Unleash
SERV <-->|"๐ก HTTP/WebSocket
- Request Flags
- Real-time Sync"| PROXY
PROXY <-->|"๐ Sync Flags
- Pull Configuration"| SERVER
SERVER <-->|"๐พ Read/Write
- Feature Data"| DB
%% User Interactions
ENDUSER -->|"๐ฑ๏ธ Interactions
- Trigger Features"| COMP
DEVOPS -->|"โ๏ธ Toggle
- Manage Flags"| SERVER
%% Styling
classDef angular fill:#DD0031,stroke:#333,stroke-width:2px,color:#fff,font-size:12px
classDef unleash fill:#7C3AED,stroke:#333,stroke-width:2px,color:#fff,font-size:12px
classDef users fill:#059669,stroke:#333,stroke-width:2px,color:#fff,font-size:12px
class COMP,SERV,DIR,GUARD,SIGNAL angular
class PROXY,SERVER,DB unleash
class ENDUSER,DEVOPS users
```
**๐ How it Works:**
1. **๐ฏ Feature Definition**: DevOps team defines feature flags in Unleash Server
2. **๐ก Real-time Sync**: Unleash Proxy pulls configurations and serves them via HTTP/WebSocket
3. **๐ง Angular Integration**: ngx-feature-proxy connects to Unleash Proxy using unleash-proxy-client
4. **๐ Reactive Updates**: Service uses Angular signals to provide real-time feature flag state
5. **๐จ Template Magic**: Directives and guards automatically react to feature flag changes
6. **๐ค User Experience**: End users see features toggled instantly without page refreshes
---
## ๐ Quick Start
### ๐ฆ Installation
```bash
# ๐ Install the library
npm install ngx-feature-proxy
```
### โ๏ธ Basic Setup
```typescript
// ๐ src/main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { provideFeatureProxy } from 'ngx-feature-proxy';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [
// ๐ฏ Configure feature proxy
provideFeatureProxy({
url: 'http://localhost:3000/api/proxy', // ๐ Your Unleash proxy URL
clientKey: 'your-client-key', // ๐ Your client key
appName: 'my-angular-app', // ๐ฑ Your app name
// ๐๏ธ Optional: Advanced configuration
context: {
environment: 'development',
},
refreshInterval: 30, // โฑ๏ธ Refresh interval in seconds
metricsInterval: 60, // ๐ Metrics interval in seconds
debug: true, // ๐ Enable debug mode
}),
// ... other providers
],
});
```
### ๐ฏ Your First Feature Flag
```typescript
// ๐ src/app/app.component.ts
import { Component, inject } from '@angular/core';
import { FeatureProxyService } from 'ngx-feature-proxy';
@Component({
selector: 'app-root',
template: `
๐ Welcome to the new dashboard!
๐ Access to premium beta features!
@if (isNewfeatureProxy) {
โจ Try New Feature
}
๐ Ready: {{ $state().ready }}
โฐ Last Update: {{ $state().lastUpdate | date: 'medium' }}
`,
standalone: true,
imports: [FeatureProxyDirective],
})
export class AppComponent {
private featureService = inject(FeatureProxyService);
// ๐ฏ Direct feature check
isNewFeatureEnabled = this.featureService.isEnabled('newFeature');
// ๐ Reactive state
$state = this.featureService.$state;
tryNewFeature() {
console.log('๐ New feature activated!');
}
}
```
---
## ๐ฎ Usage Guide
### ๐ง Service Usage
The `FeatureProxyService` is the core of the library, providing programmatic access to feature flags:
```typescript
import { Component, inject, computed, effect } from '@angular/core';
import { FeatureProxyService } from 'ngx-feature-proxy';
@Component({
selector: 'app-feature-demo',
template: `
๐ Beta Features
Status: {{ betaEnabled ? 'โ
Enabled' : 'โ Disabled' }}
Try Beta Feature
๐ Premium Feature
Variant: {{ premiumVariant.name }}
Theme: {{ premiumVariant.payload.value }}
`,
standalone: true,
})
export class FeatureDemoComponent {
private featureService = inject(FeatureProxyService);
// ๐ Reactive state
$state = this.featureService.$state;
// ๐ฏ Simple feature check
betaEnabled = computed(() => this.featureService.isEnabled('betaFeatures'));
// ๐ญ Get variant with payload
premiumVariant = computed(() => this.featureService.getVariant('premiumTheme'));
// ๐ Complex feature expression
advancedMode = computed(() =>
this.featureService.features('premiumUser && (betaAccess || adminMode)')
);
constructor() {
// ๐ React to impression events
effect(() => {
const impression = this.featureService.$impression();
if (impression.eventType === 'isEnabled') {
console.log('๐ฏ Feature accessed:', impression.featureName);
}
});
}
useBetaFeature() {
console.log('๐งช Beta feature activated!');
}
// ๐ Update user context
async updateUserContext(userId: string) {
await this.featureService.updateContext({ userId }).toPromise();
console.log('๐ค User context updated');
}
// ๐ก Manual refresh
async refreshFlags() {
await this.featureService.refresh().toPromise();
console.log('๐ Feature flags refreshed');
}
}
```
### ๐จ Directive Usage
The `*featureEnabled` directive provides declarative feature flag control in templates:
#### ๐ฏ Simple Feature Check
```html
๐ Welcome to the new dashboard!
```
#### ๐ฏ Complex Feature Check
```html
๐ Access to premium beta features!
```
### ๐ก๏ธ Route Guards
Protect your routes with feature flag-based guards:
```typescript
import { Routes } from '@angular/router';
import { featureProxyGuard } from 'ngx-feature-proxy';
export const routes: Routes = [
{
path: 'dashboard',
loadComponent: () => import('./dashboard/dashboard.component'),
canActivate: [
// ๐ฏ Simple feature guard
featureProxyGuard({
expression: 'newDashboard',
redirectTo: '/legacy-dashboard',
}),
],
},
{
path: 'admin',
loadChildren: () => import('./admin/admin.routes'),
canActivate: [
// ๐ก๏ธ Complex permission guard
featureProxyGuard({
expression: 'adminAccess && (betaTester || superUser)',
redirectTo: '/not-authorized',
}),
],
},
{
path: 'user',
loadComponent: () => import('./user/user.component'),
canActivate: [
// ๐ค User-specific feature guard
featureProxyGuard({
condition: (service) => service.isEnabled('userFeatures') && service.getVariant('userTier').name === 'gold',
redirectTo: '/upgrade',
}),
],
}
{
path: 'premium',
loadChildren: () => import('./premium/premium.routes'),
canActivateChild: [
// ๐ Premium feature guard for child routes
featureProxyGuard({
expression: 'premiumUser && validSubscription',
redirectTo: '/subscribe',
}),
],
},
];
```
#### ๐ช Advanced Guard Patterns
```typescript
// ๐ง Custom guard with complex logic
export const premiumGuard = featureProxyGuard({
condition: (service) => {
const isPremium = service.isEnabled('premiumUser');
const isValidSubscription = service.isEnabled('validSubscription');
const variant = service.getVariant('premiumTier');
return isPremium && isValidSubscription && ['gold', 'platinum'].includes(variant.name);
},
redirectTo: '/upgrade',
});
// ๐ Geo-based feature guard
export const geoFeatureGuard = featureProxyGuard({
condition: (service) => {
return service.features('featureEnabled && (region_US || region_EU)');
},
redirectTo: '/geo-restricted',
});
// ๐ฑ Device-specific guard
export const mobileFeatureGuard = featureProxyGuard({
condition: (service) => {
const isMobile = service.getVariant('deviceType').name === 'mobile';
return isMobile && service.isEnabled('mobileFeatures');
},
redirectTo: '/desktop-only',
});
```
---
## ๐ณ Docker Setup with Unleash
### ๐ณ Complete Docker Compose Setup
Create a `docker-compose.yml` file for a complete Unleash setup:
```yaml
# ๐ณ docker-compose.yml
services:
unleash:
image: unleashorg/unleash-server:${UNLEASH_VERSION:-6}
container_name: unleash
restart: ${RESTART_POLICY:-unless-stopped}
ports:
- '4242:4242'
networks:
- unleash_net
environment:
# ๐๏ธ Database configuration
DATABASE_URL: 'postgres://postgres:${UNLEASH_DATABASE_PASSWORD:-unleash}@unleash-db/postgres'
DATABASE_SSL: 'false'
# ๐ Logging and performance
LOG_LEVEL: 'warn'
# ๐ API tokens (generate secure tokens for production)
INIT_FRONTEND_API_TOKENS: ${INIT_FRONTEND_API_TOKENS:-*:*.unleash-insecure-frontend-api-token}
INIT_BACKEND_API_TOKENS: ${INIT_BACKEND_API_TOKENS:-*:*.unleash-insecure-api-token}
# ๐ Server configuration
UNLEASH_URL: 'https://${UNLEASH_DOMAIN:-localhost:4242}'
# ๐ค Default admin credentials
UNLEASH_DEFAULT_ADMIN_PASSWORD: ${UNLEASH_DEFAULT_ADMIN_PASSWORD:-admin123}
UNLEASH_DEFAULT_ADMIN_USERNAME: ${UNLEASH_DEFAULT_ADMIN_USERNAME:-admin}
# โก Performance optimizations
UNLEASH_PROXY_SECRETS: ${UNLEASH_PROXY_SECRETS:-some-secret}
depends_on:
unleash-db:
condition: service_healthy
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:4242/health || exit 1
interval: 1s
timeout: 1m
retries: 5
start_period: 15s
volumes:
# ๐ Optional: Custom configuration
- ./unleash-config:/opt/unleash/config:ro
unleash-db:
image: postgres:17-alpine
container_name: unleash-db
restart: ${RESTART_POLICY:-unless-stopped}
volumes:
- ${DATA_PATH:-./data}/unleash/postgresql/data:/var/lib/postgresql/data
expose:
- '5432'
networks:
- unleash_net
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=${UNLEASH_DATABASE_PASSWORD:-unleash123}
healthcheck:
test: ['CMD', 'pg_isready', '--username=postgres', '--host=127.0.0.1', '--port=5432']
interval: 2s
timeout: 1m
retries: 5
start_period: 10s
# ๐ Optional: Unleash Proxy (for better performance)
unleash-proxy:
image: unleashorg/unleash-proxy:latest
container_name: unleash-proxy
restart: ${RESTART_POLICY:-unless-stopped}
ports:
- '3000:3000'
networks:
- unleash_net
environment:
UNLEASH_URL: 'http://unleash:4242/api'
UNLEASH_API_TOKEN: ${INIT_BACKEND_API_TOKENS:-*:*.unleash-insecure-api-token}
UNLEASH_APP_NAME: 'unleash-proxy'
UNLEASH_INSTANCE_ID: 'unleash-proxy-1'
depends_on:
unleash:
condition: service_healthy
networks:
unleash_net:
driver: bridge
volumes:
unleash_data:
driver: local
```
Create a `.env` file for easy configuration:
```bash
# ๐ .env
# ๐ณ Docker configuration
UNLEASH_VERSION=5.7
RESTART_POLICY=unless-stopped
DATA_PATH=./data
# ๐ Domain and URLs
UNLEASH_DOMAIN=localhost:4242
# ๐๏ธ Database
UNLEASH_DATABASE_PASSWORD=unleash123
# ๐ค Admin credentials (CHANGE IN PRODUCTION!)
UNLEASH_DEFAULT_ADMIN_USERNAME=admin
UNLEASH_DEFAULT_ADMIN_PASSWORD=admin123
# ๐ API Tokens (GENERATE SECURE TOKENS FOR PRODUCTION!)
INIT_FRONTEND_API_TOKENS=*:development.unleash-insecure-frontend-api-token
INIT_BACKEND_API_TOKENS=*:development.unleash-insecure-api-token
UNLEASH_PROXY_SECRETS=proxy-secret-123
# ๐ฏ Optional: Context fields
UNLEASH_CONTEXT_FIELDS=userId,sessionId,environment,region
```
Commands to manage the Docker setup:
```bash
# ๐ Start the stack
docker-compose up -d
# ๐ View logs
docker-compose logs -f unleash
# ๐ Check health
docker-compose ps
# ๐๏ธ Clean up
docker-compose down -v
# ๐ Scale proxy (for high traffic)
docker-compose up -d --scale unleash-proxy=3
```
### ๐ Access Your Unleash
After running `docker-compose up -d`:
- **๐๏ธ Unleash Dashboard**: http://localhost:4242
- **๐ Login**: admin / admin123 (or your configured credentials)
- **โก Proxy Endpoint**: http://localhost:3000/proxy
- **๐ Health Check**: http://localhost:4242/health
---
## ๐ค Contributing
We welcome contributions! Here's how you can help:
### ๐ Bug Reports
1. ๐ Search existing issues
2. ๐ Create detailed bug report
3. ๐ท๏ธ Use appropriate labels
### โจ Feature Requests
1. ๐ก Discuss in GitHub Discussions
2. ๐ Create feature request issue
3. ๐ Submit pull request
### ๐ ๏ธ Development Workflow
```bash
# ๐ด Fork and clone
git clone https://github.com/your-username/ngx-feature-proxy.git
cd ngx-feature-proxy
# ๐ฟ Create feature branch
git checkout -b feat/amazing-feature
# โ
Commit changes
git commit -m "โจ Add amazing feature"
# ๐ Push and create PR
git push origin feat/amazing-feature
```
### ๐ Commit Convention
We use [Conventional Commits](https://www.conventionalcommits.org/):
- `โจ feat:` New features
- `๐ fix:` Bug fixes
- `๐ docs:` Documentation
- `๐จ style:` Code formatting
- `โป๏ธ refactor:` Code restructuring
- `๐ perf:` Performance improvements
- `๐จ test:` Testing
- `๐ง chore:` Maintenance
---
## ๐ License
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
```
MIT License
Copyright (c) 2025 Kiet Le
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
---
## ๐ Acknowledgments
This project wouldn't be possible without these amazing technologies:
Angular
The best Framework ever
RxJS
Reactive Programming
Unleash
Feature Flag Management
Docker
Containerization
---
## ๐ Support
### ๐ค Get Help & Connect
[](mailto:zenkiet0906@gmail.com)
[](https://github.com/zenkiet/ngx-feature-proxy/issues)
[](https://github.com/zenkiet/ngx-feature-proxy/discussions)
[](https://hub.docker.com/r/zenkiet/ngx-feature-proxy)
### ๐ Project Stats



---
### ๐ Ready to get started?
**[๐ฆ Install Now](https://www.npmjs.com/package/ngx-feature-proxy) โข [๐ View Docs](#-table-of-contents) โข [๐ฌ Join Discussion](https://github.com/zenkiet/ngx-feature-proxy/discussions)**
---
**โญ If this project helped you, please consider giving it a star! โญ**
_Made with โค๏ธ by [ZenKiet](https://github.com/zenkiet)_