Skip to content

A simple and modular Fastify-based REST API for user management using MongoDB. Includes full CRUD operations, environment variable setup, plugin architecture, and Swagger documentation for easy API exploration.

License

Notifications You must be signed in to change notification settings

rayan25nov/Fastify-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fastify Server Project 🚀

Fastify TypeScript pnpm License

This project is a server application built using Fastify and pnpm. It is designed to provide a robust and scalable API with various endpoints for user management.


📚 Table of Contents


📁 Folder Structure

└── 📁fastify
    └── 📁api
        └── index.js
    └── 📁src
        └── app.ts
        └── 📁assets
            └── logo.svg
        └── index.ts
        └── 📁models
            └── user.model.ts
        └── 📁plugins
            └── env.ts
            └── mongo.ts
            └── swagger.ts
        └── 📁routes
            └── user.routes.ts
        └── 📁services
            └── user.service.ts
        └── 📁types
            └── env.d.ts
            └── mongo.d.ts
    └── .env
    └── .gitignore
    └── LICENSE
    └── package.json
    └── pnpm-lock.yaml
    └── readme.md
    └── tsconfig.json
    └── vercel.json

🔍 What Each Folder Does

Folder/File Purpose
models/ Define the database schema for user entities.
plugins/ Register and configure various plugins such as environment variables and MongoDB.
routes/ Register API routes with Fastify, defining endpoint handlers.
services/ Implement business logic and perform database queries.
types/ Provide type definitions for TypeScript, including custom Fastify extensions.
index.ts Entry point of the application: imports and registers all routes and plugins, and starts the server.
app.ts Sets up and configures the Fastify instance, making it ready for testing or deployment.

🛠️ Getting Started

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/rayan25nov/Fastify-Server.git
    cd Fastify-Server
  2. Install dependencies:

    pnpm install
  3. Create a .env file in the root directory with the following content:

    PORT="8080"
    MONGO_URI="mongodb://localhost:27017/user"
    BASE_URL="http://localhost:8080"

Start the Development Server

Run the following command to start the server in development mode with hot-reloading enabled:

pnpm dev

📜 Available Scripts

Script Description
pnpm build Compiles the TypeScript code into JavaScript.
pnpm start Starts the server using the compiled JavaScript files.
pnpm dev Runs the server in development mode with TypeScript compilation and hot-reloading.
pnpm test Runs the test suite using Jest.
pnpm test:watch Runs the tests in watch mode for continuous testing during development.

🚀 Deployments to Vercel

This project is deployed to Vercel using a serverless function. The serverless function is defined in api/index.js, and the deployment configuration is specified in vercel.json.


👥 Contributors


📄 License

This project is licensed under the ISC License.


About

A simple and modular Fastify-based REST API for user management using MongoDB. Includes full CRUD operations, environment variable setup, plugin architecture, and Swagger documentation for easy API exploration.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published