# Appwrite Backend Platform

> Self-hosted Appwrite backend-as-a-service with databases, auth, storage, and functions.

- Category: Full Web Stacks
- Difficulty: advanced
- Components: appwrite, mariadb, redis, influxdb, telegraf
- Tags: appwrite, backend, auth, storage, functions, realtime
- Source: https://docker.recipes/full-stacks/appwrite-stack

## Overview

Appwrite is an open-source Backend-as-a-Service (BaaS) platform that provides developers with a complete set of APIs and tools for building modern applications. Originally created to simplify backend development, Appwrite offers authentication, database management, file storage, cloud functions, and real-time capabilities through a unified platform with SDKs for web, mobile, and server-side applications. This comprehensive stack combines Appwrite with MariaDB for robust relational data storage, Redis for high-performance caching and session management, InfluxDB for time-series analytics and monitoring data, and Telegraf for metrics collection and forwarding. The integration creates a production-ready backend infrastructure that handles user management, data persistence, real-time subscriptions, and comprehensive monitoring without requiring separate service configurations. This configuration is ideal for development teams building modern web applications, mobile apps, or SaaS platforms who need enterprise-grade backend capabilities without the complexity of managing individual microservices. The combination provides everything from user authentication and database operations to real-time features and system monitoring in a single deployable stack.

## Features

- Multi-database authentication with OAuth providers, email/password, phone, and anonymous login support
- Real-time subscriptions and WebSocket connections for live data updates across clients
- File storage with automatic image transformations, compression, and CDN capabilities
- Cloud Functions runtime supporting multiple programming languages with event triggers
- MariaDB with Aria storage engine for enhanced crash recovery and improved performance
- Redis-powered session management and real-time collaboration features
- InfluxDB integration for application analytics, user behavior tracking, and performance metrics
- Telegraf-based system monitoring with StatsD protocol support for custom metrics

## Use cases

- Mobile app backends requiring authentication, push notifications, and offline-first data sync
- SaaS applications needing multi-tenant user management with role-based access control
- Real-time collaboration platforms with live document editing and user presence indicators
- IoT applications collecting sensor data with time-series analysis and alerting capabilities
- E-commerce platforms requiring user accounts, product catalogs, and order management
- Content management systems with file uploads, image processing, and user-generated content
- Gaming backends with leaderboards, user profiles, and real-time multiplayer features

## Prerequisites

- Minimum 4GB RAM (2GB for Appwrite, 1GB for MariaDB, 512MB for Redis, 512MB for InfluxDB)
- Docker Engine 20.10+ and Docker Compose 2.0+ installed on the host system
- Ports 80 and 443 available for Appwrite web console and API access
- Basic understanding of REST APIs, authentication flows, and database concepts
- SSL certificate for production deployments with custom domains
- Understanding of time-series data concepts for InfluxDB analytics features

## docker-compose.yml

```yaml
services:
  appwrite:
    image: appwrite/appwrite:1.4
    container_name: appwrite
    volumes:
      - appwrite_uploads:/storage/uploads
      - appwrite_cache:/storage/cache
      - appwrite_config:/storage/config
      - appwrite_certs:/storage/certificates
      - appwrite_functions:/storage/functions
    ports:
      - "80:80"
      - "443:443"
    environment:
      - _APP_ENV=production
      - _APP_LOCALE=en
      - _APP_CONSOLE_WHITELIST_ROOT=enabled
      - _APP_CONSOLE_WHITELIST_EMAILS=
      - _APP_CONSOLE_WHITELIST_IPS=
      - _APP_SYSTEM_EMAIL_NAME=Appwrite
      - _APP_SYSTEM_EMAIL_ADDRESS=team@appwrite.io
      - _APP_SYSTEM_SECURITY_EMAIL_ADDRESS=security@appwrite.io
      - _APP_OPTIONS_ABUSE=enabled
      - _APP_OPTIONS_FORCE_HTTPS=disabled
      - _APP_OPENSSL_KEY_V1=${APPWRITE_KEY}
      - _APP_DOMAIN=localhost
      - _APP_DOMAIN_TARGET=localhost
      - _APP_REDIS_HOST=redis
      - _APP_REDIS_PORT=6379
      - _APP_DB_HOST=mariadb
      - _APP_DB_PORT=3306
      - _APP_DB_SCHEMA=appwrite
      - _APP_DB_USER=${MARIADB_USER}
      - _APP_DB_PASS=${MARIADB_PASSWORD}
      - _APP_INFLUXDB_HOST=influxdb
      - _APP_INFLUXDB_PORT=8086
      - _APP_STATSD_HOST=telegraf
      - _APP_STATSD_PORT=8125
    depends_on:
      - mariadb
      - redis
      - influxdb
    networks:
      - appwrite-network

  mariadb:
    image: mariadb:10.11
    container_name: appwrite-mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
      - MYSQL_DATABASE=appwrite
      - MYSQL_USER=${MARIADB_USER}
      - MYSQL_PASSWORD=${MARIADB_PASSWORD}
    volumes:
      - mariadb_data:/var/lib/mysql
    networks:
      - appwrite-network

  redis:
    image: redis:7-alpine
    container_name: appwrite-redis
    volumes:
      - redis_data:/data
    networks:
      - appwrite-network

  influxdb:
    image: influxdb:1.8
    container_name: appwrite-influxdb
    volumes:
      - influxdb_data:/var/lib/influxdb
    networks:
      - appwrite-network

  telegraf:
    image: appwrite/telegraf:1.4
    container_name: appwrite-telegraf
    networks:
      - appwrite-network

volumes:
  appwrite_uploads:
  appwrite_cache:
  appwrite_config:
  appwrite_certs:
  appwrite_functions:
  mariadb_data:
  redis_data:
  influxdb_data:

networks:
  appwrite-network:
    driver: bridge
```

## .env

```bash
# Appwrite Backend
APPWRITE_KEY=your-secret-key-min-128-bits
MARIADB_ROOT_PASSWORD=rootpassword
MARIADB_USER=appwrite
MARIADB_PASSWORD=appwrite_password
```

## Usage notes

- Console at http://localhost
- Create account on first visit
- SDKs available for web, mobile, server
- Supports OAuth providers
- Built-in realtime subscriptions

## Troubleshooting

- Appwrite console shows 'Database connection failed': Verify MariaDB container is running and MARIADB_USER/MARIADB_PASSWORD environment variables match database credentials
- Redis connection errors in Appwrite logs: Check Redis container health and ensure _APP_REDIS_HOST points to 'redis' service name in Docker network
- InfluxDB metrics not appearing: Confirm _APP_INFLUXDB_HOST and _APP_STATSD_HOST environment variables are correctly set to container names
- File upload failures with storage errors: Ensure appwrite_uploads volume has proper write permissions and sufficient disk space available
- Appwrite functions not executing: Verify appwrite_functions volume is mounted and Docker daemon allows container-in-container execution
- MariaDB startup fails with 'Lock wait timeout exceeded': Increase innodb_lock_wait_timeout or restart MariaDB container to clear locked transactions

