https://github.com/fitri-hy/restfull-api-starter-nodejs
Starter Kit for building modern RESTful APIs with scalable ๐๏ธ, modular ๐งฉ, and secure ๐ architecture. Suitable for use as an initial foundation for developing small to large scale backend applications, equipped with various built-in features that are ready to use ๐งฐ and easy to develop further ๐ง.
https://github.com/fitri-hy/restfull-api-starter-nodejs
api backend express jwt mysql nodejs postgresql redis rest-api restful-api scalable-architecture sequelize starter-kit
Last synced: 2 months ago
JSON representation
Starter Kit for building modern RESTful APIs with scalable ๐๏ธ, modular ๐งฉ, and secure ๐ architecture. Suitable for use as an initial foundation for developing small to large scale backend applications, equipped with various built-in features that are ready to use ๐งฐ and easy to develop further ๐ง.
- Host: GitHub
- URL: https://github.com/fitri-hy/restfull-api-starter-nodejs
- Owner: fitri-hy
- License: mit
- Created: 2025-04-16T05:11:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-21T02:11:05.000Z (about 1 year ago)
- Last Synced: 2025-04-22T22:07:33.036Z (about 1 year ago)
- Topics: api, backend, express, jwt, mysql, nodejs, postgresql, redis, rest-api, restful-api, scalable-architecture, sequelize, starter-kit
- Language: JavaScript
- Homepage:
- Size: 112 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ RESTful-API Starter Kit
Starter Kit for building modern RESTful APIs with scalable ๐๏ธ, modular ๐งฉ, and secure ๐ architecture. Suitable for use as an initial foundation for developing small to large scale backend applications, equipped with various built-in features that are ready to use ๐งฐ and easy to develop further ๐ง.
---
## ๐ Built-in Features
- โ
Authentication
- ๐งผ Input Validation & Sanitation
- ๐ Password Hashing
- ๐ JWT Token Auth
- ๐ Database Switching (MySQL / PostgreSQL)
- ๐งฉ Modular
- ๐ฆ ORM Sequelize
- ๐งฏ Handling errors
- ๐๏ธ Scalable Project Structure
- ๐ก๏ธ Rate Limiting
- ๐ Security Headers
- โก Redis Caching
- โค๏ธ Health Check & Monitoring
- ๐ Asynchronous Task Handling (Bull Queue)
- ๐ฅ Upload File Handlers
- ๐ Graceful Shutdown
- ๐๏ธ Request Profiling
- ๐ HTTP Compression
- ๐จ Anomaly Detection
- ๐ Webhook
---
## Quick Start
```
git clone https://github.com/fitri-hy/restfull-api-starter-nodejs.git
cd restfull-api-starter-nodejs
cp .env.example .env
npm install
npm run dev
```
---
## ๐งพ Configuration `.env` Variables
| Variable | Function |
|----------------------|-------------------------------------------------------------------------|
| HOST | Server host address |
| PORT | Port number the application listens on |
| NODE_ENV | Application mode (`development` / `production`) |
| API_KEY_ENABLE | Enable API key protection |
| API_KEY | API key value for authentication |
| CORS_ORIGIN | Allowed origin domain for API access (CORS) |
| DB | Database type (`mysql` / `postgres`) |
| DB_HOST | Database host address |
| DB_USER | Database username |
| DB_PASS | Database password |
| DB_NAME | Database name |
| DB_PORT | Database port number |
| WEBHOOK_ENABLE | Enable webhook notifications |
| WEBHOOK_URL | Webhook target URL |
| JWT_SECRET | Secret key to generate JWT tokens |
| JWT_EXPIRATION | JWT token expiration time (e.g., `1h`, `30m`) |
| RATE_LIMIT_MAX | Maximum number of requests before rate limiting |
| RATE_LIMIT_WINDOW_MS | Rate limit window in milliseconds |
| REDIS_CACHE_ENABLE | Enable Redis caching |
| REDIS_TASK_ENABLE | Enable Redis task queue |
| REDIS_HOST | Redis host address |
| REDIS_PORT | Redis port number |
| REDIS_TTL | Time-to-live (TTL) for Redis cache (in seconds) |
| FILE_MAX_SIZE | Maximum file upload size (in bytes) |
| FILE_UPLOAD_PATH | Directory path for file uploads |
| FILE_ALLOWED_TYPES | Allowed file types for upload |
| COMPRESSION_ENABLE | Enable response compression |
| COMPRESSION_THRESHOLD| Minimum response size to be compressed |
| COMPRESSION_LEVEL | Compression level (0-9) |
| ANOMALY_ENABLED | Enable anomaly detection for requests |
| ANOMALY_TIME | Time interval for detecting anomalies (in milliseconds) |
| ANOMALY_REQUEST | Number of suspicious requests before being flagged as an anomaly |
| ANOMALY_URL_LENGTH | Maximum URL length for anomaly detection |
---
## ๐ Status Monitoring
#### Endpoint
```
GET http://localhost:5000/status
```
---
## ๐ Task Handling
#### Endpoint
```
POST http://localhost:5000/api/v1/tasks/add
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
---
## ๐ง Redis Caching
#### Endpoint
```
GET http://localhost:5000/api/v1/data/:key
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
---
## ๐ค Example Case (Login, Register, Get All User, User Detail, Edit User Detail)
> *For testing purposes, you can import the `sample.sql` sample file available in the `/src/config/sample.sql` directory.*
#### ๐ฌ Postman Collection
Download & Import:
[RESTful-API_Starter_Kit.postman_collection.json](./src/config/RESTful-API_Starter_Kit.postman_collection.json)
### Register
#### Endpoint
```
POST http://localhost:5000/api/v1/auth/register
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
#### Body Request
```
{
"name": "John Doe",
"email": "johndoe@example.com",
"password": "securepassword"
}
```
#### Response
```
{
"message": "Registration successful",
"user": {
"name": "John Doe",
"email": "johndoe@example.com",
"password": "securepassword"
}
}
```
### Login
#### Endpoint
```
POST http://localhost:5000/api/v1/auth/login
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
#### Body Request
```
{
"email": "johndoe@example.com",
"password": "securepassword"
}
```
#### Response
```
{
"message": "Login successful",
"token": "your_jwt_token_here"
}
```
### All Users
#### Endpoint
```
GET http://localhost:5000/api/v1/auth/users
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
#### Header Authorization:
| Key | Value |
|:----------------|:--------------------------------|
| Authorization | Bearer `` |
#### Response
```
[
{
"id": 1,
"name": "John Doe",
"email": "johndoe@example.com"
}
...
]
```
### Users Detail
#### Endpoint
```
GET http://localhost:5000/api/v1/auth/profile
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
#### Header Authorization:
| Key | Value |
|:----------------|:--------------------------------|
| Authorization | Bearer `` |
#### Response
```
{
"id": 1,
"name": "John Doe",
"email": "johndoe@example.com",
"createdAt": "2025-04-21T00:42:41.000Z"
}
```
### Users Edit
#### Endpoint
```
PUT http://localhost:5000/api/v1/auth/profile
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
#### Header Authorization:
| Key | Value |
|:----------------|:--------------------------------|
| Authorization | Bearer `` |
#### Body Request
```
{
"name": "John New",
"email": "Johnnew@example.com",
"password": "123456"
}
```
#### Response
```
{
"message": "Profile updated successfully",
"user": {
"id": 1,
"name": "John New",
"email": "Johnnew@example.com",
"createdAt": "2025-04-21T01:13:14.000Z",
"updatedAt": "2025-04-21T01:13:45.000Z"
}
}
```
---
## File Upload
#### Endpoint
```
POST http://localhost:5000/api/v1/upload/:folderName
Default Location: public/uploads
```
#### Header Request (If using ApiKey)
| Key | Value |
|:----------------|:--------------------------------|
| x-api-key | my_secret_api_key |
#### Body Request (form-data)
| Key | Type | Value |
|:--------------|:----------|:-------------------------|
| file | file | Select File |
#### Response
```
{
"message": "File uploaded successfully",
"file": {
"fieldname": "file",
"originalname": "your-image.jpeg",
"encoding": "7bit",
"mimetype": "image/jpeg",
"destination": "public/uploads/",
"filename": "1744786296980-815431101.jpeg",
"path": "public\\uploads\\1744786296980-815431101.jpeg",
"size": 582884
}
}
```
---
## ๐๏ธ Folder Structure
```
rest-api-starter/
โโโ src/
โ โโโ config/
โ โโโ controllers/
โ โโโ middleware/
โ โโโ models/
โ โโโ routes/
โ โโโ service/
โ โโโ utils/
โโโ .env
โโโ .gitignore
โโโ package.json
โโโ app.js
```