# JChat Deployment Guide ## Quick Start 1. **Deploy locally with domain routing:** ```bash ./deploy.sh ``` 2. **Access the application:** - Web UI: http://web.jchat.localhost - API: http://api.jchat.localhost - Health Check: http://api.jchat.localhost/_health 3. **Run tests:** ```bash ./test_auth.sh ``` ## Configuration ### Development Configuration The application uses a configuration-driven approach. See `server/config/sys.config` for all settings: - **Domains**: `api.jchat.localhost` and `web.jchat.localhost` - **Port**: 8080 (configurable) - **Static Files**: Served from `../client` directory - **Authentication**: JWT with bcrypt password hashing - **Database**: Mnesia (file-based, no external DB required) ### Production Configuration For production deployment: 1. Copy `server/config/sys.config.template` to `sys.config` 2. Set environment variables or edit the file directly: ```bash export HTTP_PORT=80 export API_DOMAIN="api.yourdomain.com" export WEB_DOMAIN="yourdomain.com" export JWT_SECRET="your-secure-secret-key" export STATIC_FILES_DIR="/var/www/jchat" export DATA_DIR="/var/lib/jchat/data" export LOG_LEVEL="info" ``` ## Architecture ``` ┌─────────────────┐ ┌─────────────────┐ │ web.jchat.* │ │ api.jchat.* │ │ (Static Files) │ │ (JMAP API) │ └─────────────────┘ └─────────────────┘ │ │ └───────────┬───────────┘ │ ┌─────────────────┐ │ JChat Server │ │ (Erlang/OTP) │ └─────────────────┘ │ ┌─────────────────┐ │ Mnesia DB │ │ (Embedded) │ └─────────────────┘ ``` ### Domain Routing - **web.jchat.localhost**: Serves static files (HTML, CSS, JS) - **api.jchat.localhost**: Serves JMAP API, authentication, and file uploads - Single server handles both domains with Cowboy routing ### Features - ✅ Domain-based routing - ✅ Configuration-driven deployment - ✅ Static file serving with SPA support - ✅ CORS headers for cross-domain requests - ✅ Health check endpoint - ✅ Environment-specific configuration - ✅ Automated test suite - ✅ No build process required for client - ✅ Embedded database (no external dependencies) ## Development Workflow 1. **Make changes to server code** 2. **Restart with:** `make run` (in server directory) 3. **Make changes to client code** 4. **Refresh browser** (files are served directly) ## Testing ### Manual Testing - Web UI: http://web.jchat.localhost - API Health: http://api.jchat.localhost/_health ### Automated Testing ```bash # HTTP/Auth tests ./test_auth.sh # Erlang unit tests cd server && rebar3 ct ``` ## Deployment Options ### Option 1: Single Server (Recommended for small deployments) - Use `deploy.sh` script - Serves both web and API from same server - Easy SSL setup with reverse proxy ### Option 2: Separate Web Server - Serve static files from nginx/apache - Point API calls to Erlang server - Better for high-traffic deployments ### Option 3: Docker ```bash # Build image docker build -t jchat . # Run container docker run -p 8080:8080 \ -e API_DOMAIN=api.yoursite.com \ -e WEB_DOMAIN=yoursite.com \ jchat ``` ## Monitoring - **Health Check**: `GET /_health` - **Logs**: `server/log/jchat.log` - **Metrics**: Available via health endpoint ## Security Notes 1. **Change JWT secret** in production 2. **Use HTTPS** in production 3. **Configure proper CORS origins** 4. **Set up firewall rules** 5. **Regular backups** of data directory