Empowering Urban Gardening and Sustainable Living
Explore the docs »
View Demo
·
Report Bug
GreenThumb is a collaborative project for the Advanced Software Engineering course at Spring 2024, led by Dr. Amjad AbuHassan. Our mission is to empower urban gardening and promote sustainable living through a robust backend API platform. The project is designed to facilitate community-driven food production, knowledge sharing, and resource optimization among urban gardeners and enthusiasts.
-
Community Gardens Directory
- Lists community gardens with details like locations, available plots, and growing conditions.
- Helps users find and join local gardening initiatives.
-
Crop Planning and Tracking
- Enables users to plan and monitor gardening activities.
- Includes features for crop rotations, planting schedules, and harvest records.
-
Knowledge Sharing
- A library of gardening guides, tutorials, and best practices.
- Content contributed by experienced gardeners and organizations.
-
Resource Exchange
- Platform for exchanging or sharing gardening resources (tools, seeds, compost, surplus produce).
- Aims to reduce waste and promote sustainability.
-
Volunteer Coordination
- Facilitates the organization of volunteers for garden maintenance, events, and workshops.
- Enhances community collaboration.
-
Local Partnership Integration
- Connects with local nurseries, farms, and organizations.
- Promotes products, services, and events relevant to urban gardening.
-
User Privacy and Data Security
- Passwords are encrypted before getting saved in the database.
- Unique usernames and emails per user.
- Only admin and authorized user can udpate or delete a resource.
-
JSON Web Token (JWT) Support
- Our project comes with built-in support for JSON Web Tokens (JWT), providing a secure and efficient way to manage authentication and authorization.
-
Roles
- Our system has few roles, which are: user, admin and partner
-
Error Handling and Logging
- We used Morgan library to log our API requests to debug and troubleshoto bugs.
- Sequelize comes with a built in logger to log SQL queries.
- Global Util error handler
-
Safety
Follow these steps to install this project with NPM.
Follow these steps to set up the project on your local machine:
-
Clone the repository
git clone https://github.com/Bdair2002/GreenThumb.git cd GreenThumb -
Install dependencies
npm install
-
Set up the database
There are two ways of running the database, you can either install MySQL server, or install docker and let it handle everything for you. but first you will have to configure it here. If you use MySQL, then create a database and name it green_thumb, then Sequelizer will handle all the required connections.
-
Set up .env
Create a
.envfile in the root directory of the project. Add the following environment variables to it:- MYSQL_ROOT_PASSWORD: Password for the MySQL root user.
- PORT: Port number for your application (e.g., 3000).
- JWT_SECRET: Secret key for JWT (JSON Web Token) encryption.
- JWT_EXPIRES_IN: Expiration time for JWT tokens.
- JWT_COOKIE_EXPIRES_IN_DAYS: Expiration time for JWT cookies.
- EMAIL_USERNAME: Username for the email service.
- EMAIL_PASSWORD: Password for the email service.
- EMAIL_HOST: SMTP host for sending emails.
- EMAIL_PORT: SMTP port number.
These environment variables are used throughout the application to configure various settings. Ensure the
.envfile is not committed to version control for security reasons. You can use tools likedotenvto load these variables into your Node.js application during development. -
Run the application
npm start
-
Build javascript bundle
npm run build:js
If you prefer to use Docker, follow these steps:
-
Build the Docker image
cd database docker build -t mysql_db .
-
Run the Docker container
We created a short-hand script to run the database for you. All you have to do is write the folllowing
npm run database
if you are using MAC, write the following
npm run databaseMAC
- Provider: Open Weather Map
- Description: Used to fetch current weather conditions and forecasts.
- Provider: Soilgrids
- Description: Provides soil data such as composition, pH levels, and fertility.
- Provider: Tomorrow Climate API
- Description: Retrieves climate data including temperature trends, rainfall patterns, etc.
- Provider: Trefle
- Description: API used for searching and retrieving information about various plant species.
- Provider: MapBox
- Description: Provides mapping and geographical data services for location-based functionalities.
- Provider: Node Mailer
- Description: API used for sending transactional emails such as account notifications, password resets, etc.
Before using the API endpoints, you need to authenticate using JWT (JSON Web Token).
- Endpoint:
POST /GreenThumb/v1/users/signup - Description: Registers a new user.
- Request Body:
{ "username": "username", "firstname": "first_name", "lastname": "last_name", "email": "[email protected]", "password": "12345", "passwordconfirm": "12345" "role":"admin" // this is optional and the default is 'user' } - Response:
{ "status": "success", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzE4MjIxOTgxLCJleHAiOjE3MTgzMDgzODF9.agu0aehWqIMA_DGzvAbYGOXZEmG_k_N64hnwT_cUuLQ", "data": { "user": { "role": "user", "id": 1, "username": "username", "firstname": "first_name", "lastname": "last_name", "email": "[email protected]", "updatedAt": "2024-06-12T19:53:00.850Z", "createdAt": "2024-06-12T19:53:00.850Z", "passwordChangedAt": 1718221980086 } } }
- Endpoint:
POST /GreenThumb/v1/users/login - Description: Login to an existing account.
- Request Body:
{ "email": "[email protected]", "password": "12345" } - Response:
{ "status": "success", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzE4MjIyMTI4LCJleHAiOjE3MTgzMDg1Mjh9.hbaTwn2jufAvAV-V2OVjabjimdmXmFj2-0l2tv6Zg-c", "data": { "user": { "id": 1, "username": "username", "firstname": "first_name", "lastname": "last_name", "email": "[email protected]", "role": "user", "Event_ID": null, "createdAt": "2024-06-12T19:53:00.000Z", "updatedAt": "2024-06-12T19:53:00.000Z", "EventID": null } } }
RESTFUL APIs are implemented to fetch and manipulate different resources.
-
Endpoint:
POST /GreenThumb/v1/gardens/ -
Description: Create a new garden.
-
Request Body:
{ "Name":"AnNajah Garden", "Location":"nablus", "Plots":3, "Sunlight":true, "SoilType":"red", "WaterSource":"Rivers", "Latitude":"35.25444", "Longitude":"32.22111" } -
Response:
{ "id": 1, "Name": "AnNajah Garden", "owner_id": 1, "Location": "nablus", "PlotsNumber": 3, "Sunlight": true, "SoilType": "red", "WaterSource": "Rivers", "Latitude": "35.25444", "Longitude": "32.22111", "updatedAt": "2024-06-12T20:01:21.060Z", "createdAt": "2024-06-12T20:01:21.060Z" }
For detailed documentation including all endpoints, request/response formats, authentication methods, and examples, please visit the API Documentation page.
These screenshots are indicative and may not represent the final design. For a more interactive experience, please visit the live application or demo environment.
