- Node.js (v16 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn
-
Navigate to backend directory:
cd backend -
Install dependencies:
npm install
-
Configure environment:
cp .env.example .env # Edit .env with your database credentials and secrets -
Create PostgreSQL database:
CREATE DATABASE client_management;
-
Run migrations:
npm run migrate
-
Seed database (optional):
npm run seed
Default users created:
- Admin: [email protected] / admin123
- User 1: [email protected] / user123 (Full access to products & orders)
- User 2: [email protected] / user123 (Read-mostly, can create orders)
-
Start development server:
npm run dev
Server runs on http://localhost:5000
-
Navigate to frontend directory:
cd frontend -
Install dependencies:
npm install
-
Configure environment (optional):
# Create .env file if you need custom API URL REACT_APP_API_URL=http://localhost:5000/api/v1 -
Start development server:
npm start
Application runs on http://localhost:3000
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/
├── 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
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- LoginPOST /api/v1/auth/logout- LogoutPOST /api/v1/auth/refresh-token- Refresh access tokenGET /api/v1/auth/profile- Get current user profilePUT /api/v1/auth/profile- Update profilePUT /api/v1/auth/change-password- Change password
GET /api/v1/users- Get all usersGET /api/v1/users/:id- Get user by IDPOST /api/v1/users- Create userPUT /api/v1/users/:id- Update userDELETE /api/v1/users/:id- Delete userGET /api/v1/users/:id/permissions- Get user permissionsPUT /api/v1/users/:id/permissions- Update user permissions
GET /api/v1/clients- Get all clientsGET /api/v1/clients/:id- Get client by IDPOST /api/v1/clients- Create clientPUT /api/v1/clients/:id- Update clientDELETE /api/v1/clients/:id- Delete client
GET /api/v1/products- Get all productsGET /api/v1/products/:id- Get product by IDPOST /api/v1/products- Create productPUT /api/v1/products/:id- Update productDELETE /api/v1/products/:id- Delete product
GET /api/v1/orders- Get all ordersGET /api/v1/orders/:id- Get order by IDPOST /api/v1/orders- Create orderPUT /api/v1/orders/:id- Update orderDELETE /api/v1/orders/:id- Delete order
GET /api/v1/comments- Get all commentsGET /api/v1/comments/:id- Get comment by IDPOST /api/v1/comments- Create commentPUT /api/v1/comments/:id- Update commentDELETE /api/v1/comments/:id- Delete comment
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
The application implements a sophisticated permission system:
- Admin Role: Has full access to all resources automatically
- User Role: Has customizable permissions per resource
- Login as admin ([email protected] / admin123)
- Create a new user with limited permissions
- Logout and login as the new user
- Verify you can only access permitted resources
- Login as a user with order creation permissions
- Navigate to Orders > Create Order
- Select a client
- Add products to the order
- Add one or multiple payment methods
- Submit the order
- Verify stock is decremented
Create an order with total $100:
- Payment 1: Cash - $60
- Payment 2: Credit Card - $40
- System validates total equals order amount
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
REACT_APP_API_URL=http://localhost:5000/api/v1