Skip to content
Bdair2002 edited this page Jun 13, 2024 · 6 revisions

Welcome to the GreenThumb wiki!

Introduction

Our main goal for this project was to build a well-structured application with the best possible architecture. GreenThumb is designed using the Model-View-Controller (MVC) architectural pattern, ensuring a clear separation of concerns and making the codebase more maintainable and scalable. The project utilizes RESTful APIs to enable seamless communication between the client and server, adhering to standard web protocols and making it easy to integrate with other systems.

In addition to MVC, we have implemented the Factory Design Pattern to manage object creation, promoting code reusability and adhering to good design principles. This pattern helps us achieve a clean and modular code structure, making it easier to extend and maintain the application.

We also used Sequelize, which is an ORM (Object Relational Mapper), to handle database interactions efficiently. Sequelize simplifies the process of defining models for our application, mapping them to database tables, and performing CRUD operations. It provides powerful features such as migrations, associations between models, and support for multiple database dialects, ensuring robust and scalable data management.

Throughout the development process, we have focused on following best practices and good design principles, ensuring that the GreenThumb project is robust, scalable, and easy to work with. Whether you are a developer looking to contribute or a user wanting to understand more about the project, this wiki aims to provide comprehensive information and documentation to help you get started.

File Structure

image

The config folder contains the config.js file which holds the configurations for the Sequelize module.

The models folder contains the definitions of the application's data structures and the relationships between them. These are typically Sequelize models that define the schema for the database tables and include methods for querying and manipulating data. Our Models are: Users, articles, crops, events, garden, partnership, plots and resources

The Views folder holds our system's static views (pages). These are the templates that define the user interface and are rendered by the view engine (e.g. Pug) to display data to the user. It includes files such as HTML or Pug templates which are responsible for the layout and presentation of the content.

The Controllers folder contains the logic that handles user input and interacts with the models to fetch or update data. Each controller corresponds to a specific section of the application and contains methods for various actions such as creating, reading, updating, and deleting records

The Routes folder defines the application's URL endpoints and maps them to the corresponding controller actions. It acts as the intermediary that directs incoming HTTP requests to the appropriate controllers based on the URL patterns.

The Public folder contains static assets such as CSS, JavaScript, images, and other files that are served directly to the client. These files are used to enhance the look and functionality of the application's front-end.

The Utils folder contains utility functions and helper modules that are used across the application to perform common tasks or calculations.

The docker folder contains the Dockerfile to set up Mysql in the docker image, and the initialization of green_thumb data base inside it.

The db_associations folder contains all the database relations and defines the necessary foreign keys.

The middleware folder contains the middlewares used in the routes, to handle each request and do different tasks.

This File structuring system is following the MVC standards, and we worked around it because it makes it easier for us to add up new features, maintain the code and scale it, we don't need more complex systems because our project is fairly simple and does not require heavy testing.

Setting Up The Project

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed Node.js and npm.
  • You have installed Docker if you plan to use Docker for containerization.
  • You have a running instance of MySQL or access to a MySQL database.

Installation

To set up the project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/Bdair2002/GreenThumb.git
    cd GreenThumb
  2. Install dependencies:

    npm install
  3. Configure the environment:

    Create a .env file in the root directory and add your configuration settings. Below is an example:

    DB_HOST=localhost
    DB_USER=root
    DB_PASSWORD=yourpassword
    DB_NAME=greenthumb
    DB_DIALECT=mysql
    
  4. Set up the database:

    Run the Sequelize migrations to set up the database schema:

    npx sequelize-cli db:migrate
  5. Start the application:

    npm start

    The application will start running on the specified port (usually http://localhost:3000).

Running with Docker

If you prefer to use Docker, follow these steps:

  1. Build the Docker image:

    docker build -t mysql_db .
  2. Run the Docker container:

    npm run database

    Or on MAC

    npm run databaseMAC

    The application will be available at http://localhost:3000.

API Documentation

To explore and test the API endpoints, you can use Postman. Import the Postman collection from the repository to get started.

UML Diagram

AdvancedSWE_UML-1 drawio

Clone this wiki locally