A generic backend with Redis, Prisma ORM (to PgSQL) and Ethers setup. It also has a signature-based authorization middleware, that maps a common signature to a public key.
You need to have the following:
- A Redis server running
- A PostgreSQL server running
- A gRPC URL and ChainID
The connection information for these are stored in .env
. See an example file under environments.
Just run yarn
to install the packages and then yarn run start
to start the server. An environment file .env
is required as follows:
PORT=<the port to listen>
Start the backend in a terminal with yarn run start:test
, and in another run yarn test
to execute unit tests. You can skip some tests with .skip
if wanted, as linter will not be happy with the code when you comment stuff out. Note that Jest also sets NODE_ENV
variable to be test
when during testing.
The entry point is app.ts
. The other files are structured as follows:
- clients: API setups and accessors.
- config: configurations, mostly overwritten by environment variables.
- constants: non-configuration constants, whether it is a string literal used around or some parameter.
- controllers: final entry-points for each endpoint. We expect the responses to be made from within this file.
- interfaces: custom TypeScript interfaces.
- middlewares: Express middlewares, such as validation.
- routes: Express routes, which define the endpoint URLs.
- tests: Jest unit-test files.
- utilities: general utility files.
- validators: Joi validator schemes for endpoints. Note that we can have non-endpoint schemas here too, which are used to build up the endpoint schemas.
Within the tests folder, there are also utilities, mock data and isolated scripts.
Google TypeScript code formatting & linting is used as an extension of eslint
and prettier
. I have also included my VSCode settings, though you should feel free to change them.