---
title: "TeqFW: Core"
description: "How the TeqFW core boots a Node.js application, discovers npm plugins, configures DI, and composes its command-line interface."
date: 2021-06-25
---

A Teq application is first a Node.js application and then a modular
application composed of Teq plugins, which are npm modules. The platform
core has three jobs: start the application and its console commands,
discover and attach plugins, and establish the foundational
architecture.

## Bootstrap

The application entry point is `bin/tequila.mjs`. It finds the
application root, loads the DI container, maps core sources, creates the
bootstrap configuration, obtains `TeqFw_Core_Back_App$`, initializes it,
and runs it. The script belongs to the application but is intentionally
almost identical from one Teq application to another.

``` js
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import teq from '@teqfw/core';

const root = join(dirname(fileURLToPath(import.meta.url)), '..');
teq({ path: root }).catch(console.error);
```

Different behaviour comes from the installed plugins and the commands
they contribute, not from rewriting the launcher.

## Core application lifecycle

During initialization, `TeqFw_Core_Back_App`:

- initializes logging;
- loads local configuration, such as database connection settings;
- scans the application filesystem and creates the plugin registry;
- adds namespaces discovered in plugins to the DI container;
- collects CLI commands from those plugins.

During execution it runs the requested command — commonly a web server.
With no command, it prints the available commands. The application also
exposes `stop()` so a command can close resources such as database
connections in an orderly way.

## Logger and configuration

The original core design exposed a common logger abstraction that could
work on backend or frontend and route records to transports such as
console, file, database, or remote server. Local backend configuration
is read from a JSON file such as `cfg/local.json` and injected into the
objects that need it. Secrets should remain in an ignored local
configuration or a secure deployment environment, never in a package
descriptor.

## Plugin scanner

A Teq plugin is an npm package with a `teqfw.json` descriptor in its
root. At minimum it declares a namespace and source directory:

``` json
{
  "autoload": {
    "ns": "Vendor_Project_Plugin",
    "path": "./src"
  }
}
```

The plugin scanner walks `node_modules`, finds descriptors, records
plugin packages, and adds namespace-to-filesystem mappings to DI. Other
parts of the application access plugin descriptors through this registry
instead of rescanning the filesystem.

## Commands

The core application is effectively a wrapper around
[commander](https://www.npmjs.com/package/commander). Plugin descriptors
list module identifiers that produce command DTOs:

``` json
{ "commands": ["TeqFw_Core_Back_Cli_Version"] }
```

A command DTO provides an `action`, description, name and optional
realm. The realm prefixes commands from one plugin, so `app` plus
`clean` becomes `app-clean`.

``` js
const command = await container.get(`${factoryName}$`);
const fullName = command.realm ? `${command.realm}-${command.name}` : command.name;
commander.command(fullName).description(command.desc).action(command.action);
```

## Summary

The Core plugin turns a collection of npm modules into a runnable Teq
application. It discovers plugins, registers their namespaces,
initializes logging and local configuration, collects their commands,
and executes the selected command through DI. This keeps the launcher
stable while applications grow by composing plugins.

<zoom-img src="/medium/img/346fb4788e98/image-01.png" alt="Core components in a TeqFW application" width="100%"></zoom-img>
