Docker & Deployment
Docker & Deployment
Gova uses a containerized architecture to ensure consistency across development and production environments. The backend consists of a FastAPI application, a PostgreSQL database with vector support, and a Kafka message broker for handling moderation events.
Prerequisites
Before deploying, ensure the following are installed on your host machine:
- Docker (Engine 20.10+)
- Docker Compose (v2.0+)
- PgVector: The database requires the pgvector extension for storing and querying moderation embeddings.
Local Development
For development, use the provided docker-compose.yaml to spin up the entire stack including the API, database, and message brokers.
-
Clone the repository and enter the directory:
git clone https://github.com/JadoreThompson/gova-backend.git cd gova-backend -
Configure Environment Variables: Create a
.envfile in the root directory. See the Configuration section for required variables. -
Start the services:
docker-compose up --buildThe API will be accessible at
http://localhost:8000by default.
Configuration
Gova relies on environment variables to manage third-party integrations (Discord, Stripe, Kafka).
| Variable | Description |
| :--- | :--- |
| DATABASE_URL | PostgreSQL connection string (must support PgVector). |
| KAFKA_BOOTSTRAP_SERVERS | Address of the Kafka broker(s). |
| STRIPE_PRICING_PRO_PRICE_ID | The Stripe Price ID for the "Pro" subscription tier. |
| DOMAIN / SUB_DOMAIN | The base domain (e.g., gova.chat) and subdomain for callbacks. |
| SCHEME | Connection protocol (http or https). |
| CUSTOMER_SUPPORT_EMAIL | Destination for messages sent via the Public Contact form. |
| ENCRYPTION_KEY | Key used by the EncryptionService to secure OAuth payloads. |
Production Deployment
The Dockerfile is a multi-stage build optimized for production. It separates the build environment from the runtime environment to minimize the image size and attack surface.
Build Stages
- Builder: Installs build dependencies and compiles Python wheels.
- Runtime: A slim Python image containing only the necessary packages and the
srccode.
Running the API Runner
The container executes runners/api_runner.py to start the Uvicorn server. In a production environment, you should ensure the following:
- Database Migrations: Run migrations before starting the container to ensure the schema (including
uuidv7defaults andJSONBcolumns) is up to date. - Kafka Topics: Ensure the topic defined in
KAFKA_MODERATOR_EVENTS_TOPICexists and has appropriate retention settings. - SSL/TLS: While the FastAPI app runs via Uvicorn, it is recommended to use a reverse proxy (like Nginx or Traefik) to handle SSL termination.
Scaling Components
The system is designed to scale horizontally:
- API Instances: You can run multiple instances of the
APIRunner. Load balance them using a round-robin or least-connections strategy. - Moderation Workers: The moderation logic is event-driven. You can scale workers consuming from the Kafka
moderator_eventstopic to handle higher message volumes across Discord guilds. - Database: Ensure PostgreSQL is configured to handle the maximum connection pool size defined in your SQLAlchemy
async_sessionsettings.