# Feature-based Development

Most of the code you write will go in the app/features folder. Each folder within represents a discrete feature for your app where you can group related code together. The same principle that applies when organizing your kitchen -- keep related tools together -- will help you organize and understand your code over the long run.

Without breaking your code out into features, it is very easy to end up with a Controllers directory, for example, that contains dozens or more Controller files, often only vaguely related to each other. Often, people will attempt to solve this problem by creating micro-services, but this can lead to an incredible amount of overhead that slows you down -- something you want to avoid, especially in the early days of a startup!

When code is broken up into features, it becomes very obvious when you are writing code that crosses boundaries into another's domain, as you'll find yourself reaching for code that lives in another feature's folder, and that should alert you that you're building dependencies that you need to be aware of.


If you notice that you are writing code that wants to "reach into" another feature's code, try to limit that code to Services in the API and Stores in the UI. These two types of files are generally where the action happens, and are your best location to specify the "contract" for how interaction happens with your data. Try to avoid reaching directly into the lib folder, and instead try to call a Service or Store function that itself calls on a lib function for processing.

Features can be enabled or disabled at any time by editing app/config/app.js and modifying the features object. This can be helpful when you don't need to use certain Nodewood features for your application, or to use a feature flag to disable certain features in production.

# Creating a new feature

From the root of your project, run nodewood add:feature NAME. This will create a new feature in app/features/NAME and fill it with examples of Controllers, Services, Vue Pages, etc. It will also create a migration in app/migrations. These examples all work together such that the default Page for the feature will load the list of entities from the database over the API and display them in a table. Obviously your needs will be different, but you can customize your feature from here.

# Options

# No examples

If you don't want examples for your feature, you can append --no-examples to your command, and the feature will be created with just the empty default folders.

# Overwriting existing features

By default, a feature will not be created in a feature folder that already exists. If you want to overwrite that existing folder (careful!), append --overwrite to your command.

# Custom plurals

Nodewood will attempt to automatically determine the plural for your feature name for the appropriate files, but that can fail hilariously on certain words. To provide a custom plural for your feature, append --plural=PLURAL and PLURAL will be used for the plural form of your feature's name.