Architecture
How Carrier is put together, and why. This page explains the design. For how to build on it, see menus, modules and doors.
One process, one fiber per caller
Carrier runs the whole board in a single PHP process. Every listener (telnet, SSH, rlogin, web) runs on the same Revolt event loop through Amp v3, and every caller gets their own fiber.
A listener accepts a socket and starts the caller's fiber with Amp\async()
(TelnetServer.php). Inside that fiber,
module code blocks the way a 1990s BBS program did:
$handle = $terminal->ask('Handle: ');ask() suspends only this caller's fiber until a line arrives. The loop keeps serving every
other node in the meantime. There are no callbacks and no promises in module code.
Because every session lives in the same memory, features that need shared storage on other BBS software are plain function calls here:
| Feature | Where it lives | Mechanism |
|---|---|---|
| Who's online, node lookup | NodeManager $sessions |
array of Session, keyed by node number |
| Node messages and pages | NodeManager::send(), broadcast() → Session::notify() |
queues a NodeMessage and cancels the caller's interruptible key wait |
| Teleconference | App\Support\ChatRoom (#[Singleton]) |
each member registers a closure that prints a line on their screen |
| Door seat limits | DoorManager |
counts current players in memory |
The trade-off is that all callers share one process. A fatal error or a blocking call (a
synchronous sleep(), a slow non-Amp HTTP client) affects every node. Wrap blocking work in
Amp\delay(), Amp clients or amphp/process. External doors run as child processes for this
reason (see doors).
Boot path
carrier require vendor/autoload.php
└─ Carrier::console(__DIR__) ConsoleApplication::boot(root, name: 'carrier', loadBuiltInCommands: false)
└─ Tempest::boot() container, config files, discovery
└─ ->run() dispatches the console command (serve, migrate, user:create …)Carrier::console() is one line. It hands the root directory to
Tempest's ConsoleApplication::boot(). Because a name is passed, Tempest keeps its internal
storage (discovery cache, logs) in .carrier/. That path is relative, so Tempest creates it
in the current working directory. Run php carrier from the project root.
Tempest then:
- Loads every
*.config.phpfile it finds. Each returns a config object (BbsConfig,ServersConfig,DoorsConfig,SQLiteConfig,BoardConfig), which the container injects wherever a class asks for that type. The framework ships no config files of its own, so a class with no config file gets its constructor defaults. See configuration. - Runs discovery: it reflects every class in every discovery location and passes each one to every discovery class.
- Registers what discovery found (commands, event handlers, migrations, Carrier's own registries below).
php carrier discovery:status --show-locations lists the locations. In a board made from the
starter project they are the 15 vendor/tempest/*/src packages, vendor/carrier/framework/src
and ./app. In this repository ./app is replaced by the three kit folders described below.
Framework, kits and the starter project
| Package | Directory here | Namespace | Contains |
|---|---|---|---|
carrier/framework |
packages/framework/src |
Carrier\ |
transports, terminal, art, menus, ACS, doors, accounts, console commands, the install command |
(inside carrier/framework) |
packages/framework/kits/* |
App\ once installed |
the board, as files to copy: see kits |
carrier/app |
skeleton/ |
App\ |
the starter project: composer.json, carrier, .env.example, empty app/ |
A new board is a copy of the starter project. Its post-create scripts run php carrier install board and php carrier install web, which copy those kits into app/ and resources/. From
then on the files belong to the board. composer update upgrades the framework and never
touches them.
This repository is the development monorepo, the way tempestphp/tempest-framework and
laravel/framework are. Its root composer.json (carrier/monorepo) installs the framework from
a Composer path repository ("url": "packages/framework", "symlink": true), so edits to
packages/framework/src take effect without composer update. It maps App\ onto
packages/framework/kits/{board,web,games}/app/, and resources/ and doors/ hold symlinks
into the kits. So php carrier serve in the root runs every kit straight from its source.
php carrier install refuses to run here.
Accounts belong to the framework: Carrier\Auth\User and its
migration (2026-11-28_000001_create_users_table). Everything else stored in the database
(messages, mail, oneliners, polls, door scores) belongs to the app. See data.
Discovery
Carrier adds five discovery classes to Tempest's. Each follows Tempest's IsDiscovery pattern:
discover() collects matching classes or methods, apply() registers them once discovery ends.
| Discovery class | Finds | Registers with |
|---|---|---|
MenuDiscovery |
instantiable classes implementing Carrier\Menu\Menus |
MenuRegistry::addDefinitions(). The registry calls define() on first use, not at boot. |
DoorDiscovery |
classes with #[Door] |
DoorManager::register() with DoorDefinition::fromAttribute() |
DisplayCodeDiscovery |
public methods with #[DisplayCode('XX')] |
Mci::register(); the method is called through the container with session: |
AccessCheckDiscovery |
public methods with #[AccessCheck('XX')] |
Acs::extend(); called with session:, number: and list: |
WebRouteDiscovery |
public methods with #[Get('/path')] |
WebRoutes::add('GET', …); called with request: |
Tempest's own discovery handles the rest of the app's code:
| You write | Tempest discovery |
|---|---|
#[ConsoleCommand] methods |
ConsoleCommandDiscovery |
#[EventHandler] methods, e.g. CallLog |
EventBusDiscovery |
MigratesUp classes |
MigrationDiscovery |
DatabaseSeeder classes |
SeederDiscovery |
#[Singleton] classes, initializers |
container discoveries |
Discovery reflects every class in app/ and the framework's src/ at boot. A class that fails to
load (a parse error, a missing interface) therefore stops php carrier serve at startup with
an error. It does not surface later as a crash in the middle of one caller's session, after
other callers have connected. Keep it that way: don't require PHP files at runtime from
modules.
Connection lifecycle
sequenceDiagram
participant L as Listener (TelnetServer, SshServer, RloginServer, WebServer)
participant C as Connection
participant N as NodeManager
participant P as Pipeline middleware
participant M as MenuRunner
participant X as Module / door
L->>C: accept socket, async fiber
C->>C: open(): negotiate (telnet options, SSH handshake + auth, rlogin header, websocket hello)
L->>N: serve(connection)
N->>N: allocate node (1..nodes) or "All nodes are busy"
N->>N: new Terminal, new Session
N-->>N: dispatch SessionStarted
N->>P: BbsConfig::$pipeline (BlockAddresses, DetectTerminal, …)
P->>M: run(session, startMenu)
M->>X: module(), door(), call()
X-->>M: Next (menu, back, logoff) or null (redraw)
M->>M: logoff: logoff art or "NO CARRIER"
N-->>N: recordTime, dispatch UserLoggedOut (if logged in), SessionEnded
L->>C: close()Step by step:
- Accept. Each listener implements
Server(name(),address(),start(),stop()).ServerManager::build()creates one per non-null address inServersConfigand hands each the same handler,NodeManager::serve(...). - Connection. The transport wraps the socket in a
Connection: a byte pipe withread(),write(),remoteAddress(),protocol(),isSecure(),info()(aTerminalInfo) andcredentials(). SSH and rlogin collect a handle and password before the session starts; telnet and the web don't. Protocol details are in transports. - Node.
NodeManager::serve()takes the lowest free node number from 1 toBbsConfig::$nodes(default 16). When every node is taken, the caller sees "All N nodes are busy" and is disconnected. - Terminal and session. A
Terminalwraps the connection: pipe and display codes, CP437 conversion, the key decoder, line input. It gets the board's MCI resolver andBbsConfig::$idleTimeout(default 600 seconds). ASessionties the node, terminal, connection and (after login)Usertogether.SessionStartedis dispatched. - Pipeline.
Pipelineruns the classes inBbsConfig::$pipeline, eachhandle(Session $session, Closure $next). A step returns without calling$nextto end the call. The framework default isBlockAddresses(refuses addresses inblockedAddresses) thenDetectTerminal(probes ANSI, size, UTF-8 vs CP437 and CTerm). The app addsShowConnectArt. - Menus. The pipeline's destination is
MenuRunner::run($session, $config->startMenu)(defaultmatrix). The container builds a newMenuRunnerper caller; it keeps that caller's menu history stack. It checks ACS, draws art or a generated screen, reads hotkeys or a lightbar, delivers node messages, and enforces the daily time limit. - Modules and doors.
ModuleRunner::run()resolves the module from the container and callshandle()throughContainer::invoke(). Menu arguments andsession,terminal,argsare passed by name, and anything else is injected. It setsSession::$activity(shown in Who's Online) for the duration. Doors go throughDoorManager::launch(), which enforcesmaxNodesandminMinutesand dispatchesDoorEntered/DoorExited. - Login. A login module calls
Session::login($user). That bumpscalls, stampslastLoginAt, resets the daily minutes on a new day, saves, applies the user's preferences (encoding, colours, baud, theme strings) and dispatchesUserLoggedIn. - Logoff. A
Next::logoff(), a hang-up (Disconnected), running out of time or a kick ends the menu loop. Inserve()'sfinally, the caller's minutes are recorded,UserLoggedOutis dispatched (when someone was logged in), the node is freed andSessionEndedis dispatched.
An uncaught exception in a module is logged as Node N crashed. That caller sees "The system
hit an error and has to drop your call", and the node is freed. Other nodes are not affected.
Events
| Event | Dispatched by | Payload |
|---|---|---|
Carrier\Events\SessionStarted |
NodeManager::serve(), before the pipeline |
$session |
Carrier\Events\UserLoggedIn |
Session::login() |
$session |
Carrier\Door\DoorEntered |
DoorManager::launch() |
$session, $door |
Carrier\Door\DoorExited |
DoorManager::launch(), after the door returns |
$session, $door |
Carrier\Events\UserLoggedOut |
NodeManager::serve() finally, when a user was logged in |
$session |
Carrier\Events\SessionEnded |
NodeManager::serve() finally, always |
$session |
The app's CallLog handles UserLoggedIn and UserLoggedOut.
It records Caller rows for Last Callers and broadcasts "just logged in" and "has left the
building" to the other nodes. App\Support\Activity::mark()
appends flags (P posted, M mailed, D door, O oneliner, V voted, C chat) to the
current call's row.
Limits
| Limit | Setting | Enforced in |
|---|---|---|
| Concurrent callers | BbsConfig::$nodes (default 16; the app reads BBS_NODES) |
NodeManager::allocate() |
| Idle time | BbsConfig::$idleTimeout seconds (default 600) |
Terminal key waits |
| Minutes per day | SecurityLevel::$minutes for the caller's level; 0 means unlimited |
Session::minutesLeft(), MenuRunner::timeIsUp(). Warns at 5 minutes left, logs off at 0. |
| Players per door | DoorDefinition::$maxNodes (0 = no limit) |
DoorManager::launch() |
| Minutes needed to enter a door | DoorDefinition::$minMinutes |
DoorManager::launch() |
| Failed logins | 10 failures from one host (any port) within 10 minutes, then refused until they age out. After 3 failures on one handle, each further attempt on it waits 1, 2, 4 … up to 30 seconds. Every failure waits 1 second before answering. | Authenticator::attempt() |
| Connections per address | ServersConfig::$maxConnectionsPerAddress (default 8, across all transports) |
ConnectionLimiter, in each listener |
| SSH handshakes | ServersConfig::$maxPendingSsh unauthenticated at once (default 32); each must authenticate within $sshLoginGrace seconds (default 60) |
SshServer, SshConnection |
| Unread input | 64 KiB per caller. Listeners stop reading the socket while it is full, and SSH grants window credit only as the session reads, so a flood backs up in the caller's own connection. Input is decoded 4 KiB at a time and typeahead is capped at 1024 keys. | InputBuffer, Terminal |
Shutdown
ServerManager::run() starts every listener, then blocks on Amp\trapSignal([SIGINT, SIGTERM]).
On a signal, it stops the listeners and calls NodeManager::shutdown(). That writes
"The system is going down. Call back soon!" to every node and disconnects it. The normal
finally cleanup then runs for each session.
Logging
Carrier\Log\Logger is a small PSR-3 logger (#[Singleton]):
| Output | When | Format |
|---|---|---|
storage/logs/carrier.log (BbsConfig::storage('logs/carrier.log')) |
always | [Y-m-d H:i:s] LEVEL: message |
| stderr, coloured | during serve, unless --quiet |
H:i:s LEVEL message |
The minimum level comes from the LOG_LEVEL environment variable (default info). Context
values are interpolated into {placeholders}, and an exception context key appends class,
message, file and line.
packages/framework/src
Acs/ ACS parser and evaluator, #[AccessCheck]
Art/ ANSI interpreter, Canvas, renderer, SAUCE, views, MCI display codes, #[DisplayCode]
Auth/ User model, its migration, the throttled Authenticator
Config/ BbsConfig, ServersConfig, SecurityLevel
Console/ Commands: serve, migrate, db:seed, install, user:*, art:*, menu:list, ssh:keygen, make:*, about
Discovery/ the five Carrier discovery classes
Door/ #[Door], DoorDefinition, DoorsConfig, DoorManager, ExternalDoor, drop files, events
Events/ SessionStarted, SessionEnded, UserLoggedIn, UserLoggedOut
Install/ Kit, KitInstaller, the kits as #[Installer] methods
Log/ Logger
Menu/ MenuRegistry, MenuDefinition, MenuOption, Action, Next, MenuRunner, Module, ModuleRunner
Session/ NodeManager, ServerManager, Session, NodeMessage, Middleware/ (BlockAddresses, DetectTerminal)
Support/ Pipeline
Terminal/ Terminal, TerminalInfo, Attr, ColorMode, PipeCodes, Cp437, InputDecoder, Key, Widgets/
Theme/ Theme, ThemeManager
Transport/ Connection, Server, Telnet/, Ssh/, Rlogin/, Web/
Web/ #[Get], WebRoutes