The auth-flow-api
is a TypeScript-based Express application designed for building an Authentication. It uses modern JavaScript and TypeScript
features, with development tools for linting, formatting, and maintaining code quality.
-
Node.js:
v20.16.0
-
npm:
>=10.8.2
-
Ensure that Node.js and npm versions match the requirements specified in the
engines
section. Use tools likenvm
(Node Version Manager) for
managing Node.js versions.
- Clone the repository:
git clone https://github.com/ShaNaim/auth-flow.git
cd auth-flow
- Install dependencies: Make sure to install both the development and production dependencies:
npm install
- Environment Setup:
-
Create a
.env
file in the root of your project with the necessary environment variables. Refer to.env.example
if available. -
Use the
envalid
package to ensure that your environment variables are properly validated.
-
Database Setup:
-
Install PostgreSQL: If PostgreSQL is not installed on your machine, follow the instructions for your operating system:
- On macOS:
brew install postgresql
- On Ubuntu:
sudo apt update
sudo apt install postgresql postgresql-contrib
- On macOS:
-
Configure PostgreSQL: After installation, start PostgreSQL and create a new database:
# Start PostgreSQL service sudo service postgresql start
# Open PostgreSQL prompt sudo -u postgres psql
# Create a new database for AuthFlow CREATE DATABASE AuthFlow;
-
Configure Prisma:
- Set
DATABASE_URL
in the.env
file: Replace theDATABASE_URL
in your.env
with the connection URL for PostgreSQL. For example:env DATABASE_URL="postgresql://user:password@localhost:5432/auth-flow"
- Run Prisma Migrations: After configuring the database, run Prisma migrations to create the necessary tables:
This will apply the initial database schema based on your
npx prisma migrate dev --name init
schema.prisma
.
- Set
-
-
Build the project: Compile the TypeScript files into JavaScript:
npm run build
-
Start the server: After building the project, start the server using:
npm start
-
Run in Development Mode: To run the server in development mode with automatic reloads using
nodemon
andts-node
, use:npm run dev
-
Development Server: Running
npm run dev
will start the server with hot reloading, making it easier for development. -
Production Build: To create a production build, use
npm run build
and thennpm start
to run the compiled JavaScript files. -
Linting: Check code quality using ESLint:
npm run lint
-
Code Formatting: Format the codebase with Prettier:
npm run format
-
Clean Build Artifacts: To remove the
dist
directory (where the compiled JavaScript files are stored):npm run clean
-
src/
: Main source folder containing the TypeScript files. -
dist/
: Compiled JavaScript files are output here after runningnpm run build
. -
@config
,@middlewares
,@modules
,@utils
, etc.: These are module aliases to simplify imports in your TypeScript code.
We welcome contributions! To contribute, follow these steps:
-
Fork the repository: Click the "Fork" button at the top of the GitHub repository.
-
Clone your fork:
git clone https://github.com/ShaNaim/auth-flow.git
cd auth-flow
-
Create a new branch: Make sure to give your branch a descriptive name:
git checkout -b feature/your-feature-name
-
Make your changes.
-
Run tests and lint: Make sure your code passes linting and any tests before submitting a pull request:
npm run lint
npm test
-
Commit and push your changes:
git add .
git commit -m "Add a description of your changes"
git push origin feature/your-feature-name
-
Create a pull request: Go to your forked repository on GitHub, and click the "New pull request" button.
-
Lint-Staged: This project uses
lint-staged
to automatically runeslint
andprettier
on staged files before committing, ensuring consistent code quality. -
Module Aliases: Use the aliases defined in
_moduleAliases
to simplify imports. For example:
import { someUtil } from '@utils/someUtil';
- RSA Token Pair Generator: rsa-token-pair-generator is an RSA token generator required for JWT authentication. This package follows the
structure necessary for this project by default.
- If you encounter issues with the Node version, ensure that you are using atleas
v20.16.0
. Usenvm
to manage Node versions:
nvm install 20.16.0
nvm use 20.16.0
- Make sure that
.env
is properly configured with the required environment variables, as missing variables can cause the server to fail on startup.
This guide covers the essential steps to get started with auth-flow-api
, as well as details on contributing and maintaining code quality. Happy
coding!
MIT License - See LICENSE for full text.