{"id":21481322,"url":"https://github.com/mobilereality/nestjs-rest","last_synced_at":"2025-08-22T12:42:04.802Z","repository":{"id":101969591,"uuid":"438183467","full_name":"MobileReality/nestjs-rest","owner":"MobileReality","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-03T15:08:08.000Z","size":232,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-23T18:49:06.934Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MobileReality.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-12-14T08:59:53.000Z","updated_at":"2022-01-03T15:08:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"bf16eac0-fe5a-46a1-a663-77f7157b149f","html_url":"https://github.com/MobileReality/nestjs-rest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MobileReality%2Fnestjs-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MobileReality%2Fnestjs-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MobileReality%2Fnestjs-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MobileReality%2Fnestjs-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MobileReality","download_url":"https://codeload.github.com/MobileReality/nestjs-rest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244006398,"owners_count":20382443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-23T12:23:23.100Z","updated_at":"2025-03-17T09:13:40.443Z","avatar_url":"https://github.com/MobileReality.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backend graphql example app\n\nThis repository is for showing the design of MR backend REST project structure.\n\n\n## Configuration\n\nApp config is defined by environment variables. Each variable should be written in UPPER_CASE.\n\nEvery allowed/required variable should be defined and described in `example.env` file.\n\nMain file (which app uses to parse variables with dotenv library) is `.env`.\n\nEach environment variable should be mapped and validated in related script under `./src/config` directory.\n\nThanks to well-defined example.env we can easily set up development environment\nby one command which copies `example.env` into `.env`.\n```\ncp example.env .env\n```\n\n## Docker\n\nWe would like to deploy app with docker that's why we have `Dokerfile`.\n\nIt is defined as 2-step process which allows us to release docker image\nwith only required dependencies for running it in production.\n\nThat's why whenever we have to install any npm dependency we should use proper installation command\n```\nnpm i package - package is required for production eg. some core lib used in services\nnpm i -D package - package is required only for development eg. library @types\n```\n\nApplication probably will use some external services like database.\n\nEach service that is available on dockerhub should be defined in docker-compose for easy project startup.\n\nThanks to that we can just start all required backend services by\n```\ndocker-compose up\n```\nNOTE: docker-compose will load `.env` file thanks to that all variables will come from the same source.\n\nInstall required dependencies with\n```\nnpm i\n```\n\nAfter that you can start backend in development mode\n```\nnpm run dev\n```\n\n\n## Database\n\nFor database management we will use MikroORM.\n\nMikroORM config is placed in `./src/mikro-orm.config.ts` as typescript file which allows us to use in it\nenv variables mapped in `config` directory.\n\nAny database table/column/constraint name should be written in snake_case (as sql in case insensitive).\n\nIn short:\n```\n - table names -\u003e plural (users, user_comments)\n - column names -\u003e singular (email, is_blocked, created_at)\n```\n\nTo manage database during development we have script in package.json which uses MikroORM-cli under the hood\n```\nnpm run db -- SCRIPT-NAME-WITH-OPTIONS\n```\n\nTo list all available db commands\n```\nnpm run db -- -h\n```\n\nTo generate migration file based on entities changes (command will ask for file name bt prompt)\n```\nnpm run db -- migration:create\n```\n\nTo run pending migrations\n```\nnpm run db -- migration:up\n```\n\n\n## Linting\n\nTo enforce the same code style for project we are using eslint with prettier.\n\nThanks to husky+list-staged libraries combo linting will be executed after every commit.\nTo run linter\n```\nnpm run lint\n```\n\nTo run linter with auto fix base errors\n```\nnpm run lint:fix\n```\n\n\n## Naming convention\n\nDirectories and files should be named using kebab-case to avoid problems with case sensitivity across OS.\n\n\n## Project structure\nWe will use Vertical Slice Architecture which means that we're organizing code across a feature rather than layers.\nThe focus is on features and capabilities rather than technical concerns.\nCoupling is limited by the scope of the feature and the size of the vertical slice.\n\n```\nAll project source files that you should care of should be placed under `./src` directory which are:\n - common - any data that is used across multiple modules\n - config - validation and mapping env variables\n - migrations - database migration files\n - modules - core application parts\n - scripts - scripts that can be called by cli\n - test-utils - util functions used only in tests across all project (will be purged during project build and won't be available in dist)\n - main.ts - server setup and startup\n - mikro-orm.config.ts - MikroORM config file\n```\n\nEach module should look like:\n```\nmodules\n├──app.module - merges and parses all application modules\n├──app.controller - root endpoint for health check and version display\n└──cats\n   ├──__test__ - test utils related to module\n   │  └──cats.utils.ts\n   ├──entities - MikroORM entities\n   │  └──cat.entity.ts\n   ├──dtos - dtos that can be returned by endpoints\n   │  └──cat.dto.ts\n   ├──endpoints - each endpoint should be placed in separate file containing class with handler method which describes endpoint properties\n   │  ├──create-cat.mutation.ts\n   │  └──create-cat.mutation.e2e.test.ts - every endpoint should have dedicated test file which tests every response edge case\n   ├──services - stores shared logic used across endpoints\n   │  └──cats.service.ts\n   ├──cats.constant.ts - stores constant data related to module like errors or validation decorators\n   └──cats.module.ts - merges all module providers (entities, endpoints, services)\n```\n\n\n### Testing\n\nEvery endpoint should be tested with e2e tests that covers every of it's allowed responses.\n\nTo run e2e tests call:\n```\nnpm run test:e2e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobilereality%2Fnestjs-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmobilereality%2Fnestjs-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobilereality%2Fnestjs-rest/lists"}