# Modules

The Modules feature in FhyTS allows you to load, register, and manage additional features separately and modularly. This mechanism is ideal for plugin-based architectures, large-scale systems, or applications that require flexible extension points.

## General Concepts

* A module is a standalone entity or feature that can be registered with the system.
* The **Module** class acts as a registry, storing all registered module instances.
* Registered modules can be accessed globally via **getModules()** for initialization, integration, or execution.

## API Reference

| Method | Type | Description |
| -------------------- | ----------------------------------------- | ---------------------------------------------------- |
| `register(instance)` | `(moduleInstance: any) => void` | Registers a module with the system. |
| `getModules()` | `() => any[]` | Retrieves all registered module instances. |

## Usage Example

#### Registering a Module

Suppose you have a custom module named **AnalyticsModule**:

```javascript
class AnalyticsModule {
  init() {
    console.log('Analytics initialized');
  }
}
```

Registration can be done as follows:

```javascript
import { Module } from 'fhyts';

const moduleSystem = new Module();
moduleSystem.register(new AnalyticsModule());
```

#### Initialize All Modules

```javascript
for (const mod of moduleSystem.getModules()) {
  if (typeof mod.init === 'function') {
    mod.init();
  }
}
```

## Best Practices

* Each module should have a standard interface/method (e.g., **init()** or **boot())**.
* Use a single **Module** instance for the entire application and manage registration centrally.
* Avoid hard-coding modules — use autoloading when needed for large scale.

## Next

Once you understand how to use Modules, you can move on to the [Utils](#utils) section to learn about a collection of utility functions that support various operations in your application efficiently and reusably.