HW4: Backend + Frontend

CMU 15-113: Effective Coding with AI

Due Date: Sun. 9/27 at 8:00 PM
Time Estimate: up to about 6 hours
Deliverables: Backend deployed on Render + backend and frontend code, README, and key prompts on GitHub + short video + brief form response

Assignment Overview

Goal: Build a simple backend service on Render.com and integrate it with your portfolio website or a GitHub Pages site. This assignment teaches you how to build server-side code that handles operations that are better done on the backend (like using APIs securely, storing data, or processing user input).

Why This Matters: Many features are best implemented on the backend because: (1) you can keep API keys and secrets secure, (2) you can process and store data safely, (3) you can do computationally intensive work, and (4) you can validate user input before using it. This assignment teaches you to identify when a backend is useful and how to build one quickly using AI.

Examples of what you might build:

See the course website for an example: check out this Carnegie Chat example, which uses a Python backend on Render to power an AI chatbot.

Tutorial: Watch this first!

This video walks through the steps for getting an example up and running on Render. We strongly recommend you watch this first so that you can see what steps you should take, and so that you can get some inspiration for how to prompt for what you need. Your code will be different, so focus on capturing the main ideas, and refer back to HW3 for help with APIs.

Requirements & Scoring

What You Must Submit

Privacy and Security: Once again, do not commit API keys, credentials, or secrets to GitHub. Keep all secrets on the Render backend using environment variables or an uploaded secret file that is not in your repository. We will not accept submissions that expose private keys publicly. Watch the tutorial video for information on how to do this.

Grading

You'll receive full credit for submitting a working backend-frontend integration with clear documentation and clean communication: Your frontend should make requests to your backend and display the results or confirm that the request was handled successfully. It should handle errors gracefully. Focus on core functionality and clean communication between frontend and backend rather than UI polish.

Detailed Instructions

  1. Choose what your backend will do. Decide on something interesting that requires server-side logic: handle authentication, process data, call a third-party API securely, store information, etc.
Focus on functionality: For this assignment, prioritize getting the backend and frontend working together over adding lots of features and polishing the UI or user experience. Don't spend much time on design details. Later in the course (Project 2), we'll bring together your knowledge of frontends, APIs, and backends into one really polished project. For that and any future work, you can either build on earlier assignments in this class or start fresh with an entirely new idea, as long as your work meets the assignment specifications.
A caution on scope: Last semester's class rated this assignment noticeably harder than HW3, and the difficulty usually came from the platforms rather than the code. You may treat this as the seed of your Project 2 (which we officially begin next week), but we'd suggest aiming for something interesting without being exceptionally complex here, and saving the ambitious idea for the project itself. Every additional service you glue on is one more place to get stuck. A few comments from last semester's students:
  • "Setting up auth and database was tricky and AI wasn't super helpful."
  • "It's harder when it involves jumping between different services, especially for the database configuration part."
  • "Honestly, the hardest part for me was understanding how ports worked and how to run things locally. Otherwise, I found AI to be pretty helpful in understanding how the backend should connect to the front end. It just struggled to tell me why."
  1. Write your backend. We recommend using Python with Flask, but you may also use FastAPI or another backend framework, or you may use a different language altogether. Use AI tools to help you write the code. Make sure your backend:
    • Has at least one endpoint that accepts data and returns a meaningful response
    • Handles any API keys or secrets using environment variables or a secret file that is not present on your repo or your frontend
    • Returns JSON or another structured format that your frontend can use
  2. Deploy your backend to Render. Create a free account at render.com, create a new Web Service, connect your GitHub repo, and deploy. Render will give you a public URL (e.g., https://my-backend.onrender.com).
  3. Write your frontend. Create an HTML/CSS/JavaScript page (on your portfolio or a new repo) that:
    • Makes requests to your backend using fetch() or another HTTP client
    • Displays the responses nicely (or provides confirmation that the request was handled)
    • Handles errors (e.g., if the backend is down or the user provides bad input)
  4. Test end-to-end. Make sure your frontend can call your backend and display real results. Test error cases too (e.g., what happens if the user submits an empty form).
  5. Document everything. Write a clear README explaining what your backend does, how to run it locally, how the frontend calls it, and where secrets are stored.
  6. Push both repos to GitHub (backend + frontend) and fill out the Google form with your Render URL and GitHub repos before the deadline.
  7. Make your video and upload it, and fill out the google form before the deadline.

Testing Locally

Get everything working on your own machine before you deploy. Debugging is much faster locally, and every trip through Render costs you a few minutes of waiting.

  1. Start the backend. Run your backend file (for Flask, usually something like python app.py). It should print a local address such as http://127.0.0.1:5000. Leave that terminal running.
  2. Check that it responds before you involve the frontend at all. Open an endpoint in your browser, or send it a request with curl: curl -X POST http://127.0.0.1:5000/chat -H "Content-Type: application/json" -d '{"message":"Hello"}' If you get JSON back, the backend works, and anything still broken is in the frontend or in the connection between the two. (On Windows, use curl.exe in PowerShell, since plain curl there is a different command and won't accept these options.)
  3. Point your frontend at the local backend. Temporarily replace the Render URL in your JavaScript with your local address, then open your frontend .html file in the browser.
  4. Watch both sides. Errors appear in two different places: the terminal running your backend, and the browser console (right-click, Inspect, Console). Check both, and if you need help ask us or AI (and mention what you found).
  5. Put the Render URL back before you push. Forgetting this is a common way to submit a site that works on your laptop and nowhere else.

One difference to expect: secrets are handled separately in each place. On Render you set environment variables in the dashboard, but locally you'll need to set them in your shell or in a file that your .gitignore excludes.

What is a Backend? Key Concepts

A backend is a program running on a server that your frontend (website) can communicate with. Here are some key ideas:

When you use AI to write your backend, ask it to explain what each endpoint does and how to test it locally.

Tips

Getting Started with Render

Backend Framework Resources

Frontend-Backend Communication

Questions? Ask on Ed, attend office hours, or email the instructor. Consult the course AI usage and collaboration policies on the course homepage.