Skip to content

frank2ny/myRuby

Repository files navigation

ERP System - Warehouse & Hardware Store Management

A comprehensive full-stack ERP system built with Node.js, Express.js, React, and MySQL for managing warehouse and hardware store operations.

πŸš€ Features

Backend Features

  • Authentication & Authorization: JWT-based authentication with role-based permissions
  • Database Management: Prisma ORM with MySQL database
  • RESTful API: Complete CRUD operations for all entities
  • Stock Management: Real-time stock tracking, transfers, and movements
  • Sales & Purchases: Complete sales and purchase order management
  • Payment Processing: Multi-method payment handling with partial payments
  • Reports & Analytics: Comprehensive reporting with Excel export
  • Backup & Restore: Database backup and restore functionality
  • Security: Rate limiting, CORS, helmet security headers

Frontend Features

  • Modern UI: React with TailwindCSS for responsive design
  • State Management: React Query for server state management
  • Navigation: React Router with protected routes
  • Dashboard: Real-time KPIs and analytics
  • Stock Management: Visual stock levels and transfer interface
  • Sales Interface: Intuitive sales processing with payment handling
  • Reports: Interactive reports with filtering and export
  • Backup Management: File upload and download for database backups

πŸ—οΈ Architecture

Backend Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MySQL with Prisma ORM
  • Authentication: JWT with bcrypt password hashing
  • Validation: Express-validator
  • Security: Helmet, CORS, Rate limiting
  • File Processing: Multer for file uploads
  • Excel Export: XLSX library

Frontend Stack

  • Framework: React 18
  • Build Tool: Vite
  • Styling: TailwindCSS
  • State Management: TanStack Query (React Query)
  • Routing: React Router v6
  • HTTP Client: Axios
  • Icons: Lucide React

Database Schema

  • Users & Roles: Role-based access control
  • Products & Categories: Product catalog management
  • Shops: Multi-location support
  • Stock Management: Real-time inventory tracking
  • Sales & Purchases: Transaction management
  • Customers & Suppliers: Business relationship management
  • Payments: Payment tracking and management
  • Settings: System configuration

πŸ“¦ Installation & Setup

Prerequisites

  • Node.js (v18 or higher)
  • MySQL (v8 or higher)
  • npm or yarn

Backend Setup

  1. Navigate to backend directory:

    cd backend
  2. Install dependencies:

    npm install
  3. Configure environment variables: Create .env file in backend directory:

    DATABASE_URL="mysql://root:@localhost:3306/erp"
    JWT_SECRET="your_super_secret_jwt_key_change_in_production"
    NODE_ENV="development"
    PORT=3001
  4. Set up database:

    # Generate Prisma client
    npx prisma generate
    
    # Run database migrations
    npx prisma migrate dev --name init
    
    # Seed the database
    npm run db:seed
  5. Start the backend server:

    npm run dev

Frontend Setup

  1. Navigate to frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev
  4. Access the application: Open http://localhost:3000 in your browser

πŸ” Default Login Credentials

πŸ“Š API Endpoints

Authentication

  • POST /api/auth/login - User login
  • POST /api/auth/register - User registration
  • POST /api/auth/refresh - Refresh JWT token

Products

  • GET /api/products - Get all products
  • POST /api/products - Create product
  • PUT /api/products/:id - Update product
  • DELETE /api/products/:id - Delete product

Stock Management

  • GET /api/stock/levels - Get stock levels
  • GET /api/stock/movements - Get stock movements
  • POST /api/stock/movements - Create stock movement
  • POST /api/stock/transfer - Transfer stock between shops
  • GET /api/stock/low-stock - Get low stock items

Sales

  • GET /api/sales - Get all sales
  • POST /api/sales - Create sale
  • GET /api/sales/:id - Get sale by ID
  • POST /api/sales/:id/payments - Add payment to sale
  • GET /api/sales/unpaid/invoices - Get unpaid invoices

Reports

  • GET /api/reports/sales - Sales report
  • GET /api/reports/stock - Stock report
  • GET /api/reports/purchases - Purchases report
  • GET /api/reports/unpaid-invoices - Unpaid invoices report
  • GET /api/reports/dashboard - Dashboard KPIs

Backup

  • POST /api/backup/create - Create database backup
  • GET /api/backup/list - List available backups
  • GET /api/backup/download/:filename - Download backup
  • POST /api/backup/restore - Restore from backup
  • DELETE /api/backup/:filename - Delete backup

🎯 Key Features Explained

Stock Management

  • Real-time Tracking: Stock levels update automatically with sales and purchases
  • Multi-location Support: Manage inventory across multiple shops
  • Stock Transfers: Transfer products between locations
  • Low Stock Alerts: Automatic notifications for items running low
  • Stock Movements: Complete audit trail of all inventory changes

Sales & Payments

  • Flexible Payments: Support for cash, card, bank transfer, and check payments
  • Partial Payments: Handle partial payments for large orders
  • Invoice Management: Track paid and unpaid invoices
  • Customer Management: Complete customer database with contact information

Reporting & Analytics

  • Dashboard KPIs: Real-time metrics including sales, stock value, and unpaid invoices
  • Export Functionality: Export reports to Excel format
  • Filtering: Advanced filtering options for all reports
  • Date Range Selection: Custom date ranges for historical analysis

Backup & Security

  • Database Backups: Automated backup creation with download capability
  • Restore Functionality: Restore database from backup files
  • Role-based Access: Granular permissions for different user roles
  • Security Headers: Comprehensive security measures

πŸ› οΈ Development

Database Management

# Reset database
npm run db:reset

# Create new migration
npx prisma migrate dev --name migration_name

# Generate Prisma client
npx prisma generate

# Seed database
npm run db:seed

Backend Scripts

# Development mode
npm run dev

# Production mode
npm start

# Create backup
npm run backup

# Restore backup
npm run restore

Frontend Scripts

# Development mode
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

πŸ“ Project Structure

erpmfumo/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/          # API route handlers
β”‚   β”‚   β”œβ”€β”€ middleware/      # Authentication & validation
β”‚   β”‚   └── index.js        # Main server file
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”œβ”€β”€ schema.prisma   # Database schema
β”‚   β”‚   └── seed.js         # Database seeding
β”‚   β”œβ”€β”€ scripts/            # Backup/restore scripts
β”‚   └── package.json
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ pages/          # React page components
β”‚   β”‚   β”œβ”€β”€ components/     # Reusable components
β”‚   β”‚   β”œβ”€β”€ context/        # React context providers
β”‚   β”‚   └── utils/          # Utility functions
β”‚   └── package.json
└── README.md

πŸ”§ Configuration

Environment Variables

Backend (.env)

DATABASE_URL="mysql://username:password@localhost:3306/database_name"
JWT_SECRET="your_jwt_secret_key"
NODE_ENV="development"
PORT=3001

Frontend

The frontend automatically connects to the backend API at http://localhost:3001

πŸš€ Deployment

Backend Deployment

  1. Set production environment variables
  2. Run database migrations: npx prisma migrate deploy
  3. Start the server: npm start

Frontend Deployment

  1. Build the application: npm run build
  2. Deploy the dist folder to your web server
  3. Configure API endpoint for production

πŸ“ License

This project is licensed under the MIT License.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“ž Support

For support and questions, please open an issue in the repository.


Note: This is a comprehensive ERP system designed for warehouse and hardware store management. Make sure to configure proper security settings and database credentials before deploying to production.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published