This project provides the backend for the BSOSpace blog using Elysia.js as the web framework, PostgreSQL for the database, Redis for caching, and Prisma as the ORM. Docker Compose is used to orchestrate the services in both development and production environments.
Before you begin, ensure you have the following installed on your machine:
First, clone the repository to your local machine:
git clone https://github.com/BSO-Space/BSOSpace-Blog-Backend.git
cd BSOSpace-Blog-Backend
You need to create .env
files for both development and production environments.
- For development:
cp .env.example .env.dev
- For production:
cp .env.example .env.prod
Update the .env.dev
and .env.prod
files with the appropriate values:
- PostgreSQL settings (
PG_USER
,PG_PASSWORD
,PG_DATABASE
,PG_PORT
) - Redis settings (
REDIS_PORT
) - PgAdmin settings (
PGADMIN_EMAIL
,PGADMIN_PASSWORD
,PGADMIN_PORT
) - Backend ports (
DEV_BACKEND_PORT
,PROD_BACKEND_PORT
)
Here's an example of a .env.dev
file:
# PostgreSQL Configuration
PG_USER=dev_pg_user
PG_PASSWORD=dev_pg_password
PG_DATABASE=dev_database
PG_PORT=5432
# Redis Configuration
REDIS_PORT=6379
# PgAdmin Configuration
PGADMIN_EMAIL=[email protected]
PGADMIN_PASSWORD=admin123
PGADMIN_PORT=5050
# Backend Development Port
DEV_BACKEND_PORT=3000
# Prisma Database URL
DATABASE_URL=postgresql://dev_pg_user:dev_pg_password@postgres:${PG_PORT}/dev_database
To start the application in development mode:
docker-compose --env-file .env.dev up
This will:
- Start the development version of the Elysia.js backend
- Launch PostgreSQL, Redis, and PgAdmin services
- Expose the backend on the port specified in
DEV_BACKEND_PORT
To run the application in production mode:
docker-compose --env-file .env.prod up
This will:
- Start the production version of the Elysia.js backend
- Launch PostgreSQL, Redis, and PgAdmin services
- Expose the backend on the port specified in
PROD_BACKEND_PORT
- Backend:
- Development:
http://localhost:<DEV_BACKEND_PORT>
- Production:
http://localhost:<PROD_BACKEND_PORT>
- Development:
- PgAdmin:
- Access it at
http://localhost:<PGADMIN_PORT>
using the credentials set in the.env
file
- Access it at
Prisma is used to manage the PostgreSQL database. Use the following commands to run migrations and open Prisma Studio.
To apply database migrations:
- For development:
docker-compose run backend-dev npx prisma migrate dev
- For production:
docker-compose run backend-prod npx prisma migrate deploy
Prisma Studio is a graphical interface for managing your database:
docker-compose run backend-dev npx prisma studio
To stop the running services, use the following command:
docker-compose down
This setup uses Docker volumes for persistent storage of both PostgreSQL and Redis data, meaning that data will be retained even after stopping or restarting the containers.
- Make sure you have correctly set up the
.env
files and filled in the necessary variables. - Ensure Docker and Docker Compose are properly installed and running.
- If there are port conflicts, update the relevant port numbers in the
.env
files.