Getting Started with ChatAPI#
Welcome to ChatAPI! This guide will help you get up and running with your own chat service instance.
Prerequisites#
Before you begin, ensure you have the following installed:
- Go 1.21 or later - Download from golang.org
- Git - For cloning the repository
- SQLite3 (optional) - For CGO builds with native SQLite driver
Installation#
1. Clone the Repository#
git clone https://github.com/Byabasaija/chatapi.git
cd chatapi2. Install Dependencies#
go mod download3. Build the Application#
# Build with modernc SQLite driver (recommended)
go build -o bin/chatapi ./cmd/chatapi
# Or build with CGO SQLite driver (if you have SQLite3 installed)
CGO_ENABLED=1 go build -o bin/chatapi ./cmd/chatapiConfiguration#
ChatAPI uses environment variables for configuration. Create a .env file or set them directly:
# Server configuration
export LISTEN_ADDR=":8080"
export DATABASE_DSN="file:chatapi.db?_journal_mode=WAL&_busy_timeout=5000"
# Optional: Database directory
export DATA_DIR="./data"
# Optional: Logging level
export LOG_LEVEL="info"Configuration Options#
| Variable | Default | Description |
|---|---|---|
LISTEN_ADDR | :8080 | Server listen address |
DATABASE_DSN | file:chatapi.db | SQLite database connection string |
DATA_DIR | ./ | Directory for data files |
LOG_LEVEL | info | Logging level (debug, info, warn, error) |
WAL_AUTOCHECKPOINT | 1000 | WAL checkpoint frequency |
RETRY_MAX_ATTEMPTS | 5 | Max delivery retry attempts |
RETRY_INTERVAL | 30s | Retry interval |
WORKER_INTERVAL | 30s | Background worker interval |
SHUTDOWN_DRAIN_TIMEOUT | 10s | Graceful shutdown timeout |
Running ChatAPI#
Start the Server#
./bin/chatapiYou should see output similar to:
2025/12/13 12:00:00 Starting ChatAPI server addr=:8080
2025/12/13 12:00:00 Starting delivery worker interval=30s
2025/12/13 12:00:00 Starting WAL checkpoint worker interval=5m0s
2025/12/13 12:00:00 Starting HTTP server addr=:8080Health Check#
Verify the server is running:
curl http://localhost:8080/healthExpected response:
{
"status": "ok",
"uptime": "1m30s",
"db_writable": true
}Next Steps#
Now that you have ChatAPI running, you can:
- Create a Tenant - Set up your first tenant with API keys
- Create Rooms - Start creating chat rooms
- Send Messages - Begin messaging
- Integrate WebSockets - Add real-time functionality
Development Mode#
For development with live reloading:
# Run with debug logging
export LOG_LEVEL="debug"
./bin/chatapi
# Or use air for hot reloading (if installed)
airTroubleshooting#
Common Issues#
Port already in use:
# Change the port
export LISTEN_ADDR=":3000"Database permission errors:
# Ensure write permissions to data directory
mkdir -p ./data
chmod 755 ./dataBuild errors:
# Clean and rebuild
go clean
go mod tidy
go build ./cmd/chatapiLogs#
Check the structured JSON logs for debugging:
./bin/chatapi 2>&1 | jq .For more help, check the troubleshooting guide or open an issue.