Railway Deployment Guide
Relevant source files
The following files were used as context for generating this wiki page:
The Railway Deployment Guide outlines the configuration and infrastructure requirements for hosting the GentelmeN-CorE bot on the Railway platform. This project leverages Railway's V2 runtime and Nixpacks-based builder (RAILPACK) to orchestrate a Python-based Telegram bot integrated with PostgreSQL, AI services, and cryptocurrency exchanges.
This guide provides technical specifications for the deployment lifecycle, including build configurations, runtime settings, environment variable dependencies, and the underlying database schema initialized upon deployment.
Infrastructure Configuration
The project uses a structured configuration file to define how Railway should build and execute the application. The deployment is set to use a single replica with a specific restart policy to ensure high availability.
The diagram shows the deployment flow from the configuration file through the builder to the active process.
Build and Deploy Settings
| Parameter | Value | Description |
|---|---|---|
| Builder | RAILPACK | Uses Railway's Nixpacks-based builder to detect environment and install dependencies. |
| Runtime | V2 | Specifies the Railway execution environment version. |
| Start Command | python bot.py | The entry point command to launch the bot. |
| Replicas | 1 | Number of instances running simultaneously. |
| Restart Policy | ON_FAILURE | Restarts the container automatically if the process crashes. |
| Max Retries | 10 | Maximum consecutive restart attempts. |
Sources: railway.json:1-15, bot.py:1-7
Environment Variables
For the application to function correctly on Railway, several environment variables must be configured in the Railway dashboard. These variables handle authentication for Telegram, AI providers (Groq, HuggingFace), and financial integrations (KuCoin).
Required Configuration
| Variable | Usage | Source File |
|---|---|---|
TELEGRAM_TOKEN | Bot API token for Telegram connectivity. | core/bot.py:13 |
GROQ_KEY | API key for Groq Cloud (Llama/Qwen models). | core/bot.py:14 |
DATABASE_URL | Connection string for the PostgreSQL database. | core/database.py:5 |
HF_TOKEN | Token for HuggingFace Inference API (Image generation). | core/integrations.py:7 |
BRAVE_API_KEY | Key for Brave Search API. | core/integrations.py:6 |
ADMIN_ID | Telegram User ID allowed to manage alerts. | core/commands.py:13 |
OWNER_USER_ID | Telegram User ID for balance checks. | core/commands.py:102 |
Optional Integrations
- KuCoin:
KUCOIN_API_KEY,KUCOIN_SECRET,KUCOIN_PASSWORDare required for the/balanceand price monitoring features. - GitHub:
GITHUB_TOKENis used to increase rate limits for the/githubsearch command.
Sources: core/bot.py:13-25, core/commands.py:13-14, core/integrations.py:6-7
Initialization and Runtime Logic
When the bot starts on Railway via python bot.py, it executes a sequence of initialization steps. The entry point uses runpy to execute the core logic located in core/bot.py.
The sequence illustrates the startup delay and database preparation required for a stable deployment.
Startup Delay
The code includes a specific 15-second sleep during startup (time.sleep(15)). This is intended to allow Railway to gracefully close old processes before the new instance begins polling the Telegram API, preventing "Conflict: terminated by other getUpdates request" errors.
Sources: bot.py:1-7, core/bot.py:74-76
Database Schema
Upon deployment, the system automatically initializes a PostgreSQL database using the DATABASE_URL. The schema consists of two primary tables to manage user preferences and price alerts.
Table: users
Stores persistent configuration for individual bot users.
| Column | Type | Constraints | Description |
|---|---|---|---|
user_id | BIGINT | PRIMARY KEY | Unique Telegram identifier. |
username | TEXT | - | User's Telegram handle. |
language | TEXT | DEFAULT 'EN' | Preferred AI response language. |
model_name | TEXT | DEFAULT 'llama...' | Currently selected AI model. |
Table: alerts
Manages the background price monitoring system.
| Column | Type | Constraints | Description |
|---|---|---|---|
id | SERIAL | PRIMARY KEY | Auto-incrementing alert ID. |
user_id | BIGINT | - | Owner of the alert. |
symbol | TEXT | - | Trading pair (e.g., BTC/USDT). |
target_price | NUMERIC | - | Price threshold for notification. |
direction | TEXT | - | 'UP' or 'DOWN'. |
Sources: core/database.py:15-34
Dependency Management
Railway uses the requirements.txt file to build the Python environment. The following core libraries are required for the deployment:
pyTelegramBotAPI: Core bot framework.groq: Interface for LLM completions.ccxt: Cryptocurrency exchange (KuCoin) integration.psycopg2-binary: PostgreSQL adapter for Python.requests: Used for Brave, GitHub, and HuggingFace API calls.
Sources: requirements.txt:1-6
Conclusion
Deploying GentelmeN-CorE to Railway requires a PostgreSQL service and the correct population of API keys in the environment settings. The system is designed for resilience, utilizing an ON_FAILURE restart policy and an automated database initialization routine that ensures the schema is always up-to-date without manual intervention.