{"id":13567056,"url":"https://github.com/regen-network/regen-server","last_synced_at":"2025-04-04T01:30:58.786Z","repository":{"id":37572698,"uuid":"252866913","full_name":"regen-network/regen-server","owner":"regen-network","description":":seedling: Regen web server and database","archived":false,"fork":false,"pushed_at":"2024-08-29T15:02:46.000Z","size":16947,"stargazers_count":6,"open_issues_count":25,"forks_count":5,"subscribers_count":16,"default_branch":"dev","last_synced_at":"2024-08-29T16:46:33.440Z","etag":null,"topics":["graphql","postgresql"],"latest_commit_sha":null,"homepage":"https://api.regen.network","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/regen-network.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":"2020-04-03T23:45:52.000Z","updated_at":"2024-08-07T09:22:47.000Z","dependencies_parsed_at":"2023-11-24T09:08:21.293Z","dependency_job_id":"fbb8cdf9-e123-4a5f-9f5a-84b6756b8c0a","html_url":"https://github.com/regen-network/regen-server","commit_stats":{"total_commits":698,"total_committers":9,"mean_commits":77.55555555555556,"dds":0.5601719197707736,"last_synced_commit":"721ca2f65fd732ecb437c911a97ec22a74a3d5b2"},"previous_names":["regen-network/regen-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regen-network%2Fregen-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regen-network%2Fregen-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regen-network%2Fregen-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regen-network%2Fregen-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/regen-network","download_url":"https://codeload.github.com/regen-network/regen-server/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223075609,"owners_count":17083544,"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":["graphql","postgresql"],"created_at":"2024-08-01T13:02:22.558Z","updated_at":"2024-11-04T21:31:29.881Z","avatar_url":"https://github.com/regen-network.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Regen Server\n\n## Prerequisites\n\n- [NodeJS](https://nodejs.org/en/)\n- [Yarn](https://yarnpkg.com/en/)\n- [Docker](https://www.docker.com).\n\n[NVM](https://github.com/nvm-sh/nvm) is recommended for managing NodeJS\ninstallations and we are intending to stick to the\n[LTS](https://github.com/nvm-sh/nvm#long-term-support) releases of NodeJS for\nthis project.\n\nAfter installing `nvm`, this sequence of commands will provide you with an LTS\nversion of nodejs and access to `yarn`:\n\n```\n$ nvm install\n$ nvm use\n$ corepack enable\n$ yarn --help\n```\n\nNote: the `.nvmrc` file in this repo determines which node version is used locally.\n\nAt present the application is known to be compatible with\nnodejs versions 10.x, 14.x and 16.x. For information about\nwhich version is deployed on Heroku for the staging and production\nserver, see the `engines` section in `package.json`. Read here for\n[more info](https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version).\n\n## Setup\n\n### Starting PostgreSQL and Redis Locally\n\n1. Install [docker-compose](https://docs.docker.com/compose/install/)\n2. Run `cd server \u0026\u0026 docker-compose up`\n\n#### Postgres info\n\nThe database can then be accessed using:\n\n```sh\npsql postgresql://postgres:password@localhost:5432/server\n```\n\n#### Redis info\n\n[Redis](https://redis.io//) is used for caching. See `REDISCLOUD_URL` in `server/.env.example`.\nYou can connect to redis using the `redis-cli`:\n\n```\ncd server \u0026\u0026 docker-compose exec redis redis-cli\n```\n\n### Environment variables\n\nBased on `server/.env.example`, create some `server/.env` file with appropriate values.\n\n## Starting a development server\n\n1. Install all dependencies with `yarn`.\n2. Start a development server with `yarn dev`. This runs in parallel the node `server` and watches/builds code in the `worker` (used for sending emails at the moment).\n3. Start coding!!\n\n### Alternative method for starting server\n\nThis method is useful if you don't want to run the watch process.\nThe tradeoff is that you must manually restart the command after making code changes.\nThe example below shows how to increase the log verbosity for certain parts of the app.\n\n```\n$ cd regen-server\n$ DEBUG='express:*,express-sharp*' yarn start\n```\n\n## Database\n\n### Configuring postgres logging\n\nNeed verbose logging? Run this SQL command in `psql` or similar:\n\n```sql\n# the line below adjusts log level of the postgres daemon to include a lot of info..\nalter database regen_registry set log_statement = 'all';\n# the line below adjusts the client (psql) to display level debug or higher messages..\nset client_min_messages to 'debug';\n```\n\nSee [the postgres errors and messages documentation][6] for more info.\n\n### Postgraphile\n\nWe make use of postgraphile to autogenerate a graphql API. Here are some references for\nunderstanding how to work with postgraphile:\n\n- https://www.graphile.org/postgraphile/required-knowledge/\n- https://www.graphile.org/postgraphile/quick-start-guide/\n- https://learn.graphile.org/docs/PostgreSQL_Row_Level_Security_Infosheet.pdf\n\n### Migrations\n\nRefer to [migrations/README.md](migrations/README.md).\n\n### Seeding\n\nThe following section describes how to seed your local database with production data in order to facilitate local feature development and testing.\n\n0. Make sure the production database and your local database are in sync with regards to migrations by verifying the latest migration version number on `master` and on your local branch in `sql` folder. Otherwise that may cause unexpected behavior when trying to seed your local database with production data.\n   It's also recommended to start from a local database without any data, otherwise existing data might conflict with production data which could lead to constraint errors (e.g. unique constraint error in the case of multiple `user`s with the same email).\n\n1. Export data from the production database using `pg_dump`:\n\n```sh\npg_dump -d postgres -h registryproduction.cna6zybeqdns.us-east-1.rds.amazonaws.com -p 5432 -U postgres --file dump --data-only -F c\n```\n\nYou'll be asked for the database password, if you don't know where to find it, please contact one of the contributors of this repository.\nAfter entering the password, this might take a few seconds before data is exported into `dump`.\n\n2. Import production data to your local database using (the password is just `postgres` for your local database):\n\n```sh\npg_restore -d regen_registry -h localhost -p 5432 -U postgres dump\n```\n\n### Dropping local database\n\nIf for some reasons, your database is in a messy state and it's best to just restart from scratch, you may want to drop the database and recreate it.\n\nMake sure your [postgres Docker container is running](#starting-postgresql-locally) and then run:\n\n```\nyarn run graphile-migrate reset --erase\n```\n\nAnd you're ready to go again!\n\n## Tests\n\n[Jest](https://jestjs.io/) is used for testing:\n\n```sh\nyarn test\n```\n\nRight now, it's using the development database.\nTODO: Use a separate testing database instead and set up new migration command.\n\n## Linting and code formatting\n\nThis repo is configured to run prettier with eslint, in addition to some other\ncommon linting rules for eslint and eslint typescript. The setup was created by\nfollowing [the eslint getting started][1] as well as [the prettier docs for\nintegrating with linters][2].\n\nTo run the linter and formatter for the whole project:\n\n```sh\nyarn run eslint .\n```\n\nTo run the linter and formatter for the whole project, only showing \"error\"s:\n\n```sh\nyarn run eslint --quiet .\n```\n\nTo run the linter and formatter for a specific file:\n\n```sh\nyarn run eslint \u003cpath-to-files\u003e\n```\n\nTo automatically apply fixes where possible use `--fix`:\n\n```sh\nyarn run eslint \u003cpath-to-files\u003e --fix\n```\n\n## API Documentation\n\nWe make use of swagger-ui-express and swagger-jsdoc to generate documentation\nfor certain API endpoints within the routes folder. Any openapi specifications\nthat are found within routes in jsdoc style comments will be automatically\nconverted into swagger-style API documentation. i.e. search for `@openapi` to\nfind samples of openapi docs that we use in the project. [This tutorial][5] covers\nthe basic concepts involved in writing an openapi specification.\n\n## SHACL Graphs\n\n[SHACL](https://www.w3.org/TR/shacl/) schemas have been migrated to https://github.com/regen-network/regen-registry-standards\n\nThese graphs can be stored too in the PostGres database in the `schacl_graph` table in order to be queried using GraphQL and used for client-side validation.\nThe `schacl_graph` table has an `uri` as primary key and a jsonb column `graph` where a SHACL graph is encoded as JSON-LD.\nFor instance, an entry with `http://regen.network/ProjectPlanShape` as URI can be created to store the SHACL graph to validate a project plan.\n\n## IRI Generation for JSON-LD data\n\nIRIs can be generated based on JSON-LD data using the following command:\n\n```sh\ncd iri-gen \u0026\u0026 yarn gen json_file_path\n```\n\nIRIs can be generated and inserted to the database using the `--insert`\nflag. Note: You need to create an `iri-gen/.env` when using this flag for\nthe staging or production environment. See `iri-gen/.env-example`.\n\n```sh\ncd iri-gen \u0026\u0026 yarn gen --insert json_file_path\n```\n\n## Manual Deployment\n\nIf you need to deploy the app manually, you can download [the Heroku CLI][4] and\nuse the following commands to deploy from your local environment.\n\n### Authenticate the Heroku CLI\n\n```\n$ heroku login\n```\n\nOptional: Test the above by viewing the apps available to the our team.\n\n```\n$ heroku apps --team=regen-network\n=== Apps in team regen-network\n...\nregen-server\nregen-server-staging\n...\n```\n\n### Checkout and synchronize the code you want to deploy\n\nIf you are deploying to staging:\n\n```\n$ git checkout dev\n$ git pull\n```\n\nIf you are deploying to production:\n\n```\n$ git checkout master\n$ git pull\n```\n\n### Set up a git remote for the heroku app you want to deploy\n\nIf you are deploying to staging:\n\n```\n$ heroku git:remote -r regen-server-staging -a regen-server-staging\n```\n\nIf you are deploying to production:\n\n```\n$ heroku git:remote -r regen-server -a regen-server\n```\n\nYour git remotes should like this:\n\n```\n$ git remote -v\norigin\tgit@github.com:regen-network/regen-server.git (fetch)\norigin\tgit@github.com:regen-network/regen-server.git (push)\nregen-server-staging\thttps://git.heroku.com/regen-server-staging.git (fetch)\nregen-server-staging\thttps://git.heroku.com/regen-server-staging.git (push)\nregen-server\thttps://git.heroku.com/regen-server.git (fetch)\nregen-server\thttps://git.heroku.com/regen-server.git (push)\n```\n\n### Deploy the dev or master branch to heroku\n\nTo finish a deploy to staging, we need to push the `dev` branch:\n\n```\n$ git push regen-server-staging dev:main\n```\n\nTo finish a deploy to production, we need to push the `master` branch:\n\n```\n$ git push regen-server master:main\n```\n\nNote: When you are deploying a branch, Heroku requires it to be `\u003cbranch\u003e:main`.\n\nFor more on this manual process, see [the Heroku docs][3].\n\n[1]: https://eslint.org/docs/user-guide/getting-started\n[2]: https://prettier.io/docs/en/integrating-with-linters.html\n[3]: https://devcenter.heroku.com/articles/git\n[4]: https://devcenter.heroku.com/articles/heroku-cli\n[5]: https://support.smartbear.com/swaggerhub/docs/tutorials/openapi-3-tutorial.html\n[6]: https://www.postgresql.org/docs/current/plpgsql-errors-and-messages.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregen-network%2Fregen-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fregen-network%2Fregen-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregen-network%2Fregen-server/lists"}