Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ajmal-junaid/client-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Client Management System

Prerequisites

  • Node.js (v16 or higher)
  • PostgreSQL (v12 or higher)
  • npm or yarn

Backend Setup

  1. Navigate to backend directory:

    cd backend
  2. Install dependencies:

    npm install
  3. Configure environment:

    cp .env.example .env
    # Edit .env with your database credentials and secrets
  4. Create PostgreSQL database:

    CREATE DATABASE client_management;
  5. Run migrations:

    npm run migrate
  6. Seed database (optional):

    npm run seed

    Default users created:

  7. Start development server:

    npm run dev

    Server runs on http://localhost:5000

Frontend Setup

  1. Navigate to frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Configure environment (optional):

    # Create .env file if you need custom API URL
    REACT_APP_API_URL=http://localhost:5000/api/v1
  4. Start development server:

    npm start

    Application runs on http://localhost:3000

📁 Project Structure

Backend Structure

backend/
├── src/
│   ├── config/          # Database and app configuration
│   ├── controllers/     # Request handlers
│   ├── middleware/      # Auth, permissions, error handling
│   ├── models/          # Sequelize models
│   ├── routes/          # API routes
│   ├── utils/           # Utility functions
│   ├── validators/      # Input validation schemas
│   └── server.js        # Express app entry point
├── .env.example
└── package.json

Frontend Structure

frontend/
├── src/
│   ├── api/            # API client and services
│   ├── components/     # Reusable components
│   ├── hooks/          # Custom React hooks
│   ├── layouts/        # Layout components
│   ├── pages/          # Page components
│   ├── store/          # Redux store and slices
│   ├── utils/          # Utility functions
│   ├── App.jsx         # Main app component
│   └── index.jsx       # Entry point
├── public/
└── package.json

🔐 API Endpoints

Authentication

  • POST /api/v1/auth/register - Register new user
  • POST /api/v1/auth/login - Login
  • POST /api/v1/auth/logout - Logout
  • POST /api/v1/auth/refresh-token - Refresh access token
  • GET /api/v1/auth/profile - Get current user profile
  • PUT /api/v1/auth/profile - Update profile
  • PUT /api/v1/auth/change-password - Change password

Users (Admin Only)

  • GET /api/v1/users - Get all users
  • GET /api/v1/users/:id - Get user by ID
  • POST /api/v1/users - Create user
  • PUT /api/v1/users/:id - Update user
  • DELETE /api/v1/users/:id - Delete user
  • GET /api/v1/users/:id/permissions - Get user permissions
  • PUT /api/v1/users/:id/permissions - Update user permissions

Clients

  • GET /api/v1/clients - Get all clients
  • GET /api/v1/clients/:id - Get client by ID
  • POST /api/v1/clients - Create client
  • PUT /api/v1/clients/:id - Update client
  • DELETE /api/v1/clients/:id - Delete client

Products

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

Orders

  • GET /api/v1/orders - Get all orders
  • GET /api/v1/orders/:id - Get order by ID
  • POST /api/v1/orders - Create order
  • PUT /api/v1/orders/:id - Update order
  • DELETE /api/v1/orders/:id - Delete order

Comments

  • GET /api/v1/comments - Get all comments
  • GET /api/v1/comments/:id - Get comment by ID
  • POST /api/v1/comments - Create comment
  • PUT /api/v1/comments/:id - Update comment
  • DELETE /api/v1/comments/:id - Delete comment

🗄️ Database Schema

Key Tables

users

  • id, email, password, firstName, lastName, role, isActive, lastLogin, refreshToken

permissions

  • id, userId, resource, canCreate, canRead, canUpdate, canDelete
  • Unique constraint on (userId, resource)

clients

  • id, firstName, lastName, email, phone, address, city, country, postalCode, notes, isActive

products

  • id, name, description, sku, price, stockQuantity, category, isActive

orders

  • id, orderNumber, clientId, totalAmount, status, notes, createdBy

order_items

  • id, orderId, productId, quantity, unitPrice, subtotal

payments

  • id, orderId, paymentMethod, amount, status, transactionId, paymentDate, notes

comments

  • id, userId, content, entityType, entityId, isEdited

🔒 Permission System

The application implements a sophisticated permission system:

  1. Admin Role: Has full access to all resources automatically
  2. User Role: Has customizable permissions per resource

Test Permission System

  1. Login as admin ([email protected] / admin123)
  2. Create a new user with limited permissions
  3. Logout and login as the new user
  4. Verify you can only access permitted resources

Test Order Creation

  1. Login as a user with order creation permissions
  2. Navigate to Orders > Create Order
  3. Select a client
  4. Add products to the order
  5. Add one or multiple payment methods
  6. Submit the order
  7. Verify stock is decremented

Test Multi-Payment

Create an order with total $100:

  • Payment 1: Cash - $60
  • Payment 2: Credit Card - $40
  • System validates total equals order amount

📝 Environment Variables

Backend (.env)

NODE_ENV=development
PORT=5000
API_VERSION=v1

DB_HOST=localhost
DB_PORT=5432
DB_NAME=client_management
DB_USER=postgres
DB_PASSWORD=your_password

JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=7d
JWT_REFRESH_SECRET=your_refresh_secret
JWT_REFRESH_EXPIRES_IN=30d

CORS_ORIGIN=http://localhost:3000

Frontend (.env)

REACT_APP_API_URL=http://localhost:5000/api/v1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages