Demo project
The Famir demo project shows how to assemble a platform configuration, connect tenant hooks, and launch the main applications. It can be used as an example structure or as a basis for your own project.
Project structure
The demo project is a separate Node.js application in TypeScript. In it, infrastructure configuration, application code, and static files are separated into directories:
famir-demo/
├── assets/
│ ├── actions/ # static resources of actions-app
│ ├── console/ # YAML-presets and resources of console-app
│ └── reverse/ # HTML and other resources of reverse-app
├── config/ # environment configuration
├── src/
│ ├── actions/ # setup and launch of actions-app
│ ├── console/ # setup and launch of console-app
│ └── reverse/ # setup of reverse-app and tenant hooks
├── generate-assets.js # generation of TypeScript modules with static files
├── package.json
└── tsconfig.jsonThe src directory contains TypeScript code and application entry points. The assets directory holds static files. The config directory contains examples of environment configuration files and related infrastructure.
Static assets
Assets are static files that applications need during operation: for example, YAML presets, HTML pages, text files, and icons.
Before compilation, the generate-assets.js script reads the contents of the assets/console, assets/reverse, and assets/actions directories and generates TypeScript modules:
assets/console → src/console/assets.ts
assets/reverse → src/reverse/assets.ts
assets/actions → src/actions/assets.tsThe script runs during the prebuild stage. The contents of the files are included in the generated code and then end up in the application build. Therefore, assets are available to the application from its built-in registry and do not need to be read from the source assets directory on every request.
To add or change an asset, edit the source file in the corresponding assets/ directory and rebuild the project.
Applications
The project configures three Famir applications. Each has its own directory in src, a separate composition module, and a loader for connecting infrastructure and managing startup.
console-app
console-app provides an interface for managing the platform. In the demo project, it can run as a CLI application or as a network application.
The main.ts module registers controllers and services for Famir system functions and entities: campaign, proxy, target, redirector, lure, session, and message. Loaders connect the necessary dependencies, including configuration, logging, and database.
YAML presets are located in assets/console. During the build, their contents are included in the console-app assets. This allows presets to be loaded through the management application without accessing the source YAML files at runtime.
src/console/
├── loaders/
│ ├── cli.ts # launch of the CLI variant
│ └── net.ts # launch of the network variant
├── assets.ts # generated from assets/console
├── main.ts # registration of controllers and services
└── preload.ts # preliminary process setup
assets/console/
├── *.yaml # YAML presets
└── banner-greet.txt # text resourcereverse-app
reverse-app receives and processes HTTP traffic directed through an external edge server. Its loader connects the HTTP server, HTTP client, database, task queue, and other necessary infrastructure components.
main.ts assembles the reverse pipeline controllers and registers TypeScript tenant hooks. Hooks are located in src/reverse/tenants and are connected to the reverse application via a tenant switch. A specific hook can be applied to the corresponding tenant and target.
HTML pages and other static resources for the reverse application are located in assets/reverse. In the demo project, resources can be grouped by site or purpose. During the build, they are included in the generated src/reverse/assets.ts.
src/reverse/
├── loaders/
│ └── std.ts # setup and launch of reverse-app
├── tenants/
│ ├── index.ts # export of tenant hooks
│ └── *.ts # TypeScript hooks of individual tenants
├── assets.ts # generated from assets/reverse
├── main.ts # composition of controllers and tenant switch
└── preload.ts # preliminary process setup
assets/reverse/
├── <tenant>/ # resources of individual sites or tenants
└── *.html, *.txt, *.ico # common static filesYAML presets configure the campaign and targets, while hooks define additional programmable behavior. Static HTML and other files are separate assets of the reverse application; they do not replace hook code.
actions-app
actions-app is designed for background job processing. In the demo project, the application connects workers that receive jobs from BullMQ queues. In particular, analysis and webhook workers are configured.
The loader registers the database, object storage, producer/consumer components, and workers, and then launches the application. The assets/actions directory is intended for static files of this application; if they are used, they are also included in the build.
src/actions/
├── loaders/
│ └── std.ts # setup and launch of actions-app
├── assets.ts # generated from assets/actions
├── main.ts # registration of controllers and services
└── preload.ts # preliminary process setup
assets/actions/
└── ... # static resources, if neededBuild and launch
Preparation
Install dependencies, create a local environment file, and configure it for your infrastructure:
npm install
cp .env.example .envBefore launching, check the settings in .env, including connections to Redis and object storage. After preparing the configuration, build the project:
npm run buildThe build command first runs the generation of TypeScript modules with static assets, then compiles TypeScript into the dist/ directory.
Launching via npm run
Each application can be launched separately:
# Reverse proxy
npm run start:reverse-std
# Console as CLI
npm run start:console-cli
# Console as a network application
npm run start:console-net
# Background workers and job processing
npm run start:actions-stdThe CLI variant of console is intended for interactive execution of management commands. The network variant launches console as a separate application. reverse-app serves incoming traffic, while actions-app performs background tasks.
To run multiple applications in production, a process manager such as PM2 is typically used.
Launching via PM2
Create a PM2 configuration based on the example and edit it if necessary:
cp pm2.config.cjs.example pm2.config.cjsThe example configures the launch of three applications:
console- network mode of console-app;reverse- reverse-app;actions- actions-app.
Launch the applications:
pm2 start pm2.config.cjsYou can check process status and view logs with the following commands:
pm2 status
pm2 logsTo manage processes, use standard PM2 commands, for example:
pm2 restart all
pm2 stop allThe PM2 configuration uses .env and separate preload modules for the applications.
Logs
By default, the demo project writes logs to the logs/ directory, separately by application:
logs/
├── console/
├── reverse/
└── actions/The path to the logs directory can be changed with the LOGGER_BASE_PATH environment variable. If it is not set, ./logs is used. Log files are rotated daily; the demo project configuration retains the last seven files.