This project implements a credit-based system to manage API usage, ensuring fair access and preventing abuse. It uses Express.js for the backend, Postgres for the database, and Drizzle ORM for object-relational mapping. The testing framework is powered by Vitesse, offering a fast and efficient way to test your application.
Follow these steps to clone the repository and get started:
- Node.js (v20.10.0) and npm installed
- Docker (optional, for running a Postgres container)
- Postman (for testing API endpoints)
- Install Dependencies: Run
npm install
to install required dependencies. - Environment Variables:
- Copy the
.env.example
file to.env
. - Update the
.env
file with your database credentials.
- Copy the
- Database Setup:
- For Docker users, start a Postgres container by running
docker-compose up -d
. Make sure you havedocker-compose.yaml
ready. - Alternatively, manually create a database named
credit_dev
in your Postgres instance. - Create necessary tables by executing
npm run migrate
. - Populate the database with initial data using
npm run seed
.
- For Docker users, start a Postgres container by running
Here's the initial data seeded into the database:
- Users:
username
:admin@admin.com
,password
:password
username
:user@user.com
,password
:password
When running tests with Vitesse, ensure your database settings in vite.config.ts
match your testing environment. This step is crucial for accurate test results.
- Launch the development server with
npm run dev
.
- Run tests using
npm run test
to ensure your setup is correct.
Explore and test the API endpoints by importing the postman.json
schema from the root directory into your Postman application. This provides a ready-to-use collection of requests for interacting with the API.
- Backend: Express.js
- Database: Postgres with Drizzle ORM
- Testing: Vitesse for an efficient testing workflow
A docker-compose.yaml
file is included for convenience, facilitating the use of a Postgres container. This is optional but recommended for a seamless development setup.