This project is an API designed for a real estate website where users can search for their ideal property in a specific city. The API is built using Bun and Fastify, with a PostgreSQL database running in a Docker Compose environment. The API provides separate routes for web users and administrators, allowing for property management and report generation.
- Project Overview
- Technologies Used
- Getting Started
- Environment Variables
- Running the Project
- API Endpoints
- Testing
This API allows users to search for properties, view detailed property information, and contact real estate agents. Admin users can manage property listings, generate reports, and control user access. Google Maps integration enables an interactive map with property listings.
- Go: A fast garbage collected language and memory efficient.
- CHI: Low-overhead backend framework for building APIs.
- PostgreSQL: Relational database management system.
- Docker Compose: Tool to define and manage multi-container Docker applications.
- JWT: JSON Web Tokens for authentication and secure access.
- Go: Install Bun by following the official guide.
- Docker: Make sure Docker and Docker Compose are installed on your machine.
Before running the project, you need to configure the environment variables in a .env
file. Here's an example configuration:
# .env
# Application port
APP_PORT=3333
# Node environment
NODE_ENV='development'
# JWT secret key (generate a secure key using `openssl rand -base64 32`)
JWT_SECRET='your_random_secret'
# PostgreSQL database configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=realestate_db
To generate a secure JWT secret for production, use the following command:
openssl rand -base64 32
git clone https://github.com/your-repo/real-estate-api.git
cd real-estate-api
go get
Ensure Docker is running and use the Docker Compose configuration to set up the PostgreSQL database:
docker-compose up -d
After the database is running, run the migrations to set up the tables:
#TODO
To run the server in development mode:
go run .
The API will be available at http://localhost:3333
.
These routes are accessible to regular users of the real estate site.
- Description: Get a list of properties available for sale or rent.
- Query Parameters:
city
: Filter by city.price_min
&price_max
: Filter by price range.type
: Filter by property type (e.g., house, apartment).
- Response: Array of properties.
- Description: Get detailed information about a specific property.
- URL Parameters:
id
: Property ID.
- Response: Detailed property information, including location, features, and price.
- Description: Send a message to the agent responsible for the property.
- Body:
propertyId
: ID of the property the message is about.name
: Sender's name.email
: Sender's email.message
: Message content.
- Response: Confirmation of message sent.
These routes require JWT authentication and are for administrative users.
- Description: Create a new property listing.
- Body:
name
: Property name.description
: Property description.type
: Property type (e.g., house, apartment).price
: Property price.location
: Property address.features
: Array of property features (e.g., number of rooms, area).
- Response: Newly created property.
- Description: Update the information of an existing property.
- URL Parameters:
id
: Property ID.
- Body:
name
: Property name (optional).description
: Property description (optional).price
: Property price (optional).- Any other field to update.
- Response: Updated property.
- Description: Delete a property listing.
- URL Parameters:
id
: Property ID.
- Response: Confirmation of deletion.
- Description: Generate property reports based on filters like status (available, sold), date range, etc.
- Response: Report data (e.g., PDF or Excel export).
You can run tests for the API endpoints using:
go test