Description
Freestyle is an Express.js-based skeleton project with a backend and frontend. It features a database setup using Sequelize, user authentication, and basic CRUD functionality. The frontend is built using React, and it uses Vite for development and production builds.
- Installation
- Usage
- Backend Setup
- Frontend Setup
- API Endpoints
- Database Setup
- Scripts
- Contributing
- License
To install and set up this project locally:
-
Clone the repository:
git clone https://github.com/kellenweagle/freestyle.git
-
Navigate to the project directory:
cd freestyle
-
Install backend dependencies:
npm install --prefix backend
-
Install frontend dependencies:
npm install --prefix frontend
Running Both Backend and Frontend To run the development servers for both the backend and frontend simultaneously:
-
Start the backend:
npm run start-backend
-
Start the frontend:
npm run start-frontend-dev
Both servers will be running locally, with the frontend on http://localhost:3000 and the backend on http://localhost:8000.
Running Backend in Production
-
To start the backend in production mode, run:
npm run start-backend --production
Environment Variables
Ensure you have the following environment variables set up in a .env file:
- DB_URL: URL for your database (PostgreSQL/SQLite)
- JWT_SECRET: Secret for signing JWT tokens
Database Setup
Run the following commands to set up your database with Sequelize:
-
Create the database:
npm run db:create --prefix backend
-
Apply Migrations
npm run db:migrate --prefix backend
-
Seed the database:
npm run db:seed:all --prefix backend
You can also reset the database using:
npm run db:reset --prefix backend
The frontend is built with React and uses Vite as the bundler.
To run the frontend in development mode:
npm run start-frontend-dev --prefix frontend
To build the frontend for production:
npm run build --prefix frontend
To preview the production build:
npm run preview --prefix frontend
Here are the main API routes for the backend:
- Description: Fetch all products
- Response: List of products in JSON format
- Description: Add a new product
- Body:
{ "name": "Product Name", "price": 19.99, "description": "Product description" }
- Response: Newly created product object
- Description: Update an existing product
- Response: Updated product object
- Description: Delete a product by ID
- Response: Success message
npm run start-backend
: Starts the backend server.npm run db:create
: Creates the database.npm run db:migrate
: Runs database migrations.npm run db:seed:all
: Seeds the database with data.npm run db:reset
: Resets the database (drop, create, migrate, seed).
npm run start-frontend-dev
: Runs the frontend in development mode.npm run build
: Builds the frontend for production.npm run preview
: Previews the production build.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -am 'Add feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.