Git Product home page Git Product logo

yuchailam / fastify-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shyam-chen/fastify-starter

0.0 0.0 0.0 1.12 MB

:leopard: A boilerplate for Node.js, Fastify, TypeScript, Vite, Vitest, and Render. I18n | MongoDB | JWT | OTP | Redis | Cloudinary | WebSocket | EventSource | Nodemailer | BullMQ | ESLint | Prettier | Playwright | SuperTest | AutoCannon | Pnpm | PM2 | Caddy | Docker | CircleCI | TypeBox

Home Page: https://fastify-starter-12ih.onrender.com

License: MIT License

TypeScript 89.43% HTML 9.10% Dockerfile 1.47%

fastify-starter's Introduction

Fastify Starter

๐Ÿ† A boilerplate for Node.js, Fastify, TypeScript, Vite, Playwright, and Render.

๐ŸŒˆ Live Demo - The client application is here.

Table of Contents

Getting Started

Get started with Fastify Starter.

# dev server
$ pnpm install
$ pnpm dev

# mock server
$ cd mock/requests && pnpm install && cd ../..
$ pnpm mock

Project Setup

Follow steps to execute this boilerplate.

Install dependencies

$ pnpm install

Compiles and hot-reloads for development

$ pnpm dev

Compiles and minifies for production

$ pnpm build

Lints and fixes files

Files: src/**/*.ts

$ pnpm lint

Runs unit tests

Files: src/**/*.spec.ts

$ pnpm unit

Runs end-to-end tests

Files: e2e/**/*.spec.ts

# Before running the `e2e` command, make sure to run the following commands.
$ pnpm build
$ pnpm preview

# If it's not installed, run it.
$ cd e2e && pnpm install && cd ..

$ pnpm e2e

Performance metrics

Files: benchmark/**/*.spec.ts

# If it's not installed, run it.
$ cd benchmark && pnpm install && cd ..

$ pnpm bench

Mock requests

# If it's not installed, run it.
$ cd mock/requests && pnpm install && cd ../..

$ pnpm mock

Documentation

Files: docs/**/*.md

# If it's not installed, run it.
$ cd docs && pnpm install && cd ..

$ pnpm doc

Key Features

This seed repository provides the following features:

  • ---------- Essentials ----------
  • Fastify - Web Application Framework
  • MongoDB - Document Database
  • JWT - Authentication
  • PBKDF2 - Hash Passwords
  • OTP - Authenticator
  • Cloudinary - Asset Management
  • I18n - Internationalization and Localization
  • Redis - In-memory Data Structure Store
  • WebSocket - Two-way Interactive Communication Session
  • EventSource - Server-sent Events
  • Mailer - Email Sending
  • Email - Email Builder
  • Nunjucks - Email Rendering
  • Sheets - Spreadsheet Data Toolkit
  • BullMQ - Message Queue
  • ---------- Tools ----------
  • Vite - Bundler
  • TypeScript - JavaScript with Syntax for Types
  • ESLint - Linter
  • Prettier - Formatter
  • Vitest - Test Runner
  • Playwright - Test Automation
  • Autocannon - Measure Performance
  • VitePress - Documentation
  • ---------- Environments ----------
  • Node.js - JavaScript Runtime Environment
  • Pnpm - Package Manager
  • PM2 - Process Manager
  • Caddy - Web Server
  • Docker - Containerized Application Development
  • CircleCI - Continuous Integration and Delivery
  • Render - Cloud Application Hosting

Configuration

Control the environment.

Default environments

Set your local environment variables.

// env.ts
export default {
  NODE_ENV: process.env.NODE_ENV || 'development',

  HOST: process.env.HOST || '127.0.0.1',
  PORT: process.env.PORT || 3000,

  SITE_URL: process.env.SITE_URL || 'http://127.0.0.1:5173',

  MONGODB_URL: process.env.MONGODB_URL || 'xxx',
  REDIS_URL: process.env.REDIS_URL || 'xxx',
  CLOUDINARY_URL: process.env.CLOUDINARY_URL || 'xxx',
  SMTP_URL: process.env.SMTP_URL || 'xxx',

  SECRET_KEY: process.env.SECRET_KEY || 'xxx',
};

