This is MarketPlace backend app.
-
Set environmental variables:
export FLASK_ENV=development # or production export FLASK_DEBUG=1
-
Add
.env.development
or.env.production
file to the project root directory. -
Install dependencies
pip install -r requirements.txt
-
Run app:
flask run
-
Forward Stripe events:
stripe listen --forward-to http://localhost:5000/webhook/order/paid
To run application in a Docker container:
-
Install Docker on your system.
-
Build the Docker image:
docker build -t my-app .
-
Run the Docker container with hot reload enabled:
docker run -d -p 5000:5000 -v $(pwd):/app my-app
-
Access the application at
http://localhost:5000
.
PostgreSQL is used as the database for this project.
Alembic is used for database migration. Follow these steps to manage migrations:
- Create migration file:
alembic revision --autogenerate -m <message>
- Review and update the migration script if necessary. The script can be found in the alembic/versions directory.
- Apply the migration:
alembic upgrade head
Considering we have both production and development environment setups, migration has to be done twice, once for each environment. To switch between environments, use:
export FLASK_ENV=development # or production
Make sure to set the appropriate environment variables in your .env.development
and .env.production
files.
Stripe is used as a payment gateway. Some of the docs used during development:
graph TD;
subgraph Web App
Auth[User Authentication];
Catalog[Product Catalog];
Cart[Shopping Cart];
Order[Order];
User[User];
Wishlist[Wishlist];
end
subgraph Flask Backend
AuthAPI[Auth API];
ProductAPI[Product API];
CartAPI[Cart API];
OrderAPI[Order API];
UserAPI[User API];
WishlistAPI[Wishlist API];
end
subgraph PostgreSQL Database
UserTable[User Table];
OrderTable[Order Table];
CartTable[Cart Table];
WishlistTable[Wishlist Table];
end
subgraph PaymentGateway
StripeProducts[Products];
end
Auth --> AuthAPI
Catalog --> ProductAPI
Cart --> CartAPI
Order --> OrderAPI
User --> UserAPI
Wishlist --> WishlistAPI
AuthAPI --> UserTable
ProductAPI --> StripeProducts
CartAPI --> CartTable
OrderAPI --> OrderTable
UserAPI --> UserTable
WishlistAPI --> WishlistTable