https://github.com/pedramcode/usersvc
user service
https://github.com/pedramcode/usersvc
Last synced: 2 months ago
JSON representation
user service
- Host: GitHub
- URL: https://github.com/pedramcode/usersvc
- Owner: pedramcode
- Created: 2025-07-27T23:27:07.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-07-27T23:59:45.000Z (8 months ago)
- Last Synced: 2025-07-28T01:14:22.133Z (8 months ago)
- Language: TypeScript
- Size: 46.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# User Service
A RESTful API microservice for user management, authentication, and permissions. Built with Node.js, Express, and MongoDB.
## Features
- User registration with OTP email verification
- Secure login and JWT-based authentication (access & refresh tokens)
- Permission management for admin/superuser
- Rate limiting and error handling
- Modular code structure for easy extension
## Technologies
- Node.js
- Express
- MongoDB (Mongoose)
- JWT (jsonwebtoken)
- Winston (logging)
- Zod (validation)
## Getting Started
### Prerequisites
- Node.js >= 18
- MongoDB instance
- npm
### Installation
1. Clone the repository:
```sh
git clone https://github.com/yourusername/usersvc.git
cd usersvc
```
2. Install dependencies:
```sh
npm install
```
3. Configure environment variables (see below).
### Environment Variables
Set the following variables in a `.env` file or your environment:
- `HTTP_PORT` - Port for HTTP server (default: 3000)
- `HTTP_HOST` - Host for HTTP server (default: localhost)
- `LOG_PATH` - Path for log files (default: /var/log)
- `MONGO_URL` - MongoDB connection string
- `RUNTIME` - "dev" or "prod"
- `SECRET` - Secret key for JWT signing
- `REDIS_URL` - Redis server URL for caching
Example `.env`:
```
HTTP_PORT=3000
HTTP_HOST=localhost
LOG_PATH=/var/log
MONGO_URL=mongodb://localhost:27017/usersvc
RUNTIME=dev
SECRET=your_jwt_secret
```
### Running the Service
```sh
npm run start:dev
```
or
```sh
npm run start:prod
```
The server will run at `http://HTTP_HOST:HTTP_PORT`.
### Health Check
- `GET /ping`
Returns "PONG"
## Error Handling
Standard HTTP status codes and error messages are returned for all endpoints.
Custom errors:
- 400 Bad Request
- 401 Unauthorized
- 404 Not Found
- 409 Conflict
- 500 Internal Server Error
## Project Structure
```
src/
application/services/ # Business logic
infrastructure/ # Config, logger, database
interfaces/http/ # Controllers, DTOs, routes, middlewares
shared/ # Common utilities and error classes
```
## Development
- Logging is verbose in `dev` mode.
- Rate limiting is enabled (50 requests/minute).
- OTP codes expire after 2 minutes.
## License
MIT
## Maintainer
For issues or questions, open an issue or contact [dev.dehghanpour@gmail.com](mailto:dev.dehghanpour@gmail.com).