# Structure

`Main.js` follows a **consistent internal structure** that all expansions adhere to. Understanding this structure helps you organize your code efficiently.

***

### **1. Module Exports**

At the very top/bottom of the file:

```js
module.exports.init = async () => { /* … */ };
module.exports.metadata = { id: "apitest", version: "0.1" };
```

* `init`: Entry point where everything is registered.
* `metadata`: Basic info about the expansion (ID and version).

***

### **2. Initialization Function (`init`)**

The `init` function is structured in a **logical sequence**:

1. **Access the internal API**

   ```js
   const nm = api.nexomaker;
   ```

   Provides all methods for registration, asset loading, and exporting.
2. **Optional logging**

   ```js
   api.console.log("Initializing expansion...");
   ```
3. **Register UI pages**

   ```js
   nm.registerModularPage("pageName", pathToComponent);
   ```
4. **Register overlays or background modules**

   ```js
   nm.registerBackgroundModule("overlayName", pathToOverlay, options);
   ```
5. **Load assets and models**

   ```js
   const icon = await nm.loadAsset(iconPath);
   const model = await nm.loadModel(modelPath);
   const texture = await nm.loadAsset(texturePath);
   ```
6. **Register sidebar buttons, templates, editor modules**

   ```js
   nm.postSidebarIcon({ /* ... */ });
   nm.postTemplate({ /* ... */ });
   nm.postEditorModule({ /* ... */ });
   ```
7. **Define export formats**

   ```js
   nm.postExportFormat(exportFormatObject);
   ```

> The order is not strictly enforced, but this sequence ensures clarity and avoids dependency issues.

***

### **3. File References and Organization**

Within `Main.js`, you reference other parts of the expansion:

* `Pages/` → React components for pages.
* `Components/` → Reusable UI components.
* `Overlays/` → Modular overlays or background modules.
* `Assets/` → Icons, textures, 3D models.

> `Main.js` itself contains **no UI logic**; it only registers components and modules. This folder names and structures are just suggestions.&#x20;

***

### **5. Key Structural Tips**

* Keep sections clearly separated (Pages, Overlays, Assets, Templates, Export Formats).
* Use `async/await` for loading assets or models to avoid race conditions.
* Always test that each registered component is accessible in Nexo Maker after adding it.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nexo-maker.gitbook.io/nexo-maker-docs/main.js/structure.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
