Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adarshaacharya/bricks
🧱 Bricks - all in one real estate marketplace.
https://github.com/adarshaacharya/bricks
docker nestjs oauth2 prisma redis s3-bucket sendgrid
Last synced: 2 months ago
JSON representation
🧱 Bricks - all in one real estate marketplace.
- Host: GitHub
- URL: https://github.com/adarshaacharya/bricks
- Owner: adarshaacharya
- Created: 2024-02-12T05:33:01.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-05-31T20:45:43.000Z (7 months ago)
- Last Synced: 2024-05-31T21:57:03.468Z (7 months ago)
- Topics: docker, nestjs, oauth2, prisma, redis, s3-bucket, sendgrid
- Language: TypeScript
- Homepage:
- Size: 1.09 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bricks
Bricks is a backend api for a real estate marketplace.
# Features
- User Authentication with Google and Github or Email and Password
- Three user roles : Super Admin, Admin, and User
- Super Admin can manage all the users and properties
- Admin can manage the properties (CRUD operations)
- User can view the properties and schedule meetings with the Admin to view the properties# Running the application locally
- To run the application locally, you need to have Docker installed on your machine. Run the following command to start the docker container:
```sh
docker compose up
```- Copy the `.env.example` file to `.env` and update the environment variables accordingly.
- Reset the database schema and seed the database with the following command:
```sh
npx prisma migrate reset
```- Start the backend server with the following command:
```sh
pnpm run start:dev
```Server will start on `http://localhost:9000`
- You can import postman collection from the [docs/postman](docs/postman/) folder to test the API endpoints.
- View the API documentation at `http://localhost:9000/api/v1/docs`
- View redis cache via redis commander at `http://localhost:5540/`
# Integrating Google Auth
To generate the env variable likes `CLIENT_ID` and `CLIENT_SECRET`, you need to create a project in Google Cloud Platform and enable the Google Auth API.
Visit this [blog](https://thriveread.com/nestjs-oauth-serve-with-google-and-passport/?expand_article=1)
for reference.The final outcome should look like this :
Notice : Redirect URL should be `http://localhost:9000/auth/google/callback`
where `http://localhost:9000` is the base URL of the Backend application.
If you host backend application on a different URL, you need to change the redirect URL accordingly. eg : `api.dev.com/auth/google/callback`
Here's is how the flow looks like:
- User clicks on the login button
- Call the `http://localhost:9000/api/v1/auth/google` endpoint
- This will redirect to the Google Auth page
- User enters the credentials
- Google will redirect to the `http://localhost:9000/auth/google/callback` with the code
- Backend will exchange the code with the Google Auth server and get the user details
- Backend will create a JWT token and send it back to the frontend in cookies
- Backend will redirec the user to `localhost:3000` with the JWT token in the cookies
- Frontend will store the in the cookies and use it for further requests# Github Auth
- Head over to the [Github Developer Settings](https://github.com/settings/applications/new) and create a new OAuth App
the configuration should look like this:
Notice : Redirect URL should be `http://localhost:9000/auth/github/callback`
where `http://localhost:9000` is the base URL of the Backend application.
If you host backend application on a different URL, you need to change the redirect URL accordingly. eg : `api.dev.com/auth/github/callback`
Here's is how the flow looks like:
- User clicks on the login button
- Call the `http://localhost:9000/api/v1/auth/github` endpoint
- This will redirect to the Github Auth page
- User enters the credentials
- Github will redirect to the `http://localhost:9000/auth/github/callback` with the code
- Backend will exchange the code with the Github Auth server and get the user details
- Backend will create a JWT token and send it back to the frontend in cookies
- Backend will redirec the user to `localhost:3000` with the JWT token in the cookies
- Frontend will store the in the cookies and use it for further requests# Commands
Database seeding happens in two ways with Prisma ORM: manually with `prisma db seed` and automatically in `prisma migrate dev` and prisma migrate reset.
# Building Docker Image
To build the docker image, run the following command:
```sh
docker build -t bricks .
docker images # to view the image
```# Running the container using the image
To run the container using the image, run the following command:
```sh
docker run -p 9000:9000 bricks --env ACCESS_TOKEN_JWT_KEY="secret" --env REFRESH_TOKEN_JWT_KEY="secret" --env S3_REGION="ap-south-1" # ... other env variablesdocker ps # to view the running container
```