Day 05 Mastery

Deploy the Full Stack App

Local apps are demos. Deployed apps are products. Deploy both frontend and backend to free hosting services and connect them with production environment variables.

~1 hour Hands-on Precision AI Academy

Today's Objective

Your full-stack AI app running live on the internet: FastAPI backend on Railway, React frontend on Vercel, connected via environment variables.


  
code
import os

# Read allowed origins from environment variable
FRONTEND_URL = os.getenv("FRONTEND_URL", "http://localhost:3000")

app.add_middleware(
    CORSMiddleware,
    allow_origins=[FRONTEND_URL],
    allow_methods=["*"],
    allow_headers=["*"]
)
frontend/src/config.js
javascript
// Use environment variable for backend URL
export const API = process.env.REACT_APP_API_URL || 'http://localhost:8000';
01
Section 2 · 15 min

Deploy Backend to Railway

1

Push your backend folder to a GitHub repository (separate from frontend).

2

Go to railway.app → New Project → Deploy from GitHub → select backend repo.

3

In Railway Variables, set: ANTHROPIC_API_KEY and FRONTEND_URL (set to your Vercel URL, which you'll get in the next step — use a placeholder first).

4

Set start command: uvicorn main:app --host 0.0.0.0 --port $PORT. Railway provides the PORT env var automatically.

5

Generate Domain → copy the Railway URL (looks like your-app.up.railway.app).

01
Section 3 · 20 min

Deploy Frontend to Vercel

1

Push your React frontend to GitHub.

2

Go to vercel.com → New Project → Import from GitHub → select frontend repo.

3

In Environment Variables, add: REACT_APP_API_URL = your Railway backend URL.

4

Deploy. Vercel detects Create React App automatically and runs npm run build.

5

Once deployed, copy the Vercel URL and update the FRONTEND_URL variable in Railway. Redeploy Railway.

Two URLs cross-reference each other. Railway needs the Vercel URL for CORS. Vercel needs the Railway URL for API calls. Deploy both with placeholder values first, then update both once you have the final URLs.

100%

Want live instruction and hands-on projects? Join the AI bootcamp — 3 days, 5 cities.

Day 5 Checkpoint

Before moving on, confirm understanding of these key concepts:

  • What is the core concept introduced in this lesson?
  • How does the main technique or tool work in practice?
  • What common mistakes should be avoided?
  • How would this apply in a real-world project?
  • What is the next logical step to build on this knowledge?
Course Complete
Return to Course Overview