The idea of this project is to learn how to build a fast server to be used as a complete OAuth2 server.
- User registration and login with Credential Authentication
- Creation of profiles to be used as OAuth2 clients
- Application Code Grant
- Access token and Refresh token Grant
- Token expiration and Token revocation
- Protected routes
- And many more...
- NodeJS as the runtime environment
- TypeScript for type safety (This is a modern and secure way to write JavaScript)
- Fastify as a web framework that is faster and has a better UX than Express
- Zod for data validation and type inference (instead of JSON Schema for example)
- Prisma as an ORM for a sqlite database (This enable us to create a local database for development that is lightweight and easy to use)
- Argon2 for password hashing and verification (instead of the commonly used bcrypt, which is slower and less secure)
- Pino for logging (This is a fast and simple logger)
- Pino-pretty for pretty logging (This transforms the logs from pino into a more readable format to be used in development)
- Vitest for testing (Instead of Jest, which is slower and has a worse DX)
- - NodeJS v19.2.0 or higher installed (Technically, you can use any version of NodeJS, but I recommend using the latest version)
- - Pnpm v7.18.1 or higher installed (This is a package manager that is faster than npm and yarn, but you can use npm or yarn if you want to)
- Clone the repo
- Install dependencies with
pnpm i
- Apply migrations, seed and generate typings with
pnpm db:setup
- Run the dev script with
pnpm dev
- Use the API with Postman or Insomnia or any other API client of your choice
Testing is done with Vitest. To run the tests, run bun run test
, to check the coverage, run bun run coverage
.
- To build the project, run
pnpm build
. This will create adist
folder with the compiled code. To run the compiled code, runpnpm start
.
Bundling is the process of combining multiple files, such as JavaScript or CSS files, into a single file. This allows for fewer requests to the server, which can improve the performance of the website or application.
Minifying is the process of removing unnecessary characters, such as white space, comments, and new lines, from the code to make it smaller and more efficient. This can further improve the performance by reducing the size of the code that needs to be transferred to the user's device.
Together, bundling and minifying can help to optimize the performance of a website or application by reducing the number of requests and the amount of code that needs to be transferred. The pnpm dev command should be used during development, while the pnpm build command, which includes bundling and minifying, should be used in production. This can ensure that the website or application performs well and provides a good user experience.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the Unlicense License. See LICENSE
for more information.