@diagramers/api
A comprehensive Node.js API template with TypeScript, Firebase Functions, Socket.io, and extensive authentication and communication capabilities.
π Features
Core Framework
- TypeScript - Full TypeScript support with strict typing
- Express.js - Fast, unopinionated web framework
- MongoDB - NoSQL database with Mongoose ODM
- Firebase Functions - Serverless deployment support
- Socket.io - Real-time bidirectional communication
- Webpack - Module bundling and optimization
Authentication & Authorization
- Multi-Provider Authentication:
- Internal (Database-based) authentication
- Firebase Authentication
- OAuth providers (Google, GitHub, Facebook, Twitter, LinkedIn, Microsoft, Apple, Discord, Spotify, Twitch)
- SMS authentication (Twilio, AWS SNS, Vonage, MessageBird)
- Email authentication (Nodemailer, SendGrid, AWS SES, Mailgun, Postmark)
- LDAP authentication
- SAML authentication
- OAuth2 generic provider
- OpenID Connect
- WebAuthn (FIDO2) authentication
- Social media authentication (Instagram, TikTok, Snapchat, Pinterest, Reddit, Slack, Zoom, Dropbox, Bitbucket, GitLab)
Security Features
- JWT Tokens - JSON Web Token authentication
- Password Policies - Configurable password requirements
- Rate Limiting - Request throttling and protection
- CORS - Cross-Origin Resource Sharing configuration
- Security Headers - Helmet.js security middleware
- Session Management - Secure session handling
- Multi-factor Authentication - Enhanced security options
Communication Services
-
Email System:
- Multiple email providers (SMTP, SendGrid, AWS SES, Mailgun, Postmark)
- Template engine support (Handlebars)
- Email verification, password reset, login codes
- Custom email providers
-
SMS System:
- Multiple SMS providers (Twilio, AWS SNS, Vonage, MessageBird)
- SMS verification codes
- Custom SMS providers
-
Push Notifications:
- Firebase Cloud Messaging (FCM)
- Cross-platform push notifications
Database & Storage
- MongoDB Integration - Native MongoDB support with connection pooling
- Database Seeding - Automated data seeding and management
- File Storage:
- Local file storage
- AWS S3 integration
- Google Cloud Storage
- Cloudinary integration
Development & DevOps
- CLI Tools - Command-line interface for development
- Module Generation - Automated module scaffolding
- Endpoint Generation - Quick API endpoint creation
- Database Migration - Schema migration tools
- Backup & Restore - Database backup automation
- Health Checks - Application monitoring endpoints
- Logging - Comprehensive logging system (JSON, colored, file-based)
- External Logging - Sentry, Loggly, Papertrail integration
Performance & Monitoring
- Performance Monitoring - Application performance tracking
- New Relic Integration - APM monitoring
- Metrics Collection - Application metrics
- Compression - Response compression
- Caching - Redis integration for caching
Third-Party Integrations
-
Payment Processing:
- Stripe integration
- PayPal integration
-
Analytics:
- Google Analytics integration
Development Tools
- Hot Reload - Development server with auto-reload
- Type Checking - TypeScript type validation
- Linting - ESLint code quality checks
- Formatting - Prettier code formatting
- Documentation - Auto-generated API documentation
- Testing - Test database configuration
π¦ Installation
npm install @diagramers/api
π οΈ Quick Start
1. Initialize a New API Project
npx diagramers-cli api init my-api-project
cd my-api-project
2. Configure Environment Variables
cp .env.example .env
3. Install Dependencies
npm install --legacy-peer-deps
4. Start Development Server
npm run dev
π§ Configuration
Environment Variables
The API supports extensive configuration through environment variables:
Basic Configuration
NODE_ENV=development
PORT=3000
HOST=localhost
APP_URL=http://localhost:3000
Database Configuration
DATABASE_TYPE=mongodb
DATABASE_URL=mongodb://localhost:27017/diagramers
DATABASE_NAME=diagramers
Authentication Configuration
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=1h
AUTH_DEFAULT_PROVIDER=internal
Email Configuration
EMAIL_ENABLED=true
EMAIL_PROVIDER=nodemailer
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-password
SMS Configuration
SMS_ENABLED=false
SMS_PROVIDER=twilio
TWILIO_ACCOUNT_SID=your-twilio-account-sid
TWILIO_AUTH_TOKEN=your-twilio-auth-token
TWILIO_PHONE_NUMBER=+1234567890
π API Documentation
Authentication Endpoints
Internal Authentication
POST /api/auth/register
- User registration
POST /api/auth/login
- User login
POST /api/auth/logout
- User logout
POST /api/auth/refresh
- Refresh JWT token
POST /api/auth/forgot-password
- Password reset request
POST /api/auth/reset-password
- Password reset
OAuth Authentication
GET /api/auth/oauth/:provider
- OAuth provider authentication
GET /api/auth/oauth/:provider/callback
- OAuth callback
SMS Authentication
POST /api/auth/sms/send-code
- Send SMS verification code
POST /api/auth/sms/verify-code
- Verify SMS code
Email Authentication
POST /api/auth/email/send-code
- Send email verification code
POST /api/auth/email/verify-code
- Verify email code
User Management
GET /api/users
- Get all users
GET /api/users/:id
- Get user by ID
PUT /api/users/:id
- Update user
DELETE /api/users/:id
- Delete user
Email Management
GET /api/email/configs
- Get email configurations
POST /api/email/configs
- Create email configuration
PUT /api/email/configs/:id
- Update email configuration
DELETE /api/email/configs/:id
- Delete email configuration
POST /api/email/send
- Send email
Notifications
GET /api/notifications
- Get notifications
POST /api/notifications
- Create notification
PUT /api/notifications/:id
- Update notification
DELETE /api/notifications/:id
- Delete notification
π οΈ Development Commands
Basic Commands
npm run dev
npm run build
npm run start
npm run clean
Database Commands
npm run seed
npm run seed:force
npm run seed:reset
npm run seed:truncate
Generation Commands
npm run generate:module
npm run generate:endpoint
npm run generate:table
npm run generate:relation
Code Quality Commands
npm run lint
npm run lint:fix
npm run type-check
npm run format
npm run format:check
Documentation Commands
npm run docs
npm run docs:serve
Docker Commands
npm run docker:build
npm run docker:run
npm run docker:compose
npm run docker:compose:down
Maintenance Commands
npm run backup
npm run backup:restore
npm run migrate
npm run migrate:create
npm run migrate:rollback
Monitoring Commands
npm run health
npm run logs
npm run logs:clear
npm run monitor
π Plugin System
The API supports a plugin system for extending functionality:
Plugin Structure
src/plugins/
βββ base/
β βββ manager.ts
β βββ plugin.ts
βββ registry/
βββ auth.plugin.ts
Creating Custom Plugins
import { BasePlugin } from '../base/plugin';
export class CustomPlugin extends BasePlugin {
async initialize(): Promise<void> {
}
async execute(data: any): Promise<any> {
}
}
π§ͺ Testing
Test Configuration
TEST_DATABASE_URL=mongodb://localhost:27017/diagramers-api-test
TEST_JWT_SECRET=test-jwt-secret
Running Tests
npm test
npm run test:unit
npm run test:integration
npm run test:coverage
π Deployment
Firebase Functions Deployment
npm run deploy
npm run deploy:staging
npm run deploy:production
Docker Deployment
npm run docker:build
npm run docker:run
Environment-Specific Deployment
npm run deploy:staging
npm run deploy:production
π Monitoring & Logging
Logging Configuration
LOG_LEVEL=info
LOG_FORMAT=colored
LOG_FILE_ENABLED=true
LOG_FILE_PATH=logs/app.log
External Logging Services
- Sentry - Error tracking and monitoring
- Loggly - Log aggregation and analysis
- Papertrail - Log management and search
Health Checks
curl http://localhost:3000/health
π Security
- Helmet.js for security headers
- CORS configuration
- Rate limiting
- Input validation
Authentication Security
- JWT token management
- Password hashing with bcrypt
- Session management
- Multi-factor authentication
π€ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
π License
MIT License - see LICENSE file for details
π Related Packages
π Support
For support and questions:
- Create an issue on GitHub
- Check the documentation
- Review the examples in the codebase
πΊοΈ Roadmap