Advanced
Namespaces
Featurevisor allows namespacing features and segments to tackle the challenges of scaling large projects.
Namespaces help teams organize their features and segments in a structured and hierarchical way, making it easier to manage and maintain them as their project grows larger and more complex over time.
Features#
Creating a namespace for a feature is as simple as putting the feature under a directory, and the directory name then becomes the namespace.
If there is a team working on the checkout flow for e.g., they can create a namespace called checkout and put all their features related to the checkout flow in that namespace:
features/├── checkout/│ ├── feature1.yml│ ├── feature2.yml│ └── feature3.yml└── globalFeature.ymlEvaluating features#
By default, path segments are joined with . when deriving feature keys. When evaluating a feature, you can refer to the feature by its namespace and key in the format namespace.featureKey:
const f; // Featurevisor SDK instancef.isEnabled("checkout.feature1");f.isEnabled("globalFeature");Testing features#
When testing features, you can refer to the feature by its namespace and key in the format namespace.featureKey:
feature: checkout.feature1# ...The file name and location for test specs do not matter, as long as they exist inside the tests directory.
Segments#
Very similar to features, you can namespace segments by putting them in a directory:
segments/├── countries/│ ├── germany.yml│ └── netherlands.yml└── globalSegment.ymlReferencing segments#
When defining the rules inside features, you can refer to the segment by its namespace and key in the format namespace.segmentKey:
# ...rules: production: - key: '1' segments: 'countries.netherlands' percentage: 100Testing segments#
When testing segments, you can refer to the segment by its namespace and key in the format namespace.segmentKey:
segment: countries.nl# ...Custom namespace character#
The namespace separator is controlled by namespaceCharacter in your project configuration:
module.exports = { namespaceCharacter: ".", // default};With the default ".", features/checkout/feature1.yml becomes checkout.feature1.
If you need slash-separated keys for an existing project, configure:
module.exports = { namespaceCharacter: "/",};Then features/checkout/feature1.yml becomes checkout/feature1.
Comparison#
Namespaces are no replacement for tags or environments, but they can be used in conjunction with them to create a more structured and organized project.
- Tags: for tagging features resulting in targeted and smaller datafiles that your applications consume via SDKs
- Environments: for creating different environments, like
productionandstaging, and then use them in your feature rules to control the rollout of features - Namespaces: for organizing features and segments in a hierarchical way

