Full Stack Project Intro
Welcome! This tutorial will help you set up and run a full stack application with a frontend (React) and backend (FastAPI).
๐ ๏ธ Prerequisitesโ
Make sure you have the following installed:
- Node.js (v18+)
- Python (v3.10+)
- Docker (optional but recommended)
- A package manager like
npm
,yarn
orpnpm
- pip (Python package installer)
- Poetry (recommended for backend dependency management)
๐ Project Structureโ
my-project/
โโโ backend/ # FastAPI backend
โ โโโ app/
โ โโโ Dockerfile
โ โโโ pyproject.toml
โโโ frontend/ # React frontend
โ โโโ src/
โ โโโ public/
โ โโโ package.json
โโโ README.md
๐ง Backend Setup (FastAPI)โ
1. Install dependenciesโ
From the backend/
folder:
cd backend
poetry install # or use pip install -r requirements.txt if not using Poetry
2. Run the backendโ
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
Your backend will be available at
http://localhost:8000
You can also use Docker:
docker build -t my-backend .
docker run -p 8000:8000 my-backend
๐ Frontend Setup (React)โ
1. Install dependenciesโ
From the frontend/
folder:
cd frontend
npm install
2. Start the frontendโ
npm run dev # or npm start depending on the setup
Your frontend will be available at
http://localhost:5173
(or3000
if using CRA)
๐ Connecting Frontend to Backendโ
Make sure your frontend fetches data from the correct backend URL:
// Example (frontend/src/api.ts)
const api = axios.create({
baseURL: 'http://localhost:8000/api',
});
In production, use environment variables to configure URLs.
โ Running Both with Docker (Optional)โ
You can use Docker Compose to run both frontend and backend:
# docker-compose.yml (in root)
version: '3.8'
services:
backend:
build: ./backend
ports:
- "8000:8000"
frontend:
build: ./frontend
ports:
- "5173:5173"
docker-compose up --build
๐งช Testingโ
You can run tests for:
- Backend:
pytest
inside thebackend/
directory - Frontend:
npm test
orvitest
inside thefrontend/
directory
๐ฆ Build for Productionโ
-
Frontend:
npm run build
-
Backend:
uvicorn app.main:app --host 0.0.0.0 --port 8000
๐ง Summaryโ
Area | Command Example | Description |
---|---|---|
Backend | uvicorn app.main:app | Starts FastAPI server |
Frontend | npm run dev | Starts React dev server |
Docker | docker-compose up | Runs both services together |
Now you're ready to develop, test and deploy your full stack application! ๐