This guide explains how to set up and run the Segflow server on macOS.
First, install MySQL using Homebrew:
brew install mysql
Start MySQL service and enable it to run at startup:
brew services start mysql
Connect to MySQL and create the Segflow database:
mysql -u root
In the MySQL prompt:
CREATE DATABASE segflow;
exit;
Create a .env
file in your project root:
# Required server-side environment variables
DATABASE_URL=mysql://root:@localhost:3306/segflow # MySQL connection string
SEGFLOW_API_KEY=0xdeadbeef # API key for authentication
DATABASE_URL
: MySQL connection string. Format:mysql://username:password@host:port/database
SEGFLOW_API_KEY
: Secret key used to authenticate API requests
Initialize the database schema using Drizzle Kit:
# Install dependencies if you haven't already
bun install
# Push database schema
bun drizzle-kit push
This uses the configuration in drizzle.config.ts
to set up your database tables.
Start the Segflow server:
bun src/server/index.ts
The server will:
- Start on port 3000
- Connect to MySQL using the DATABASE_URL
- Begin processing campaign executions every 100ms
- Listen for incoming API requests
You should see output like:
Server listening on http://localhost:3000
If you can't connect to MySQL:
- Check if MySQL is running:
brew services list
- Verify your connection string:
mysql -u root -h localhost
- If you set a MySQL root password, update DATABASE_URL:
DATABASE_URL=mysql://root:yourpassword@localhost:3306/segflow
If port 3000 is in use:
- Find and stop the conflicting process, or
- Modify the port in
src/server/index.ts
If drizzle-kit push
fails:
- Ensure MySQL is running
- Verify DATABASE_URL is correct
- Confirm the database exists:
mysql -u root -e "SHOW DATABASES;"
- The server runs an execution daemon every 100ms to process campaign flows
- Graceful shutdown is handled for SIGINT and SIGTERM signals
- The server uses Bun's built-in server capabilities for HTTP handling
- Database schema is managed through Drizzle ORM
- Always use a strong SEGFLOW_API_KEY
- In production, ensure MySQL is properly secured with a password
- Consider running behind a reverse proxy for SSL termination
- Keep your
.env
file secure and never commit it to version control
Once your server is running:
- Configure your client to connect using the server's URL and API key
- Create your first campaign configuration
- Push the configuration using the CLI:
bun segflow push
For client configuration and campaign creation, see the main README.md.