> For the complete documentation index, see [llms.txt](https://tokenf.gitbook.io/tokenf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tokenf.gitbook.io/tokenf/deep-dive/tokenf-modules.md).

# TokenF Modules

## Modules Architecture

Modules are the backbone of the TokenF framework regulatory mechanics. All rules, requirements, and compliance for KYC and various token transfers can be customized via modular plugin-based architecture.

In the vanilla TokenF version there are two main types of modules:

1. KYC modules
2. Regulatory modules

The KYC modules are responsible for any KYC-related compliance checks while Regulatory modules are used to perform conditional transfer limits / token balance obligations / operational limits / etc.

Modules represent quite a complex set of smart contracts that are related through inheritance and plugged in through composition to the aforementioned `RegulatoryCompliance` and `KYCCompliance` facets.

<figure><img src="https://3376190671-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7uHAvxrFJxs7AFPdsjC4%2Fuploads%2FElcUvZ7veb4HGug0Wuwz%2FModules%20architecture.png?alt=media&amp;token=c21ac310-e10f-4b49-88f8-065296078fa2" alt=""><figcaption><p>Pic. 2 TokenF modules architecture</p></figcaption></figure>

The diagram depicts the relationships between contracts within the TokenF modules architecture. The bulk of the logic is implemented in the `AbstractModule` that `AbstractKYCModule` and `AbstractRegulatoryModule` extend. Certain modules will then inherit from `AbstractKYCModule` and `AbstractRegulatoryModule` contracts to define handlers, their relation to handler topics, context keys construction, and perform the required checks.

## AbstractModule Contract

The `AbstractModule` contract is the basis for writing new modules for the TokenF framework. The contract implements the logic of handler topics management, the definition of handlers, and stores the “weak reference” to the AssetF token contract itself (for certain operations that should only be called by the token).\
\
Moreover, the `AbstractModule` contract defines an interface through which the TokenF managers will “speak” with the module.

## AbstractKYCModule Contract

The `AbstractKYCModule` contract implements the `AbstractModule` interface and extends it by introducing the `isKYCed` function. This function is used by the `KYCCompliance` AssetF facet to authorize the user of the token. By default, the context key is `keccak256(function selector)`.

## AbstractRegulatoryModule Contract

The `AbstractRegulatoryModule` contract is very similar to the `AbstractKYCModule` in terms that it also implements the `AbstractModule` interface. However, two new functions are introduced: `canTransfer` and `transferred`. `RegulatoryCompliance` AssetF facet will call them to perform regulatory compliance checks. Similar to `AbstractKYCModule`, the default context key is `keccak256(function selector)`.
