Skip to content

xshopai/user-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

287 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ‘€ User Service

Enterprise-grade user management microservice for the xshopai e-commerce platform

Node.js Express MongoDB Dapr License

Getting Started β€’ Documentation β€’ API Reference β€’ Contributing


🎯 Overview

The User Service is a foundational microservice responsible for comprehensive user profile management, address and payment method storage, wishlist management, and role-based access control across the xshopai platform. Built with scalability and reliability in mind, it supports multi-cloud deployments and integrates seamlessly with the broader microservices ecosystem.


✨ Key Features

πŸ‘€ Profile Management

  • Complete user profile CRUD operations
  • Email verification workflows
  • Password management & security
  • User preferences & settings

πŸ“ Address & Payment

  • Multiple shipping/billing addresses
  • Payment method storage
  • Default address selection
  • Secure payment info handling

πŸ“‘ Event-Driven Architecture

  • CloudEvents 1.0 specification
  • Pub/sub messaging via Dapr
  • User lifecycle event publishing
  • Cross-service synchronization

πŸ›‘οΈ Enterprise Security

  • JWT token authentication
  • Role-based access control (RBAC)
  • Complete audit trail
  • Secure password hashing (bcrypt)

πŸš€ Getting Started

Prerequisites

  • Node.js 20+
  • MongoDB 8.0+
  • Docker & Docker Compose (optional)
  • Dapr CLI (for production-like setup)

Quick Start with Docker Compose

# Clone the repository
git clone https://github.com/xshopai/user-service.git
cd user-service

# Start all services (MongoDB, service, etc.)
docker-compose up -d

# Verify the service is healthy
curl http://localhost:8002/health

Local Development Setup

πŸ”§ Without Dapr (Simple Setup)
# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

# Start MongoDB (Docker)
docker run -d --name user-mongodb -p 27018:27017 mongo:8

# Start the service
npm run dev

πŸ“– See Local Development Guide for detailed instructions.

⚑ With Dapr (Production-like)
# Ensure Dapr is initialized
dapr init

# Start with Dapr sidecar
npm run dev:dapr

# Or use platform-specific scripts
./run.sh       # Linux/Mac
.\run.ps1      # Windows

πŸ“– See Dapr Development Guide for detailed instructions.


πŸ“š Documentation

Document Description
πŸ“˜ Local Development Step-by-step local setup without Dapr
⚑ Local Development with Dapr Local setup with full Dapr integration
☁️ Azure Container Apps Deploy to serverless containers with built-in Dapr
πŸ“‹ Product Requirements Complete API specification and business requirements
πŸ—οΈ Architecture System design, patterns, and data flows
πŸ” Security Security policies and vulnerability reporting

πŸ§ͺ Testing

We maintain high code quality standards with comprehensive test coverage.

# Run all tests
npm test

# Run unit tests only
npm run test:unit

# Run integration tests
npm run test:integration

# Run with coverage report
npm run test:coverage

# Run tests in watch mode
npm run test:watch

Test Coverage

Metric Status
Unit Tests βœ… Passing
Code Coverage βœ… Target 80%+
Security Scan βœ… 0 vulnerabilities

πŸ—οΈ Project Structure

user-service/
β”œβ”€β”€ πŸ“ src/                       # Application source code
β”‚   β”œβ”€β”€ πŸ“ controllers/           # REST API endpoints
β”‚   β”œβ”€β”€ πŸ“ services/              # Business logic layer
β”‚   β”œβ”€β”€ πŸ“ models/                # Mongoose models
β”‚   β”œβ”€β”€ πŸ“ schemas/               # Reusable subdocuments
β”‚   β”œβ”€β”€ πŸ“ events/                # Event publishing (Dapr)
β”‚   β”œβ”€β”€ πŸ“ middlewares/           # Authentication, logging, tracing
β”‚   β”œβ”€β”€ πŸ“ validators/            # Input validation
β”‚   β”œβ”€β”€ πŸ“ routes/                # Route definitions
β”‚   β”œβ”€β”€ πŸ“ core/                  # Config, logger, errors
β”‚   └── πŸ“ database/              # MongoDB connection setup
β”œβ”€β”€ πŸ“ tests/                     # Test suite
β”‚   β”œβ”€β”€ πŸ“ unit/                  # Unit tests
β”‚   β”œβ”€β”€ πŸ“ integration/           # Integration tests
β”‚   └── πŸ“ e2e/                   # End-to-end tests
β”œβ”€β”€ πŸ“ .dapr/                     # Dapr configuration
β”‚   β”œβ”€β”€ πŸ“ components/            # Pub/sub, secrets, state stores
β”‚   └── πŸ“„ config.yaml            # Dapr runtime configuration
β”œβ”€β”€ πŸ“ docs/                      # Documentation
β”œβ”€β”€ πŸ“„ docker-compose.yml         # Local containerized environment
β”œβ”€β”€ πŸ“„ Dockerfile                 # Production container image
└── πŸ“„ package.json               # Node.js dependencies

πŸ”§ Technology Stack

Category Technology
🟒 Runtime Node.js 20+
🌐 Framework Express 5.1+
πŸ—„οΈ Database MongoDB 8.0+ with Mongoose ODM
πŸ“¨ Messaging Dapr Pub/Sub (RabbitMQ backend)
πŸ“‹ Event Format CloudEvents 1.0 Specification
πŸ” Authentication JWT Tokens + bcrypt password hashing
πŸ§ͺ Testing Jest with coverage reporting
πŸ“Š Observability Winston structured logging

⚑ Quick Reference

# 🐳 Docker Compose
docker-compose up -d              # Start all services
docker-compose down               # Stop all services
docker-compose logs -f user       # View logs

# 🟒 Local Development
npm run dev                       # Run without Dapr
npm run dev:dapr                  # Run with Dapr sidecar
npm run debug:dapr                # Debug with Dapr

# πŸ§ͺ Testing
npm test                          # Run all tests
npm run test:unit                 # Run unit tests
npm run test:coverage             # Run with coverage

# πŸ” Health Check
curl http://localhost:8002/health
curl http://localhost:8002/health/ready

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Write tests for your changes
  4. Run the test suite
    npm test && npm run lint
  5. Commit your changes
    git commit -m 'feat: add amazing feature'
  6. Push to your branch
    git push origin feature/amazing-feature
  7. Open a Pull Request

Please ensure your PR:

  • βœ… Passes all existing tests
  • βœ… Includes tests for new functionality
  • βœ… Follows the existing code style
  • βœ… Updates documentation as needed

πŸ†˜ Support

Resource Link
πŸ› Bug Reports GitHub Issues
πŸ“– Documentation docs/
πŸ“‹ API Reference docs/PRD.md
πŸ’¬ Discussions GitHub Discussions

πŸ“„ License

This project is part of the xshopai e-commerce platform.
Licensed under the MIT License - see LICENSE for details.


⬆ Back to Top

Made with ❀️ by the xshopai team

About

Manages user accounts, profiles, and role-based access

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors