# ByteBin deployment on Render

This Blueprint deploys the Next.js client, API gateway, private file/LLM/email services, and the chat-history worker. It uses external PostgreSQL, MongoDB Atlas, and managed Kafka so the databases and Kafka broker are not tied to an app container's disk.

## Before creating the Blueprint

Create these external services first:

1. **PostgreSQL (Neon works well for a small demo):** use one database for `client`, `llms-service`, and `chat-worker`. Copy Neon’s pooled connection URI with `sslmode=require`. The Neon Free plan currently includes 1 GB per project and 100 compute-hours per month; compute scales to zero after inactivity, so the first request after idle can be slower. Keep the three application pool limits small, especially if you run multiple app replicas.
2. **MongoDB Atlas:** use one database for `file-service` and `llms-service`. Add the deployed services' network access as required by your Atlas configuration.
3. **Kafka:** create a broker and a SASL/SCRAM user with permission to create and use the `chat.history` topic. Copy the broker list, username, and password. The client and worker use TLS plus SCRAM-SHA-256.

## Create the deployment

1. Push this repository to a Git provider connected to Render.
2. In Render, create a **Blueprint** from the repository and select `render.yaml`.
3. Enter the prompted values for `DATABASE_URL`, `MONGODB_URI`, `KAFKA_BROKERS`, `KAFKA_USERNAME`, `KAFKA_PASSWORD`, `RESEND_API_KEY`, and `EMAIL_FROM`. Set `DATABASE_URL` to the Neon pooled URI only in Render's secret environment-variable field; never commit the URI to Git.
4. Review the service plans and estimated charges before confirming. The Blueprint uses the smallest paid Render plan for its web/private services and always-on worker; Render generates and connects the internal keys and JWT secret.
5. Wait for all services to deploy, then use the `bytebin-client` public URL. The gateway is public; file, LLM, and email services are private to the Render network.

Render generates `JWT_SECRET`, `REPO_SERVICE_API_KEY`, `EMAIL_SERVICE_API_KEY`, and `METRICS_BEARER_TOKEN`, then passes those values to the services that need them. No secret values belong in this file or in Git.

## Optional integrations

- Add `GROQ_API_KEY` and `GEMINI_API_KEY` to the client/LLM service only when you are ready to enable those model features. The deployment setup does not make any model requests.
- Add `NEXT_PUBLIC_FIREBASE_*` values to the client if Firebase sign-in is enabled.
- Add GitHub App and ImageKit settings only if those features are enabled.
- `RESEND_API_KEY` and `EMAIL_FROM` enable welcome-email delivery. Without a valid Resend key, account creation can still succeed, but email delivery is unavailable.

## Important deployment notes

- The web and worker plans are paid because Render free instances sleep or have limited shared hours, and the Kafka consumer needs to stay running to persist saved history. The external databases and Kafka may have free tiers, but they have resource and availability limits.
- The local Grafana/Prometheus/Loki/Alloy stack in `docker-compose.yml` is not deployed by this Blueprint. Render captures each service's stdout/stderr logs in its dashboard.
- Keep the file service and chat worker in the same Render region as the gateway and client. The Blueprint uses Singapore for each service.
- If you change a service name in `render.yaml`, update the references to that name in the other services' `fromService` settings.
