Express, TypeScript, Prisma ORM and OpenAPI project
This project features a RESTful CRUD API that processes data for an ecommerce application.
- Designed and fully documented using Swagger tools and OpenAPI Specification.
- Full API contract can be found here.
- Powered by Vercel's serverless functions, including a PSQL database server for managing application data (configured for session persistence).
- Session and cookie-based authentication enabling persistent logins.
- Middleware functions for data validation and user authentication.
- In-depth error handling, casting a wide net over potential edge cases and sources of error.
- Data modelling and database migrations with Prisma ORM.
- Comprehensive integration testing, achieving 90% test coverage as reported by Istanbul's nyc CLI.
- Programmatic database reseeding using dummy data.
For more information on available query parameters and request body requirements, visit the API base url.
Many of these endpoints require authenticated access, which you can accomplish by first signing up and then logging in.
// 1) Send a POST request to /api/signup
{
"username": ...,
"password": ...,
"email": ... ,
"name": ...
}
// 2) Send a POST request to /api/login
{
"username": ... /* your username from step 1) */,
"password": ... /* your password from step 1) */
}
HTTP method(s) | URL |
---|---|
POST | /api/signup |
POST | /api/login |
POST | /api/logout |
GET | /api/products |
GET | /api/products/bestsellers |
GET | /api/products/:id |
GET | /api/products/:id/reviws |
GET, PUT, DELETE | /api/customers/:id |
GET, PUT | /api/customers/:id/cart |
GET, PUT | /api/customers/:id/wishlist |
GET, POST | /api/customers/:id/orders |
GET | /api/customers/:id/favorites |
GET | /api/customers/:id/orders/:orderId |
GET | /api/customers/:id/reviews |
POST | /api/customers/:id/addresses |
DELETE | /api/customers/:id/addresses/:addressId |
GET | /api/categories |
GET | /api/suppliers |
GET, POST | /api/reviews |
GET, PUT, DELETE | /api/reviews/:id |
This is a simplified view of the entity relationships that exist within the database. For a more complete picture, consult the schema configuration and migration files.
Package | Purpose |
---|---|
Express | Web API framework |
Prisma | Node.js & TypeScript ORM |
SuperTest | Integration testing |
Mocha | Test framework |
Chai | Assertion library |
Passport.js | Authentication middleware |
express-session | Session middleware |
This project requires PSQL to be installed locally.
- Clone and fork the repository and install all dependencies.
- Create a local empty PSQL database called ecommerce_db.
- Create a .env file in the root of the repository with 4 environment variables:
DATABASE_PRISMA_URL=postgresql://<USER>:<password>@localhost:5432/ecommerce_db
DATABASE_URL_NON_POOLING=postgresql://<USER>:<password>@localhost:5432/ecommerce_db
SESSION_SECRET=sessionsecret
PORT=3000
- For the database connection strings, Replace
<USER>
with the name of your local database user (e.g. postgres) and replace<PASSWORD>
with whatever password you used to set up the local user.
You can now run the scripts below and begin to explore the project.
npm run dev
# or
npm run start
npm run test
npm run testcov
This command performs 2 actions: syncs the database schema with Prisma schema and regenerates Prisma Client.
npx prisma migrate dev
# or
prisma db push
npx prisma db seed
Prisma Studio (browser-based GUI and database visualiser)
npx prisma studio