# Fly.io

### Quick Start Prerequisites

Before exploring FormSG on Fly.io:

* [ ] **Fly.io account** with CLI installed (optional - for your own deployment)
* [ ] **Basic Docker knowledge** (helpful for understanding the setup)

### FormSG Demo Architecture

This demo shows how FormSG can be adapted for the Fly.io platform:

#### Fly.io Implementation

FormSG components in this demo setup:

* **Application**: Single container running on Fly.io infrastructure
* **Database**: External MongoDB instance
* **Object Storage**: External storage service
* **Email Service**: External SMTP provider
* **Monitoring**: Basic Fly.io platform monitoring

### 🌟 Live FormSG Demo

**Try it now**: [form.demos.sg](https://form.demos.sg) - A working FormSG instance you can explore immediately

#### What the Demo Demonstrates

The FormSG Fly.io demo showcases:

* **Platform deployment** - FormSG running on Fly.io infrastructure
* **Overlay architecture** - How to customize FormSG for different contexts
* **Platform adaptation** - FormSG adapted for container deployment
* **Development workflow** - Clean development and deployment patterns
* **Live example** - Working system you can test and explore

#### Getting Started

{% tabs %}
{% tab title="Quick Start" %}
**Repository**: [opengovsg/formsg-on-fly](https://github.com/opengovsg/formsg-on-fly)

```bash
# 1. Clone the template
git clone https://github.com/opengovsg/formsg-on-fly.git
cd formsg-on-fly

# 2. Install dependencies
# Install "just" command runner (macOS)
brew install just

# Or install "just" (other platforms)
# See: https://github.com/casey/just#installation

# 3. Set up the environment
just setup

# 4. Start development server
just start
```

**Local testing**: Application runs at `http://localhost:5000`
{% endtab %}

{% tab title="Configuration" %}
**Essential Settings** (configure in your Fly.io app):

**External Services** (required):

* **MongoDB**: Atlas cluster or external MongoDB instance
* **Object Storage**: Cloudflare R2, AWS S3, or compatible service
* **Email SMTP**: For OTP delivery and notifications

**Environment Variables** (set via `fly secrets`):

* Database connection string
* Storage service credentials
* SMTP configuration
* Application domain settings

**Fly.io App Setup**:

```bash
# Create Fly.io app
fly apps create your-formsg-app

# Set secrets
fly secrets set DB_HOST="mongodb+srv://..."
fly secrets set SES_USER="smtp-username"
...
```

{% endtab %}

{% tab title="Deployment" %}
**Deploy to Fly.io**:

```bash
# Deploy your configured app
fly deploy

# Check deployment status
fly status

# View application logs
fly logs
```

**Post-Deployment**:

1. **Verify deployment**: Check `fly status` for healthy instances
2. **Test application**: Visit your Fly.io app URL
3. **Configure domain**: Point your domain to Fly.io app
4. **Test functionality**: Login, create forms, test submissions

**Scaling Configuration**:

* Fly.io automatically scales based on traffic
* Configure regions via `fly.toml` for global distribution
* Monitor usage via Fly.io dashboard
  {% endtab %}
  {% endtabs %}

#### Fly.io Template Documentation

For detailed configuration and advanced features:

* **Repository**: [FormSG on Fly.io](https://github.com/opengovsg/formsg-on-fly)
* **Live Demo**: [form.demos.sg](https://form.demos.sg)
* **Fly.io Docs**: [Platform Documentation](https://fly.io/docs/)

{% hint style="success" %}
**Best For**: Learning FormSG capabilities, understanding platform adaptation patterns, or experimenting with your own FormSG instance.
{% endhint %}

### Exploring the Demo

**Try the live demo first**: Visit [form.demos.sg](https://form.demos.sg) to explore FormSG features

**If deploying your own instance**:

1. **Check deployment**: `fly status` shows healthy instances
2. **Test functionality**:
   * [ ] Login with email OTP
   * [ ] Create a test form
   * [ ] Submit form as user

**Issues?** Check `fly logs` for application logs.

{% hint style="success" %}
**🎉 Success!** You've explored FormSG on Fly.io and understand how it can be adapted for different platforms.

**Next steps**:

* Try the live demo at [form.demos.sg](https://form.demos.sg)
* Explore the overlay architecture in the repository
* Consider how this approach might work for your deployment needs
  {% endhint %}
