Certainly! Below is a detailed prompt formatted in a code block that you can use for your custom Large Language Model (LLM). This prompt includes all the necessary details for an MVC project in Node.js that involves login and signup functionality for farmers and users who wish to purchase crops, vegetables, fruits, etc.
I want you to create a **Node.js project** that uses the **MVC (Model-View-Controller)** architecture. The project will serve as a platform where farmers can list their crops/vegetables/fruits/etc., and regular users (buyers) can log in to purchase these items. Below are the requirements and specifications for the project. Ensure the code is clean, modular, and scalable:
---
### 1. Project Name
The project should be called: `AgriMarket`
---
### 2. Technologies to Use:
- Backend: **Node.js (Express)** for the main application logic.
- Database: **MongoDB** (using Mongoose for database interactions).
- Authentication: **JWT** (JSON Web Tokens) for secure authentication.
- Password Hashing: **bcrypt** for encrypting user passwords.
- Views: Use **EJS (Embedded JavaScript)** for rendering dynamic frontend pages.
- Middleware: Use **express-session** for session management and **body-parser** for parsing incoming requests.
- API Testing: Use **Postman** for API testing.
- Validation: Form input should be validated using **Joi** or a similar validation library.
---
### 3. Folder Structure (MVC Architecture)
The project structure should follow MVC principles:
AgriMarket/
│
├── controllers/ -> Contains logic for handling routes
├── models/ -> Database models using Mongoose
├── routes/ -> Declarative route definitions
├── services/ -> Functional services (e.g., email, JWT generation)
├── public/ -> Public assets (CSS, JS, images)
├── views/ -> EJS templates for frontend
├── middlewares/ -> Custom middleware files
├── utils/ -> Helper functions (e.g., error handling)
├── .env -> Environment variables for sensitive data
├── app.js -> Main entry point for the application
└── package.json -> Dependencies and metadata
---
### 4. User Roles and Features:
#### 4.1. **Farmers**
- **Signup**:
- A farmer can create an account by providing information such as:
- Name
- Email
- Password
- Phone Number
- Farm Details (e.g., location, farm name, size)
- Validate inputs for accuracy before saving to the database.
- Passwords must be hashed before saving.
- **Login**:
- Farmers must log in with their `email` and `password`.
- Generate a **JWT token** upon successful login, and use it for session management.
- **Dashboard** (Post-Login):
- Farmers can list new crops/vegetables/fruits for sale.
- Each item listing must include:
- Product name
- Description
- Image URL
- Category (crop/vegetable/fruit/meat/etc.)
- Quantity available
- Price (per unit)
- Farmers can edit/delete their listings.
- Farmers can view feedback/reviews from buyers.
#### 4.2. **Buyers (Users)**
- **Signup**:
- A user can create an account by providing:
- Name
- Email
- Password
- Passwords must be hashed before saving.
- **Login**:
- Users must log in with their `email` and `password`.
- Generate a **JWT token** upon successful login.
- **Dashboard** (Post-Login):
- Users can browse products listed by farmers.
- Filters (optional):
- By category (crop/fruit/vegetable/etc.)
- By price range
- By location of farmer
- Users can add products to a shopping cart.
- Users can place orders and provide reviews for products.
- Users should see their order history.
---
### 5. Routes:
Below is the route structure. Use **Express Router** to organize the endpoints.
#### 5.1. Authentication Routes
| HTTP Method | Endpoint | Description |
|-------------|---------------------|------------------------|
| POST | `/auth/signup` | Signup for Farmers/Users |
| POST | `/auth/login` | Login for Farmers/Users |
| GET | `/auth/logout` | Logout |
#### 5.2. Farmer Routes
| HTTP Method | Endpoint | Description |
|-------------|----------------------------|---------------------------------|
| POST | `/farmer/products` | Add a new product listing |
| PUT | `/farmer/products/:id` | Edit a product listing |
| DELETE | `/farmer/products/:id` | Delete a product listing |
| GET | `/farmer/orders` | View all orders for a farmer's products |
#### 5.3. Buyer Routes
| HTTP Method | Endpoint | Description |
|-------------|-----------------------------|---------------------------------|
| GET | `/buyer/products` | Browse all products |
| GET | `/buyer/products/:id` | View details of a product |
| POST | `/buyer/cart` | Add product to shopping cart |
| POST | `/buyer/orders` | Place an order |
| GET | `/buyer/orders` | View order history |
---
### 6. Middleware
Create the following middleware files:
1. **authMiddleware.js**:
- Verify if the user is logged in by checking the JWT token.
- Restrict certain routes to authenticated users only.
2. **roleMiddleware.js**:
- Check user roles (Farmer or Buyer) to restrict access to specific endpoints.
3. **errorHandler.js**:
- Handle and standardize error responses for invalid routes, wrong input, etc.
---
### 7. Database Models (MongoDB with Mongoose):
Below are the Mongoose Schemas to define.
#### 7.1. **User Model**
```javascript
{
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
role: { type: String, enum: ['Farmer', 'Buyer'], required: true }
}
7.2. Product Model
{
name: { type: String, required: true },
description: { type: String },
imageURL: { type: String },
category: { type: String, required: true },
quantity: { type: Number, required: true },
price: { type: Number, required: true },
farmerID: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } // Relations
}
7.3. Order Model
{
buyerID: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
products: [
{
productID: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
quantity: { type: Number }
}
],
total_price: { type: Number, required: true },
placedAt: { type: Date, default: Date.now }
}
8. Views (EJS)
- Create the following views:
signup.ejs: Signup page for both Farmers and Buyers.
login.ejs: Login page.
farmerDashboard.ejs: Farmer’s dashboard to manage product listings.
buyerDashboard.ejs: Buyer’s dashboard to browse products and manage their cart.
9. Deployment
- Use dotenv for storing environment variables (e.g., database URL, JWT secret key).
- Deploy on a cloud platform such as Render or Heroku.
- Use GitHub Actions for CI/CD to run linting, testing, and deployment workflows.
10. Documentation
- Provide clear API documentation in the form of a markdown file (
API_DOC.md) with detailed examples for every route.
- Include a README with setup instructions and project details.
Do not leave out any detail while generating the code and structure for this project. Ensure code readability and proper use of comments wherever applicable. The prompt is now complete.