Enterprise-grade administrative operations microservice for the xshopai e-commerce platform
Getting Started β’ Documentation β’ API Reference β’ Contributing
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.
|
|
|
|
- Node.js 20+
- Docker & Docker Compose (optional)
- Dapr CLI (for production-like setup)
# 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π§ 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| 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.
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| Metric | Status |
|---|---|
| Unit Tests | β Passing |
| Code Coverage | β Target 80%+ |
| Security Scan | β 0 vulnerabilities |
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
| 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 |
# 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 IDSee .env.example for complete configuration options.
# π³ 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/healthPublisher-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
| Service | Relationship |
|---|---|
| user-service | User profile management |
| auth-service | Authentication and JWT issuance |
| audit-service | Audit logging |
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Write tests for your changes
- Run the test suite
npm test && npm run lint
- Commit your changes
git commit -m 'feat: add amazing feature' - Push to your branch
git push origin feature/amazing-feature
- 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
| Resource | Link |
|---|---|
| π Bug Reports | GitHub Issues |
| π Documentation | src/routes/ |
| π¬ Discussions | GitHub Discussions |
This project is part of the xshopai e-commerce platform.
Licensed under the MIT License - see LICENSE for details.
Made with β€οΈ by the xshopai team