Skip to content

DStojanac/Web-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web-app - Product Exchange Platform

A full-stack web application for exchanging products and items. Users can list products they want to trade, browse available items by category, search for specific products, and connect with other users for exchanges.

📋 Features

  • User Authentication: Secure registration, login, and logout functionality with bcrypt password hashing
  • Product Management: Users can create, view, and manage product listings
  • Category Browsing: Browse products organized by categories
  • Advanced Search: Search for products using keywords and filters
  • Image Upload: Upload product images with image processing using Sharp
  • User Dashboard: Personal dashboard to manage posted products and account settings
  • Admin Panel: Administrative dashboard for managing users and products
  • Wishlist: Save favorite products for later viewing
  • Role-Based Access: Different permissions for regular users and administrators
  • Flash Messages: User-friendly feedback messages for actions
  • Responsive Design: Mobile-friendly interface

🛠️ Technologies Used

Backend

  • Node.js - Runtime environment
  • Express.js - Web application framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling

Authentication & Security

  • bcrypt - Password hashing
  • express-session - Session management
  • connect-mongo - MongoDB session store
  • jsonwebtoken - JWT authentication
  • cookie-parser - Cookie parsing middleware

Frontend

  • EJS - Templating engine
  • express-ejs-layouts - Layout support for EJS

File Handling

  • Multer - File upload handling
  • Sharp - Image processing and optimization

Additional Tools

  • dotenv - Environment variable management
  • method-override - HTTP method override
  • connect-flash - Flash message middleware
  • cors - Cross-origin resource sharing
  • nodemon - Development auto-restart (dev dependency)

📦 Prerequisites

Before running this application, make sure you have:

  • Node.js (v14 or higher)
  • MongoDB (local installation or MongoDB Atlas account)
  • npm or yarn package manager

🚀 Installation

  1. Clone the repository

    git clone https://github.com/DStojanac/Web-app.git
    cd Web-app
  2. Install dependencies

    npm install
  3. Set up environment variables

    Create a .env file in the root directory with the following variables:

    PORT=3000
    MONGODB_URI=your_mongodb_connection_string
    SESSION_SECRET=your_session_secret_key
    JWT_SECRET=your_jwt_secret_key
  4. Start the application

    For production:

    npm start

    For development (with auto-restart):

    npm run dev
  5. Access the application

    Open your browser and navigate to:

    http://localhost:3000
    

📁 Project Structure

Web-app/
├── middleware/           # Custom middleware functions
│   ├── checkAuth.js     # Authentication middleware
│   └── isAdmin.js       # Admin authorization middleware
├── public/              # Static files
│   ├── css/             # Stylesheets
│   ├── img/             # Images
│   ├── js/              # Client-side JavaScript
│   └── uploads/         # Uploaded product images
├── server/
│   ├── config/          # Configuration files
│   │   └── db.js        # Database connection
│   ├── controllers/     # Route controllers
│   │   ├── adminController.js
│   │   ├── authController.js
│   │   ├── dashboardController.js
│   │   └── mainController.js
│   ├── models/          # Database models
│   │   ├── Product.js   # Product schema
│   │   └── User.js      # User schema
│   └── routes/          # Route definitions
│       ├── admin.js     # Admin routes
│       ├── auth.js      # Authentication routes
│       ├── dashboard.js # User dashboard routes
│       └── index.js     # Public routes
├── views/               # EJS templates
│   ├── layouts/         # Layout templates
│   ├── partials/        # Reusable components (header, footer)
│   ├── admin/           # Admin views
│   └── users/           # User views
├── .env                 # Environment variables (create this)
├── package.json         # Project dependencies
├── server.js            # Application entry point
└── README.md            # Project documentation

🗄️ Database Models

User Model

{
  username: String (required, unique),
  email: String (required, unique),
  password: String (required, hashed),
  role: String (enum: ['admin', 'user'], default: 'user'),
  wishlist: [ObjectId] (references Product),
  postedProducts: [ObjectId] (references Product)
}

Product Model

{
  name: String (required),
  description: String,
  price: Number (required),
  tradeFor: String (required),
  category: String (required),
  contactPhone: String (required),
  email: String (required),
  user: ObjectId (references User),
  imageCover: String (required),
  images: [String],
  published: Boolean (default: false)
}

🔐 Environment Variables

Create a .env file with the following variables:

Variable Description Example
PORT Server port number 3000
MONGODB_URI MongoDB connection string mongodb://localhost:27017/webapp or mongodb+srv://...
SESSION_SECRET Session encryption key your_random_secret_key
JWT_SECRET JWT token secret your_jwt_secret_key

🎓 Academic Project

This web application was created as a university project to demonstrate full-stack web development skills including user authentication, database management, file uploads, and RESTful API design.

About

Web application for exchanging things created for university project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors