{"id":38380346,"url":"https://github.com/phucvinh57/fastify-template","last_synced_at":"2026-01-18T13:01:57.975Z","repository":{"id":160778065,"uuid":"635588450","full_name":"phucvinh57/fastify-template","owner":"phucvinh57","description":"A project template using fastify with many helpful configurations","archived":false,"fork":false,"pushed_at":"2025-09-11T06:54:22.000Z","size":826,"stargazers_count":9,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-17T14:09:26.884Z","etag":null,"topics":["basic-authentication","bot","ci-cd","eslint","fastify","husky","prettier","prisma","swagger-ui","testing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phucvinh57.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-03T02:45:28.000Z","updated_at":"2025-09-11T06:54:27.000Z","dependencies_parsed_at":"2024-06-28T05:30:17.009Z","dependency_job_id":"190fe1d5-5b48-4c11-b1f6-f68ad5529d3c","html_url":"https://github.com/phucvinh57/fastify-template","commit_stats":null,"previous_names":[],"tags_count":17,"template":true,"template_full_name":null,"purl":"pkg:github/phucvinh57/fastify-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvinh57%2Ffastify-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvinh57%2Ffastify-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvinh57%2Ffastify-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvinh57%2Ffastify-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phucvinh57","download_url":"https://codeload.github.com/phucvinh57/fastify-template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvinh57%2Ffastify-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28536686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["basic-authentication","bot","ci-cd","eslint","fastify","husky","prettier","prisma","swagger-ui","testing"],"created_at":"2026-01-17T03:37:29.274Z","updated_at":"2026-01-18T13:01:57.954Z","avatar_url":"https://github.com/phucvinh57.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify Template\n\n[![formatter: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) ![CI](https://github.com/phucvinh57/fastify-template/actions/workflows/ci.yml/badge.svg) ![Deploy](https://github.com/phucvinh57/fastify-template/actions/workflows/release.yml/badge.svg)\n\nUsing [fastify](https://www.fastify.io), this template includes:\n\n- API Docs: `Swagger UI`\n- Input definition: [`Typebox`](https://github.com/sinclairzx81/typebox)\n- ORM: `Prisma`\n- Deployment:\n  - Dockerfile \u0026 docker-compose files\n  - Script CI/CD in `.github/workflows`\n- Testing: `jest`\n- Code linting \u0026 styling: `husky` + `prettier`\n- Precommit hook: `lint-staged`\n\nFor applying conventional commits, refer [commitizen](https://github.com/commitizen/cz-cli).\n\n## 1. Prerequisites\n\n- `docker` v20.10.22\n- `docker-compose` v1.29.2\n- `node` v18.13.0\n- `npm` 8.19.3\n\n## 2. Commands\n\nNote: Fill in `.env` file (use template from `.env.example`) before starts.\n\n- `yarn bootstrap`: Set up development\n- `yarn barrels`: Gather export objects from many files in a folder and re-export in `index.ts` file. See configs in `.barrelsby.json`.\n- `yarn start`: Start application in dev mode\n- `yarn db:migrate`: Apply new migration to current database\n- `yarn db:reset`: Reset database and run seed\n- `yarn db:deploy`: Deploy all migrations without confirmations (use in production)\n- `yarn db:generate`: Just generate prisma client library\n- `yarn db:studio`: Interact with database by a web UI\n- `yarn lint`: Check linting\n- `yarn format`: Format code\n- `yarn start:docker`: Run `docker-compose.dev.yml` file to set up local database\n- `yarn clean:docker`: Remove local database instance include its data.\n- `yarn clean:git`: Clean local branches which were merged on remote\n- `yarn test \u003ctest_label\u003e`: Run test with label `\u003ctest_label\u003e`. For example: `yarn test auth` will run all tests in `auth.test.ts` or `auth.spec.ts` file.\n\n## 3. Project structure\n\n```py\n📦prisma\n ┣ 📂migrations     # All SQL migration scripts go here\n ┣ 📜schema.prisma  # Database schema declaration\n ┗ 📜seed.ts        # Generate sample data script\n📦src\n ┣ 📂configs        # Contain environment variables \u0026 other app configurations\n ┣ 📂constants      # Constants and enums go here\n ┣ 📂dtos           # Schema for input (from requests) \u0026 output (from responses)\n ┃ ┣ 📂in\n ┃ ┣ 📂out\n ┃ ┗ 📂common           # Reusable schemas\n ┣ 📂handlers       # Handlers, which are responsible for handling core business logic\n ┣ 📂interfaces     # Interfaces\n ┣ 📂plugins        # Plugin, in charge of organizing api routings \u0026 registering middleware\n ┣ 📂repositories   # Datasource configurations \u0026 connections. Could have more than one datasource.\n ┣ 📂services       # 3rd-party services or business logic services\n ┣ 📂types          # Types\n ┣ 📂utils          # Helping classes and functions\n ┣ 📜Server.ts      # Server setting \u0026 binding modules\n ┗ 📜index.ts       # Program entry\n```\n\n## 4. Appendix\n\nThis section contains some useful information for development.\n\n### Testing\n\nThese are some best practices for testing and overall quality:\n\n1. At the very least, write API (component) testing.\n2. Include 3 parts in each test name\n3. Structure tests by the AAA pattern\n4. Ensure Node version is unified\n5. Avoid global test fixtures and seeds, add data per-test\n6. Check your test coverage, it helps to identify wrong test patterns\n7. Refactor regularly using static analysis tools\n8. Mock responses of external HTTP services\n9. Test your middlewares in isolation\n10. Specify a port in production, randomize in testing\n11. Test the five possible outcomes\n\n### Code linting \u0026 formating\n\nWe use [`eslint`](https://eslint.org/) to find and fix problem in code, such as:\n\n- Unused variables\n- Use `var` declaration\n- Loosely comparation using `==`\n- ...\n\nYou can run this command to test eslint script:\n\n```bash\nyarn lint\n```\n\nTo maintain only one style coding across members, we use [`prettier`](https://prettier.io/). Try:\n\n```bash\nyarn format\n```\n\nYou don't need to run these scripts regularly or before commiting code. They are run automatically before `git commit` command by setting as a precommit script. In some circumstances, precommit script is not enabled by default, just type two commands below to fix it:\n\n```bash\nchmod ug+x .husky/*\nchmod ug+x .git/hooks/*\n```\n\nFor a tip, two plugins above could be installed in `VSCode`'s extensions.\n\n### Barrelsby \u0026 Path alias\n\n```py\n............\n ┣ 📂controllers\n ┃ ┗ 📜user.ctrler.ts\n ┣ 📂routes\n ┃ ┗ 📜user.route.ts\n ┣ 📂schemas\n ┃ ┣ 📂in\n ┃ ┃ ┣ 📜ids.schema.ts\n ┃ ┃ ┣ 📜user.schema.ts\n ┃ ┃ ┗ 📜index.ts\n............\n```\n\nImagine you are in `user.ctrler.ts` and want to import `ASchema` from `ids.schema.ts`. The code can be like this:\n\n```typescript\nimport { ASchema } from '../schemas/in/ids.schema.ts'\n```\n\nThe more nested folders, the more bad looking importation. It is waste time to guess how many `..` should be put in relative path.\n\nThe solution is [`barrelsby`](https://www.npmjs.com/package/barrelsby) and **path alias**. With configurations in `.barrelsby.json`, barrelsby can import your entire code base in a specific folder, and re-export them in `index.ts` file.\n\nTry this:\n\n```bash\nyarn barrels\n```\n\nTo avoid using many `..` in relative path, config path alias in `tsconfig.json`. See the guideline [here](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping).\n\n### Git working culture\n\n- For every updates, DO NOT push directly to `master` branch. Create a new branch, commit, publish branch and create a pull request (PR) instead.\n- A branch should have prefix `feat/` for a feature update, prefix `hotf/` for a hotfix, `improv/` for an improvement ...\n- A PR should be small enough to review. To split a large PR, use [stacked PRs](https://blog.logrocket.com/using-stacked-pull-requests-in-github/).\n\n### About Prisma ORM\n\n- [Database schema](https://www.prisma.io/docs/concepts/components/prisma-schema)\n- [Type mapping Prisma \u0026 PostgreSQL](https://www.prisma.io/docs/concepts/database-connectors/postgresql#type-mapping-between-postgresql-to-prisma-schema)\n- [Schema references](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucvinh57%2Ffastify-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphucvinh57%2Ffastify-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucvinh57%2Ffastify-template/lists"}