A scalable API service that handles social media analytics processing with tier-based rate limiting and sentiment analysis.
- Rate Limiting: Tier-based rate limiting (Free, Standard, Premium)
- Analytics Processing:
- Hashtag extraction
- Sentiment analysis
- Platform-specific metrics
- Time-Based Analytics: Filter data by date ranges
- Redis Backend: Fast data storage and retrieval
- RESTful API: Clean and well-documented endpoints
- Node.js (v14 or higher)
- Redis (v6 or higher)
- npm or yarn
- Clone the repository:
git clone https://github.com/yourusername/rate-limiter-api.git
cd rate-limiter-api- Install dependencies:
npm install- Set up environment variables:
cp .env.example .envEdit .env with your configuration:
PORT=3000
REDIS_URL=redis://localhost:6379
NODE_ENV=development- Start Redis:
brew services start redis # macOS
# or
sudo service redis start # Linux- Start the server:
npm startGET /health
POST /api/v1/analytics/submit
Headers:
- X-User-ID: <user_id>
- X-User-Tier: <free|standard|premium>
GET /api/v1/analytics/dashboard?user_id=<user_id>&start_date=<date>&end_date=<date>&platform=<platform>
| Tier | Requests/Minute | Requests/Hour |
|---|---|---|
| Free | 10 | 100 |
| Standard | 50 | 500 |
| Premium | 200 | 2000 |
- Run automated tests:
npm test- Manual testing script:
chmod +x test.sh
./test.shSee API Testing Documentation for detailed testing instructions.
.
├── src/
│ ├── app.js # Main application file
│ ├── config/ # Configuration files
│ ├── middleware/ # Custom middleware
│ ├── routes/ # Route handlers
│ ├── services/ # Business logic
│ └── utils/ # Utility functions
├── test/ # Test files
├── .env # Environment variables
├── .gitignore
├── package.json
└── README.md
The API uses standard HTTP status codes:
- 200: Success
- 400: Bad Request
- 429: Too Many Requests
- 500: Internal Server Error
Example error response:
{
"status": "error",
"message": "Rate limit exceeded",
"retry_after": 30
}- Create a new branch:
git checkout -b feature/your-feature-name- Make your changes and commit:
git commit -m "Add: your feature description"- Push and create a pull request:
git push origin feature/your-feature-name- Use ESLint for code linting
- Follow JavaScript Standard Style
- Add JSDoc comments for functions
- Build the image:
docker build -t rate-limiter-api .- Run the container:
docker run -p 3000:3000 rate-limiter-api- Set NODE_ENV to 'production'
- Use a production Redis instance
- Configure appropriate logging levels
- Set up monitoring and alerts
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, email your-email@example.com or create an issue in the GitHub repository.
- Redis for the amazing in-memory data store
- Node.js community for excellent packages
- Contributors who helped improve the project # Rate_Limiter_for_API_Service