A modern full-stack e-commerce application built with Node.js, Express, TypeScript, Prisma, and MySQL. This application provides both admin management capabilities and client-facing shopping features.
- User registration and authentication
- Product browsing and search
- Shopping cart management
- Order placement and tracking
- User profile management
- Dashboard with analytics
- Product management (CRUD operations)
- User management
- Order management and status updates
- File upload for product images
- Backend: Node.js with Express and TypeScript
- Database: MySQL with Prisma ORM
- Authentication: Passport.js with local strategy
- Session Management: Express sessions with Prisma store
- File Upload: Multer for handling image uploads
- Validation: Zod for schema validation
- Security: Bcrypt for password hashing
Before running this application, ensure you have the following installed:
- Node.js (v16 or higher)
- npm or yarn
- MySQL (v8.0 or higher)
- Git
git clone <repository-url>
cd paulstore-fullstacknpm installCreate a .env file in the root directory by copying from the example:
cp .env.example .envConfigure your environment variables in .env:
PORT=8080
NODE_ENV=development
DATABASE_URL="mysql://root:root@localhost:3306/paulstore"Note: The configuration above uses default MySQL credentials (root:root). If you have different MySQL credentials, replace root:root with your actual username:password. Make sure your MySQL server is running on port 3306 and you have created the paulstore database.
First, create a MySQL database:
CREATE DATABASE paulstore;npx prisma generatenpx prisma migrate dev --name init-dbsThis command will:
- Create all necessary tables
- Seed the database with initial data (admin user, roles, sample products)
To explore your database with Prisma Studio:
npx prisma studionpm run devnpm startThe application will be available at http://localhost:8080
After running migrations, the following default accounts are available:
- Email:
[email protected] - Password:
nvminh162 - Role: Administrator
- Email:
[email protected] - Password:
nvminh162 - Role: Regular User
├── src/
│ ├── app.ts # Application entry point
│ ├── config/ # Configuration files
│ │ ├── client.ts # Prisma client setup
│ │ ├── constants.ts # Application constants
│ │ ├── db.ts # Database configuration
│ │ └── seed.ts # Database seeding
│ ├── controllers/ # Route controllers
│ │ ├── admin/ # Admin panel controllers
│ │ └── client/ # Client-side controllers
│ ├── middleware/ # Custom middleware
│ ├── routes/ # Route definitions
│ ├── services/ # Business logic
│ ├── validation/ # Input validation schemas
│ └── views/ # EJS templates
├── prisma/
│ ├── schema.prisma # Database schema
│ └── migrations/ # Database migrations
├── public/ # Static assets
│ ├── admin/ # Admin panel assets
│ ├── client/ # Client-side assets
│ └── images/ # Uploaded images
└── package.json
The project includes a Postman collection for API testing:
- Location:
src/routes/nodejs-pro.postman_collection.json - Import this file into Postman to test API endpoints
- Authentication:
/api/auth/* - Users:
/api/users/* - Products:
/api/products/* - Orders:
/api/orders/* - Cart:
/api/cart/*
The application uses the following main entities:
- Users: Customer and admin accounts
- Roles: User permissions (ADMIN, USER)
- Products: E-commerce products
- Cart: Shopping cart functionality
- Orders: Order management
- Sessions: User session storage
# Development
npm run dev # Start development server with hot reload
# Production
npm start # Build and start production server
# Database
npx prisma generate # Generate Prisma client
npx prisma migrate dev # Run database migrations
npx prisma studio # Open database admin interface
npx prisma db seed # Seed database with initial data
# Debug
npm run start:debug # Start with debugging enabledThe application supports file uploads for:
- User avatars
- Product images
Uploaded files are stored in the public/images/ directory.
- Password hashing with bcrypt
- Session-based authentication
- CSRF protection
- Input validation with Zod
- Secure file upload handling
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
-
Database Connection Error
- Ensure MySQL is running
- Verify DATABASE_URL in
.envfile - Check database credentials
-
Migration Errors
- Ensure database exists
- Check Prisma schema syntax
- Try
npx prisma migrate resetfor development
-
Port Already in Use
- Change PORT in
.envfile - Kill process using the port:
npx kill-port 8080
- Change PORT in
This project is licensed under the ISC License.
For questions or support, please contact the development team.