UNPKG

fastify-auth-starter

Version:

Scaffold a Fastify + Prisma + Auth backend app

200 lines (131 loc) 3.63 kB
# Auth-starter backend codebase This is the backend service for Auth-starter demo, built with Fastify, TypeScript, Prisma, and PostgreSQL --- ## Project Setup ### Prerequisites Ensure you have the following installed on your system: - [Node.js](https://nodejs.org/) (Recommended: v18+) - [Docker](https://www.docker.com/) (For database container) - [pnpm](https://pnpm.io/) (Package manager, or use npm/yarn) ### Clone the Repository ```sh git clone https://github.com/Rx-Internal/rx-demo-backend.git cd rx-demo-backend ``` ### Install Dependencies ```sh pnpm install ``` ### Setup Environment Variables Create a `.env` file from the example: ```sh cp .env.example .env ``` ### Configuration Settings To modify application settings without changing the code: 1. Open `src/config/settings.ts` 2. Update the following values as needed: - Session expiration period (in days) - Token validity duration for email verification and password reset - SendGrid email template identifiers These settings can be adjusted at any time to meet your requirements without modifying the application code. ### Start / Setup the Database Using Docker Compose: ```sh pnpm start:local-db ``` If you prefer to query on the database locally in your terminal (optional): ```sh pnpm look:local-db ``` To stop the local database: ```sh pnpm stop:local-db ``` ### Generate Prisma Client ```sh pnpm prisma:generate ``` ### Running Migrations ```sh pnpm migrate ``` ### Running the Server For development mode with auto-restart: ```sh pnpm dev ``` For production: ```sh pnpm build pnpm start ``` ### Prisma Studio (Database GUI) ```sh pnpm prisma:studio ``` ### API Documentation (Swagger) Swagger UI is available at: ``` http://127.0.0.1:4000/docs ``` This provides interactive API documentation for exploring available endpoints. --- ## Sample API Usage ### Base URL ``` http://127.0.0.1:4000/api/v1 ``` ### Example Endpoint: Health Check - **GET** `/health` - **Usage**: ```sh curl http://127.0.0.1:4000/api/v1/health ``` - **Response**: ```json { "status": "ok", "uptime": 914.3940557, "timestamp": "2025-04-07T07:16:56.032Z" } ``` > For full list of endpoints and testing, refer to Swagger at `/docs` --- ## Code Quality Run linting: ```sh pnpm lint ``` Fix lint issues: ```sh pnpm lint:fix ``` Format code: ```sh pnpm format ``` --- ## 📄 Backend Developer Guide All contributors must follow the [Auth-starter demo Backend Developer Guide](./docs/Developer_Guide.md). This guide covers: - Backend architecture and best practices - API standards and versioning - Input validation and error handling - Commit, review, and collaboration workflow - Testing and documentation expectations Please review the guide before starting any development. --- ## 🔐 Authentication Guide All contributors must follow the [Authentication Flow Documentation](./docs/authentication/Auth.md) for user authentication implementation. --- ## 📧 Email & Password Verification Guide All contributors must follow the [Email & Password Verification Flow Documentation](./docs/authentication/EMAIL_PASSWORD_VERIFICATION.md) for user email and reset password implementation. --- ## 📊 SonarQube We support local SonarQube setup for code quality analysis. Please follow the [SonarQube Guide](./docs/SonarQube.md) to learn more about setup instructions and usage. --- > ⚠️ **Note:** > The project contains some existing Prisma migration files. > If needed, you can safely delete these files and reset the migrations after updating the `prisma.schema` file based on your requirements.