Continuous integration environments

Add environment variables to the CircleCI build.

# production
DEPLOY_HOOK=xxx

# development
DEV_DEPLOY_HOOK=xxx

# staging
STAGE_DEPLOY_HOOK=xxx

Continuous delivery environments

Add environment variables to the Render build.

SITE_URL=xxx

MONGODB_URL=xxx
REDIS_URL=xxx
CLOUDINARY_URL=xxx
SMTP_URL=xxx

SECRET_KEY=xxx

Directory Structure

The structure follows the LIFT Guidelines.

.
โ”œโ”€โ”€ .circleci
โ”œโ”€โ”€ benchmark
โ”œโ”€โ”€ docs
โ”œโ”€โ”€ e2e -> e2e testing (Caddy Server proxy api and proxy mock api)
โ”œโ”€โ”€ mock
โ”‚   โ”œโ”€โ”€ requests -> mock api
โ”‚   โ””โ”€โ”€ responses -> mock data for mock api, unit testing, and e2e testing
โ”œโ”€โ”€ public -> not handled by vite, copy it to dist
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ assets -> wasm
โ”‚   โ”œโ”€โ”€ components -> shared module
โ”‚   โ”œโ”€โ”€ composables -> shared module
โ”‚   โ”œโ”€โ”€ locales -> core module
โ”‚   โ”œโ”€โ”€ middleware -> core module
โ”‚   โ”œโ”€โ”€ modules -> feature modules
โ”‚   โ”‚   โ””โ”€โ”€ <FEATURE> -> feature module
โ”‚   โ”‚       โ”œโ”€โ”€ __tests__ -> unit testing
โ”‚   โ”‚       โ”œโ”€โ”€ _locales
โ”‚   โ”‚       โ”œโ”€โ”€ controller.ts
โ”‚   โ”‚       โ”œโ”€โ”€ registry.ts -> route component
โ”‚   โ”‚       โ”œโ”€โ”€ schema.ts
โ”‚   โ”‚       โ”œโ”€โ”€ service.ts
โ”‚   โ”‚       โ””โ”€โ”€ types.ts
โ”‚   โ”œโ”€โ”€ plugins -> root module
โ”‚   โ”œโ”€โ”€ templates -> email templates with nunjucks
โ”‚   โ”œโ”€โ”€ utilities -> shared module
โ”‚   โ”œโ”€โ”€ app.ts
โ”‚   โ”œโ”€โ”€ error.ts
โ”‚   โ”œโ”€โ”€ main.ts
โ”‚   โ””โ”€โ”€ shims.d.ts
โ”œโ”€โ”€ .editorconfig
โ”œโ”€โ”€ .eslintrc
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .prettierrc
โ”œโ”€โ”€ Caddyfile
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ env.ts
โ”œโ”€โ”€ index.ts -> entrypoint
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ pnpm-lock.yaml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ render.yaml
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ vite.config.ts

Microservices

A microservice architecture โ€“ a variant of the service-oriented architecture structural style โ€“ is an architectural pattern that arranges an application as a collection of loosely-coupled, fine-grained services, communicating through lightweight protocols.

See Micro-Fullstack's Micro Backends for instructions on how to create microservices from source code.

api.example.com
โ”œโ”€โ”€ /auth
โ”‚   โ””โ”€โ”€ auth.api.example.com
โ”œโ”€โ”€ /stats
โ”‚   โ””โ”€โ”€ stats.api.example.com
โ”œโ”€โ”€ /todoist
โ”‚   โ””โ”€โ”€ todoist.api.example.com
โ”œโ”€โ”€ /feature
โ”‚   โ””โ”€โ”€ feature.api.example.com
โ”œโ”€โ”€ /files
โ”‚   โ””โ”€โ”€ files.api.example.com
โ””โ”€โ”€ /settings
    โ””โ”€โ”€ settings.api.example.com

fastify-starter's People

Contributors

shyam-chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.