π Railway Deployment Guide for TalimBot
π Overview
This guide will help you deploy your complete TalimBot application (Frontend + Backend) to Railway for free, making it accessible from anywhere.
β What We've Done (Preparation Complete!)
1. Restructured the Project
- β
Created
backend/static/folder - β
Moved all frontend files (HTML, CSS, JS, Icons) to
backend/static/ - β
Updated
main.pyto serve static files - β
Updated
data.jsto use relative API paths for Railway
2. Updated FastAPI Configuration
Your backend/main.py now:
- Serves static files from
backend/static/folder - Uses environment variable for OpenRouter API key
- Handles both frontend (HTML pages) and backend (API endpoints) from the same server
- Works seamlessly on Railway's deployment platform
3. Project Structure
talimbot/
βββ .env # LOCAL ONLY - Contains your API key (NEVER commit this!)
βββ .env.example # Template for environment variables
βββ .gitignore # Ensures .env is not committed
βββ Procfile # Tells Railway how to start the server
βββ runtime.txt # Specifies Python version
βββ README.md
βββ RAILWAY_DEPLOYMENT.md
βββ backend/
β βββ main.py # β
UPDATED - Serves static files + API endpoints
β βββ grouping_logic.py
β βββ requirements.txt
β βββ data/
β β βββ students.json
β βββ static/ # β
NEW - All frontend files
β βββ index.html
β βββ assets/ # CSS and JS files
β β βββ css/
β β β βββ styles.css
β β βββ js/
β β βββ data.js # β
UPDATED - Uses relative API paths
β β βββ grouping.js
β βββ pages/ # All HTML pages
β β βββ login.html
β β βββ student-dashboard.html
β β βββ teacher-dashboard.html
β β βββ ams-questionnaire.html
β β βββ cooperative-questionnaire.html
β β βββ group-view.html
β βββ Icons/ # Logo and icons
π Deployment Steps
Step 1: Verify Local Setup
Create
.envfile (if you haven't already):# In the project root (talimbot/) folder echo OPENROUTER_API_KEY=sk-or-v1-your-actual-key-here > .envTest locally:
cd backend python main.pyOpen browser to
http://localhost:8000- You should see the index.html page
- All pages should work (login, dashboards, questionnaires)
- API calls should work (grouping, data saving)
Step 2: Commit Changes to GitHub
β οΈ IMPORTANT: Make sure .env is in .gitignore (it already is!)
# From the talimbot/ directory
git add .
git status # Verify .env is NOT listed (should only see modified files)
git commit -m "Restructure project for Railway deployment - serve frontend from backend"
git push origin main
Step 3: Deploy to Railway
A. Sign Up / Log In
- Go to railway.app
- Click "Start a New Project"
- Sign in with your GitHub account
B. Create New Project
- Click "Deploy from GitHub repo"
- Select your
talimbotrepository - Railway will automatically detect it's a Python project
C. Configure Environment Variables
- In the Railway dashboard, go to your project
- Click on the "Variables" tab
- Click "+ New Variable"
- Add:
- Key:
OPENROUTER_API_KEY - Value:
sk-or-v1-your-actual-openrouter-api-key
- Key:
- Click "Add"
D. Verify Deployment Settings
Railway auto-detects settings from your files:
- β Build Command: None needed (Python dependencies auto-installed)
- β
Start Command: From
Procfileβcd backend && uvicorn main:app --host 0.0.0.0 --port $PORT - β
Python Version: From
runtime.txtβpython-3.11.0
E. Deploy!
- Click "Deploy"
- Wait 2-3 minutes for deployment
- Railway will show deployment logs
- When complete, you'll see: β "Deployment successful"
F. Get Your URL
- In Railway dashboard, click "Settings" tab
- Scroll to "Networking" section
- Click "Generate Domain"
- Copy your URL (e.g.,
https://talimbot-production-abc123.up.railway.app)
Step 4: Test Your Deployed Application
- Open your Railway URL in a browser
- Test all features:
- β
Main page loads (
index.html) - β
Login page works (
/pages/login.html) - β Student dashboard loads
- β Teacher dashboard loads
- β Questionnaires work (AMS, Cooperative)
- β Grouping functionality works
- β Data saves correctly
- β
Main page loads (
π§ How It Works
Single Server Architecture
Railway runs ONE server that handles BOTH:
Frontend (Static Files):
GET /β Servesindex.htmlGET /pages/login.htmlβ Serves login pageGET /assets/css/styles.cssβ Serves CSSGET /assets/js/data.jsβ Serves JavaScript
Backend (API Endpoints):
POST /api/groupingβ AI grouping logicGET /api/studentsβ Get all studentsPUT /api/students/{id}β Update student- All other API routes in
main.py
How Requests Are Routed
User Browser β Railway URL
β
FastAPI Server (main.py)
β
βββββββββββ΄ββββββββββ
β β
/api/* Everything else
(API Endpoints) (Static Files)
β β
grouping_logic.py backend/static/
OpenRouter API (HTML/CSS/JS)
Environment Variable Flow
Local Development:
.env file β load_dotenv() β os.getenv("OPENROUTER_API_KEY")
Railway Production:
Railway Variables β os.getenv("OPENROUTER_API_KEY")
π Monitoring & Management
View Logs
- Go to Railway dashboard
- Click on your project
- Click "Deployments" tab
- Click on the latest deployment
- View real-time logs
Check Usage
- Railway free tier: $5 credit/month
- Your app should use: ~$2-3/month
- Monitor usage in "Usage" tab
Redeploy (After Code Changes)
- Make changes locally
- Test locally (
python main.py) - Commit and push to GitHub:
git add . git commit -m "Your changes" git push origin main - Railway auto-deploys within 1-2 minutes!
π Troubleshooting
Problem: API calls fail (404 errors)
Solution: API routes must start with /api/
- β
Correct:
POST /api/grouping - β Wrong:
POST /grouping
Problem: Static files not loading (CSS/JS missing)
Solution:
- Verify files are in
backend/static/folder - Check browser console for 404 errors
- Ensure paths in HTML are relative (e.g.,
/assets/css/styles.css)
Problem: OpenRouter API errors
Solution:
- Verify API key is correct in Railway Variables
- Check you have credits in your OpenRouter account
- View logs in Railway to see exact error message
Problem: Server won't start
Solution:
- Check Railway logs for error messages
- Verify
requirements.txthas all dependencies - Ensure
Procfilecommand is correct
π― Success Checklist
After deployment, verify:
- Railway URL loads the main page
- All navigation links work
- Login system works (student/teacher)
- Student dashboard loads
- Teacher dashboard loads
- AMS questionnaire works and saves
- Cooperative questionnaire works and saves
- AI grouping creates groups successfully
- Student data persists after refresh
- API calls complete without errors
- No console errors in browser DevTools
π‘ Next Steps
Once deployed successfully:
- Share the Railway URL with your teacher
- Test from different devices (phone, tablet)
- Monitor Railway dashboard for any errors
- Keep your OpenRouter API key secure
- Consider upgrading Railway plan if you exceed free tier
π Support Resources
- Railway Docs: https://docs.railway.app
- OpenRouter Docs: https://openrouter.ai/docs
- FastAPI Docs: https://fastapi.tiangolo.com
- Your Deployment Guide:
RAILWAY_DEPLOYMENT.md
π Congratulations!
Your TalimBot is now a real, independent website accessible from anywhere! π
Your app URL: https://your-project.up.railway.app
Teachers and students can access it from:
- β Home computers
- β School computers
- β Phones (any device with internet)
- β Tablets
No need for localhost, no need for running Python locally - it's fully online! π