Skip to content

alchemy-unifi

Describe a UniFi site’s networks, Wi-Fi, zone-based firewall and local DNS as Effect code, and let Alchemy plan and apply the changes on your console.

alchemy.run.ts
import * as UnifiNetwork from "@alchemy-unifi/network";
import * as Alchemy from "alchemy";
import * as Effect from "effect/Effect";
export default Alchemy.Stack(
"HomeNetwork",
{ providers: UnifiNetwork.providers(), state: UnifiNetwork.state() },
Effect.gen(function* () {
const cameras = yield* UnifiNetwork.FirewallZone("cameras", { name: "Cameras" });
yield* UnifiNetwork.Network("cctv", {
management: "GATEWAY",
name: "CCTV",
vlanId: 30,
enabled: true,
cellularBackupEnabled: false,
internetAccessEnabled: false,
isolationEnabled: true,
zone: cameras,
ipv4Configuration: { autoScaleEnabled: false, hostIpAddress: "192.168.30.1", prefixLength: 24 },
});
yield* UnifiNetwork.FirewallPolicy("cameras-to-internal", {
name: "Block cameras to internal",
enabled: true,
action: { type: "BLOCK" },
source: { zone: cameras },
destination: { zone: UnifiNetwork.FirewallZone.INTERNAL },
ipProtocolScope: { ipVersion: "IPV4_AND_IPV6" },
loggingEnabled: false,
});
}),
);
  • Networks: VLANs, DHCP and zone membership.
  • Wi-Fi: SSIDs and their security.
  • Local DNS: records and forwarded domains on the gateway.
  • UniFi Network 10.6 with the zone-based firewall. The provider tracks the latest stable Network release, and warns when a console runs another version.
  • Node 22 or later, Alchemy 2 (beta) and Effect 4.

For a real-world config, see home-network: two sites sharing one stack, with zones, networks, Wi-Fi, a full firewall matrix and the state store on the console.