This repository contains the backend API for Root Rhythm, a full-stack web application designed to help plant enthusiasts manage their botanical collections with ease. This API serves as the central hub for all plant data, user authentication, and care management logic, providing a robust and scalable foundation for the Root Rhythm frontend application.
The API is built with Node.js and Express.js, leveraging MongoDB as its database. It's designed to be efficient, secure, and ready for deployment as a serverless function on platforms like Vercel.
- User & Plant Data Management: Securely handles user profiles and comprehensive CRUD (Create, Read, Update, Delete) operations for plant records.
- Organized Data Retrieval: Provides endpoints for fetching plants by user, category, latest additions, and care level (e.g., easy).
- RESTful API Endpoints: A well-defined set of API endpoints for seamless interaction with the frontend application.
- CORS Configuration: Securely configured for cross-origin requests from the Root Rhythm frontend application.
Below are the main API endpoints provided by the Root Rhythm backend:
| Endpoint | Method | Description | Request Body (Example) |
|---|---|---|---|
/users |
POST |
Creates a new user profile. | { uid: "firebaseUid", email: "user@example.com", ... } |
/user/:uid |
GET |
Retrieves a single user's profile by their unique ID. | None |
/home |
GET |
Fetches categories, latest plants, and easy care plants for the homepage. | None |
/category |
POST |
Adds a new plant category. | { category: "Tropical" } |
/categories |
GET |
Retrieves all available plant categories. | None |
/category/:category |
GET |
Retrieves plants belonging to a specific category. | None |
/plant |
POST |
Creates a new plant record. | { name: "Fiddle Leaf Fig", category: "Tropical", ... } |
/plants |
GET |
Retrieves all plant records. Supports sorting by query parameters (sortBy, order). |
None (/plants?sortBy=createdAt&order=descending) |
/latest |
GET |
Retrieves the 6 most recently added plants. | None |
/plant/:id |
GET |
Retrieves a single plant record by its MongoDB _id. |
None |
/plants/:uid |
GET |
Retrieves all plants associated with a specific user ID. | None |
/plant/:id |
PUT |
Updates an existing plant record by its MongoDB _id. |
{ name: "Updated Name", careLevel: "medium", ... } |
/plant/:id |
DELETE |
Deletes a plant record by its MongoDB _id. |
None |
/ |
GET |
Basic route to confirm the server is running. | None |
- Node.js: JavaScript runtime environment.
- Express.js: Fast, unopinionated, minimalist web framework for Node.js.
- MongoDB: NoSQL database for flexible and scalable data storage.
- MongoDB Node.js Driver: Official driver for connecting to and interacting with MongoDB.
cors: Node.js package for providing a Connect/Express middleware to enable Cross-Origin Resource Sharing.dotenv: Loads environment variables from a.envfile intoprocess.env.
To get the Root Rhythm backend API up and running on your local machine, follow these steps:
Ensure you have:
- Node.js (v18 or higher recommended)
- npm or Yarn
- A MongoDB Atlas cluster (recommended for ease of use) or a local MongoDB instance.
-
Clone the Repository: Start by cloning the backend repository to your local machine and navigating into its directory:
git clone https://github.com/ShaharearSabbir/root-rhythm-server cd root-rhythm-server -
Install Dependencies: Install all the necessary Node.js packages:
npm install # or yarn install -
Configure Environment Variables: Create a file named
.envin the root directory of the project (the same directory asindex.jsorserver.js). Add the following lines to this.envfile, replacing the placeholder values with your actual credentials:DB_USER=your_mongodb_username DB_PASS=your_mongodb_password PORT=5000
DB_USER: Your MongoDB Atlas database username.DB_PASS: Your MongoDB Atlas database password.PORT: The port number on which the server will run (e.g.,5000).
Important: Never commit your
.envfile to version control (Git)! It should be listed in your.gitignorefile to prevent exposing sensitive credentials. -
Run the Server: Finally, start the backend server:
npm start # or node index.jsThe server should start on the specified port (defaulting to 5000) and you'll see a confirmation message in your console, such as:
plant is growing on http://localhost:5000.