Skip to content

Demo Project ​

The demonstration project shows how to configure the platform, connect tenant hooks, and start the main applications. It can be used as a project structure example or as the basis for your own deployment.

Project Structure ​

The demo project is a repository in which application code, static assets, and third-party component configuration examples are organized in separate directories:

text
famir-demo/
├── assets/                 # static application resources
├── third-party/            # third-party component configuration examples
├── logs/                   # log files
├── src/                    # TypeScript application code
├── build-assets.js         # generated source files for static assets
├── package.json
└── tsconfig.json

The src directory contains the TypeScript code and application entry points. The assets directory contains static files. The third-party directory contains external infrastructure configuration examples.

Static assets ​

Assets are static files required by applications at runtime, including YAML presets, HTML pages, text files, and icons.

Before compilation, build-assets.js reads the contents of assets/console, assets/reverse, and assets/actions, then generates TypeScript modules:

text
assets/console  → src/console/assets.ts
assets/reverse  → src/reverse/assets.ts
assets/actions  → src/actions/assets.ts

The script runs during the prebuild phase. Its output is included in the application build, so applications access assets through an embedded registry rather than reading files directly from the assets directory at runtime.

To add or modify an asset, edit the source file in assets/<app> and rebuild the project.

Third-party component configuration ​

The third-party directory contains configuration examples for components used with Famir:

text
third-party/
├── caddy/                  # Caddy configuration examples
├── gost/                   # gost proxy manager configuration
└── hosts-local             # example hosts file for local YAML presets

Files under third-party are not embedded in applications as static assets. They are configuration examples for external components that can be adapted to a specific environment.

hosts-local demonstrates how to map local mirror domains to the test environment. If needed, entries from this example can be added to the system /etc/hosts file.

Applications ​

The project contains three Famir applications. Each application has a directory under src, a composition module, and a loader that connects infrastructure dependencies and manages startup.

console-app ​

console-app provides the platform administration interface. 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 system functions and Famir entities such as campaign, proxy, target, redirector, lure, session, and message. Loaders connect required dependencies, including configuration, logging, and the database.

YAML presets are located in assets/console. During the build, their contents are included in the console-app assets. This allows the application to load presets without reading the original YAML files at runtime.

text
src/console/
├── loaders/
│   ├── cli.ts            # CLI variant startup
│   └── net.ts            # network variant startup
├── assets.ts             # generated from assets/console
├── main.ts               # controller and service registration
└── preload.ts            # process initialization

assets/console/
├── *.yaml                # YAML presets
└── banner-greet.txt      # text resource

reverse-app ​

reverse-app accepts and processes HTTP traffic forwarded by the external edge server. Its loader connects the HTTP server and client, database, task queue, and other required infrastructure components.

The main.ts module composes the reverse-processing controllers and registers tenant hooks. Hooks are located in src/reverse/tenants and connected to the reverse application through a tenant switch. A hook can apply to the corresponding tenant and target.

HTML pages and other static resources for the reverse application are stored in assets/reverse. In the demo project, resources can be grouped by website or purpose. During the build, they are included in generated src/reverse/assets.ts.

text
src/reverse/
├── loaders/
│   └── std.ts            # reverse-app startup
├── tenants/
│   ├── index.ts          # tenant hook exports
│   └── *.ts              # individual tenant hooks
├── assets.ts             # generated from assets/reverse
├── main.ts               # controller and tenant switch composition
└── preload.ts            # process initialization

assets/reverse/
├── <tenant>/             # resources for an individual website or tenant
└── *.html, *.txt, *.ico  # shared static files

YAML presets configure campaigns and targets, while hooks implement additional programmable behavior. Static HTML and other files are separate reverse-app assets and do not replace hook code.

actions-app ​

actions-app performs background task processing. In the demo project, it runs workers that consume jobs from BullMQ queues, including analysis and webhook workers.

The loader registers database, object storage, producer and consumer components, and workers before starting the application. The assets/actions directory stores static files for this application.

text
src/actions/
├── loaders/
│   └── std.ts            # actions-app startup
├── assets.ts             # generated from assets/actions
├── main.ts               # controller and service registration
└── preload.ts            # process initialization

assets/actions/
└── ...                   # static resources

Build and run ​

Preparation ​

Install dependencies:

sh
npm install

Create a local environment file:

sh
cp .env.example .env

Configure .env for your infrastructure, including Redis and object storage connection settings. Then build the project:

sh
npm run build

The build command first generates TypeScript modules containing static assets and then compiles TypeScript into the dist/ directory.

Running with npm run ​

Each application can be started separately:

sh
# Reverse proxy application
npm run start:reverse-std

# Console Cli application
npm run start:console-cli

# Console Net application
npm run start:console-net

# Background workers and task processing
npm run start:actions-std

The console-app Cli variant is intended for interactive administration commands. The Net variant runs console as a TCP server. reverse-app handles incoming traffic, while actions-app executes background tasks.

Running with PM2 ​

Create a PM2 configuration from the example:

sh
cp pm2.config.cjs.example pm2.config.cjs

The example configures three applications:

  • console — Net variant of console-app;
  • reverse — reverse-app;
  • actions — actions-app.

Start the applications:

sh
pm2 start pm2.config.cjs

Check process status and view logs with:

sh
pm2 status
pm2 logs

Standard PM2 commands can be used to manage processes:

sh
pm2 restart all
pm2 stop all

The PM2 configuration uses .env and separate preload modules for each application.

Building the Docker image ​

Build the Docker image from the repository root:

sh
docker build -t famir-demo:latest .

The Dockerfile installs the required system dependencies, builds the project, and creates a production image containing the applications and runtime dependencies.

Running with Docker Compose ​

After building the image, start the services:

sh
docker compose up -d

The Compose configuration starts the Famir applications and supporting infrastructure, including Redis, object storage, and the edge server. Before startup, review the Compose file and adjust environment variables, domains, ports, and component configuration paths for your environment.

Check service status and inspect output with:

sh
docker compose ps
docker compose logs -f

Stop the services with:

sh
docker compose down

Logs ​

By default, the demo project writes logs to the logs/ directory, organized by application:

text
logs/
├── console/
├── reverse/
└── actions/

The log directory can be changed with the LOGGER_BASE_PATH environment variable.

When running with Docker, logs are stored inside the containers. Configure a Docker volume or bind mount for the log directory if logs need to survive container removal or recreation.