Skip to main content

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 or pnpm
  • 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 (or 3000 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 the backend/ directory
  • Frontend: npm test or vitest inside the frontend/ directory

๐Ÿ“ฆ Build for Productionโ€‹

  • Frontend:

    npm run build
  • Backend:

    uvicorn app.main:app --host 0.0.0.0 --port 8000

๐Ÿง  Summaryโ€‹

AreaCommand ExampleDescription
Backenduvicorn app.main:appStarts FastAPI server
Frontendnpm run devStarts React dev server
Dockerdocker-compose upRuns both services together

Now you're ready to develop, test and deploy your full stack application! ๐Ÿš€