This repository contains a skeleton project for building a web application with a SQL database, Express API, and a React webpage using Vite. The project is set up to run in a dev container using Visual Studio Code.
- SQL database using MySQL
- Express API for handling server-side logic
- React webpage with Vite for frontend development
- Dev container configuration for a consistent development environment
- User table displaying user information
- Form to add new users with fields for first name, last name, email, password, address, and age
- Docker installed on your machine
- Visual Studio Code installed on your machine
- Remote - Containers extension installed in Visual Studio Code
-
Clone this repository to your local machine:
git clone https://github.com/washyu/webapp_db_skeleton.git -
Set up the environment variables:
- Create a
.envfile in the root directory of the project. - Add the following variables to the
.envfile:ReplaceDB_HOST=hostname DB_USER=username DB_PASS=password DB_NAME=database_name API_PORT=5000username,password,hostname, anddatabase_namewith your actual database credentials and connection details. Replace 5000 with the port you want the api server listening on.
-
Open the project in Visual Studio Code.
-
When prompted, click on "Reopen in Container" to start the dev container.
-
Wait for the dev container to be built and the dependencies to be installed. This may take a few minutes.
-
Once the dev container is running, open a terminal in Visual Studio Code.
-
In the terminal, navigate to the
serverdirectory and run the following command to start the Express API:npm run dev -
Open another terminal in Visual Studio Code.
-
In the new terminal, navigate to the
clientdirectory and run the following command to start the React development server:npm run dev -
Open your browser and navigate to
http://localhost:3000to view the web application.
The project uses a dev container to provide a consistent development environment. The dev container configuration files are located in the .devcontainer directory.
devcontainer.json: Defines the dev container configuration, including the Docker Compose file to use, the workspace folder, and VS Code settings.Dockerfile: Specifies the base image and additional dependencies for the dev container.
The project also includes a docker-compose.yml file that defines the services required for the application, including the Express API and the MySQL database.
The project follows a typical structure for a web application with a backend API and a frontend React application:
server: Contains the Express API code and related files.config: Configuration files for the database connection.controllers: Controller functions for handling API requests.models: Sequelize models for defining the database schema.routes: Express routes for defining API endpoints.
client: Contains the React webpage code and related files.src: Source code for the React application.components: React components used in the application.
index.html: Main HTML file for the React application.vite.config.js: Configuration file for Vite.
The project uses MySQL as the database. The database connection configuration is located in the server/config/database.js file. Make sure to update the database credentials in this file to match your environment.
The database schema is defined using Sequelize models. The user model is defined in the server/models/userModel.js file.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is open-source and available under the MIT License.