FastAPI React Starter Project is a boilerplate repository for building full-stack web applications using FastAPI as the backend framework and React as the frontend framework. This project is designed to provide developers with a starting point for modern web application development, supporting separate or unified backend and frontend deployments.
- Quick Start: Offers a ready-to-use structure for full-stack projects, reducing setup time.
- Flexibility: Allows running the backend and frontend separately during development or as a single app in production.
- Scalability: Built with modularity and best practices to make it easy to extend and scale.
- Developer-Friendly: Includes features like CORS support, environment-based configuration, and clear instructions for deployment.
- Backend: FastAPI-powered REST API.
- Frontend: React app with Bootstrap for styling.
- CORS Support: Preconfigured for seamless backend-frontend communication.
- Environment Variables:
.envsupport for flexible configuration. - Unified Deployment: Option to serve the React app directly from FastAPI.
-
Backend Requirements:
- Python (3.9 or higher)
- Virtual environment setup (optional but recommended)
-
Frontend Requirements:
- Node.js (16.x or higher)
- npm or Yarn package manager
-
Clone the Repository
git clone https://github.com/naderzare/fastapi-react-starter.git cd fastapi-react-starter -
Create and Activate a Python Virtual Environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Python Dependencies
pip install -r requirements.txt
-
Run the FastAPI Backend
python -m uvicorn app.main:app --reload
-
Access the Backend
- Open
http://127.0.0.1:8000in your browser. - API documentation is available at
http://127.0.0.1:8000/docs.
- Open
-
Navigate to the
frontendDirectorycd app/frontend -
Install Node.js Dependencies
npm install
-
Run the React Development Server
npm start
-
Access the Frontend
- Open
http://localhost:3000in your browser.
- Open
To serve the React app through FastAPI in production:
-
Build the React App
cd app/frontend npm run buildThis will generate a
buildfolder in thefrontenddirectory. -
Update the
.envFile- Open the
.envfile and set:SERVE_UI=true
- Open the
-
Run the FastAPI App
python -m uvicorn app.main:app --reload
-
Access the Unified App
- Open
http://127.0.0.1:8000in your browser to see the React frontend served by FastAPI.
- Open
fastapi-react-starter/
├── app/
│ ├── main.py # FastAPI app definition
│ ├── database.py # Database configuration
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic schemas
│ ├── logger.py # Custom logger setup
│ ├── frontend/ # React app
│ │ ├── build/ # React build files
│ │ ├── src/ # React source code
│ └── __init__.py
├── requirements.txt # Python dependencies
├── .env # Environment variables
└── README.md # Project documentation
-
Add a User
- POST
/user/add - Request Body:
{ "username": "john_doe", "age": 30 } - Response:
{ "id": 1, "message": "User created successfully" }
- POST
-
Get All Users
- GET
/user/all - Response:
[ { "id": 1, "username": "john_doe", "age": 30 } ]
- GET
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes and push the branch.
- Open a pull request for review.
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions or feedback, feel free to reach out or open an issue in the repository.
- FastAPI React Starter
- Full-stack web development
- FastAPI boilerplate
- React frontend with FastAPI
- Modern web app example