Skip to content

Provides back-office tools for managing users, products, analytics, and system configuration

License

Notifications You must be signed in to change notification settings

xshopai/admin-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

116 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ‘₯ Admin Service

Enterprise-grade administrative operations microservice for the xshopai e-commerce platform

Node.js Express MongoDB Dapr License

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


🎯 Overview

The Admin Service is a privileged microservice responsible for administrative operations including user management, role administration, and system-wide administrative functions across the xshopai platform. Built with a publisher-only pattern following Amazon's admin portal architecture, it provides REST APIs for admin actions and publishes events for audit trails.


✨ Key Features

πŸ‘€ User Administration

  • Complete user management (list, view, update, delete)
  • Role and permission administration
  • User status management (activate/deactivate)
  • Admin-initiated password changes

πŸ” Security & Authorization

  • JWT token authentication
  • Role-based access control (RBAC)
  • Comprehensive authorization checks
  • Admin privilege verification

πŸ“‘ Event-Driven Architecture

  • CloudEvents 1.0 specification
  • Pub/sub messaging via Dapr
  • Audit trail event publishing
  • admin.user.updated, admin.user.deleted events

πŸ›‘οΈ Enterprise Compliance

  • Bulk user operations
  • Complete audit logging
  • Structured logging for compliance
  • Service-to-service authentication

πŸš€ Getting Started

Prerequisites

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

Quick Start with Docker Compose

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

# Start all services
docker-compose up -d

# Verify the service is healthy
curl http://localhost:1003/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 the service
node src/server.js
⚑ With Dapr (Production-like)
# Ensure Dapr is initialized
dapr init

# Start with Dapr sidecar
npm run dev

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

πŸ“š Documentation

Document Description
πŸ“˜ Environment Setup Environment variables and configuration
πŸ” Security Security policies and vulnerability reporting

API Documentation: See src/routes/ for endpoint definitions and tests/ for API contract examples.


πŸ§ͺ 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 e2e tests
npm run test:e2e

Test Coverage

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

πŸ—οΈ Project Structure

admin-service/
β”œβ”€β”€ πŸ“ src/                       # Application source code
β”‚   β”œβ”€β”€ πŸ“ controllers/           # REST API endpoints
β”‚   β”œβ”€β”€ πŸ“ clients/               # External service clients
β”‚   β”œβ”€β”€ πŸ“ middlewares/           # Authentication, logging, tracing
β”‚   β”œβ”€β”€ πŸ“ validators/            # Input validation
β”‚   β”œβ”€β”€ πŸ“ routes/                # Route definitions
β”‚   β”œβ”€β”€ πŸ“ core/                  # Config, logger, errors
β”‚   β”œβ”€β”€ πŸ“ utils/                 # Helper functions & utilities
β”‚   β”œβ”€β”€ πŸ“„ app.js                 # Express app configuration
β”‚   └── πŸ“„ server.js              # Entry point
β”œβ”€β”€ πŸ“ tests/                     # Test suite
β”‚   β”œβ”€β”€ πŸ“ e2e/                   # End-to-end tests
β”‚   └── πŸ“ shared/                # Shared test utilities
β”œβ”€β”€ πŸ“ .dapr/                     # Dapr configuration
β”‚   β”œβ”€β”€ πŸ“ components/            # Pub/sub, secrets, state stores
β”‚   └── πŸ“„ config.yaml            # Dapr runtime configuration
β”œβ”€β”€ πŸ“„ 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
πŸ§ͺ Testing Jest with coverage reporting
πŸ“Š Observability Winston structured logging

βš™οΈ Configuration

Required Environment Variables

# Service
NODE_ENV=development              # Environment: development, production, test
PORT=1003                         # HTTP server port

# External Services
USER_SERVICE_URL=http://localhost:8002/api/users

# Security
JWT_SECRET=your-secret-key        # JWT signing secret (32+ characters)
USER_SERVICE_SECRET=shared-secret # Shared secret for service-to-service auth

# Dapr
DAPR_HTTP_PORT=3500
DAPR_GRPC_PORT=50001             # Dapr sidecar gRPC port
DAPR_APP_ID=admin-service        # Dapr application ID

See .env.example for complete configuration options.


⚑ Quick Reference

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

# 🟒 Local Development
npm run dev                       # Run with Dapr (recommended)
npm run debug                     # Debug with Dapr

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

# πŸ” Health Check
curl http://localhost:1003/health
curl http://localhost:3500/v1.0/invoke/admin-service/method/health

πŸ›οΈ Architecture

Publisher-Only Pattern: Following Amazon's admin portal pattern, this service:

  • Provides REST API endpoints for admin actions
  • Publishes events for audit/notification (admin.user.updated, admin.user.deleted)
  • Does NOT consume events - it's an action center, not an event responder
  • Forwards admin JWT to user-service for all privileged operations

Related Services

Service Relationship
user-service User profile management
auth-service Authentication and JWT issuance
audit-service Audit logging

🀝 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 src/routes/
πŸ’¬ 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

Provides back-office tools for managing users, products, analytics, and system configuration

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published