Skip to content

hrishix6/backend-template-2024

Repository files navigation

Opinionated backend project template

This is opinionated project template for backend in 2024.

Base

Libraries

  • zod - validations.
  • typedi - depedency injection tool.
  • dotenv - config loader in development.
  • kysely - query builder for postgres.
  • winston - logger.

Code quality & formatting

Other integrations

Setup

  1. You need Docker installed, it's required.

  2. Clone this repo.

  3. Create a .env file in the root directory,

 # server config
 APP_PORT=<your port>
 FRONTEND_ORIGINS=<comma separated list of frontend origins>
 FRONTEND_METHODS=<comma separated list of HTTP methods you want to allow>

 #db config
 DB_HOST=<database hostname>
 DB_PORT=5432
 DB_NAME=<database name>
 DB_USER=<database username>
 DB_PASS=<database password>

 # cache config
 CACHE_ENABLED=<true | false to enable/disable cache>
 CACHE_HOST=<cache hostname>
 CACHE_USER=<cache username>
 CACHE_PASS=<cache password>
 CACHE_PORT=6379
  1. create a integrations.env in root of the project,
 # Pgadmin 4 config , use these to login to pgAdmin
 PGADMIN_DEFAULT_EMAIL=admin@admin.com
 PGADMIN_DEFAULT_PASSWORD=12345

 # Postgresql config , these will be default user/pass credentials
 POSTGRES_USER=postgres
 POSTGRES_PASSWORD=postgres

 # redis-commander config, make sure redis settings below match your redis.conf settings.
 HTTP_USER=admin@admin.com
 HTTP_PASSWORD=12345
 PORT=8080
 REDIS_PORT=6379
 REDIS_HOST=cache
 REDIS_USERNAME=redis-user
 REDIS_PASSWORD=hrishix6
  1. Add your database schema commands in src/database/schema.sql, it will be used to initialize a database in postgres container.

  2. If you have your open api spec , paste it in src/openapi/spec.json, the documentation for api will be available at http://localhost:5000/docs (open).

How to run

$ docker compose up --build
  • Pgdmin4 will be accessible at http://localhost:8888 (open)

  • Redis GUI will be accessible at http://localhost:8080 (open)

  • Postgresql will be accessible at postgres://<db-user>:<db-password>@localhost:5432/<your-db-name>.

  • Redis server will be accessible at localhost:6379

  • As database and cache are accessible in docker network and localhost , during development you can switch hostname to localhost and run.

License

MIT