A powerful Node.js/TypeScript API that enables users to manage and cross-post content across multiple social media platforms (LinkedIn, X/Twitter) with a unified interface.
- Multi-Platform Support: Post content simultaneously to LinkedIn and X/Twitter
- OAuth Integration: Seamless authentication with Google and social media platforms
- Queue-Based Processing: BullMQ-powered background job processing for reliable post distribution
- Media Upload: Built-in image upload support via Cloudinary
- Real-Time Updates: Socket.IO integration for real-time notifications
- JWT Authentication: Secure session management with refresh tokens
- User Account Management: Connect and manage multiple social media accounts
- Post Management: Track post status across different platforms
- Framework: Express.js 5.x
- Language: TypeScript
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT, Google OAuth, OAuth 1.0a
- Cache & Queue: Redis, BullMQ
- Media: Cloudinary
- Validation: Zod
- Logging: Winston
src/
βββ config/ # Configuration files
β βββ googleOAuth.config.ts
β βββ logger.config.ts
β βββ multerr.config.ts
β βββ prisma.ts
β βββ redis.config.ts
βββ middlewares/ # Express middlewares
β βββ auth.middleware.ts
β βββ error.middleware.ts
βββ modules/ # Feature modules
β βββ auth/ # Authentication
β βββ post/ # Post management
β βββ linkedin/ # LinkedIn integration
β βββ x/ # X/Twitter integration
β βββ shared/ # Shared services
βββ workers/ # Background job workers
β βββ linkedin/
β βββ x/
βββ utils/ # Utility functions
βββ queues/ # Queue configuration
βββ lib/ # Library code
- Docker
- PostgreSQL
- Redis
- Cloudinary account
- Google OAuth credentials
- LinkedIn & X/Twitter OAuth credentials
- Clone the repository
git clone https://github.com/Mayur-00/OncePost-Api.git
cd OncePost-Api- Set up environment variables
Create a .env file in the root directory:
DATABASE_URL=postgresql:your_DB_pooler_url
DIRECT_DATABASE_URL=direct_DB_url
JWT_SECRET=your_jwt_secret
JWT_REFRESH_SECRET=your_refresh_secret
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
CLOUDINARY_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
LINKEDIN_CLIENT_ID=your_linkedin_client_id
LINKEDIN_CLIENT_SECRET=your_linkedin_client_secret
X_API_KEY=your_x_api_key
X_API_SECRET=your_x_api_secret
X_ACCESS_TOKEN=your_x_access_token
X_ACCESS_TOKEN_SECRET=your_x_access_token_secret
REDIS_HOST=your_redis_host_uri
REDIS_PORT=redis_server_port
REDIS_PASSWORD=redis_password
REDIS_URL=redis_DB_uri
PORT=5000
NODE_ENV:develement
DOMAIN:domain_name
CORS_ORIGIN:your_frontend_client_link
FRONTEND_URI:your_frontend_client_link
RAZORPAY_KEY_ID=your_razorpay_key
RAZORPAY_KEY_SECRET=your_razorpay_secret
- Build and Start Container
docker compose up -D The API will be available at http://localhost:5000
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production servernpm run worker:dev-post- Start dev posting background workernpm run worker:post- Start posting background workernpm run migration:dev- Run dev prisma migrationnpm run migrate- Run prisma migrationnpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issues
POST /google- Login with Google OAuthPOST /register- Register a new userPOST /login- Login with email and passwordPOST /refresh-access- Refresh JWT tokenGET /user- Get current user profile (requires auth)GET /logout- Logout user (requires auth)GET /delete- Request account deletion (requires auth)
POST /publish-post- Queue post for publishing to multiple platformsPOST /schedule- schedule post for publishing later on multiple platformsGET /all- Get all posts including all platfrom postsGET /Query- Get all posts with user's searched query
GET /auth- Initiate LinkedIn OAuth flow (requires auth)GET /callback- LinkedIn OAuth callback
GET /callback- X/Twitter OAuth callbackPOST /auth- Initiate X/Twitter OAuth flow (requires auth)
- Stores user information with support for Google OAuth and credential-based auth
- Maintains relationships with social accounts, posts, and sessions
- Represents connected social media accounts (LinkedIn, X, Facebook)
- Stores OAuth tokens and platform-specific data
- Represents a post created by a user
- Tracks post status (CREATED, UPLOADED, PENDING, DRAFT, FAILED)
- Contains post content and media
- Represents the status of a post on a specific platform
- Links posts to their platform-specific implementations
- Tracks platform post ID and URL
- Manages OAuth state for authentication flows
- Implements PKCE for enhanced security
- Represents Subscription plans
- Represents User subscription
- Represents all transactions made by user
- Mostly Represnts Subscripiton transactions
CREATED- Post created but not yet uploadedUPLOADED- Post content uploadedPENDING- Awaiting platform postingDRAFT- Saved as draftFAILED- Posting failed
PENDING- Awaiting posting to platformPOSTED- Successfully postedFAILED- Posting failed
GOOGLE- Google OAuth authenticationCREDENTIAL- Email/password authentication
LINKEDIN- LinkedIn platformX- X/Twitter platform
The API uses BullMQ for asynchronous post processing:
- Posts are queued for each platform
- Background workers process posts independently
- Failed posts can be retried automatically
- Images uploaded via Multer
- Stored in Cloudinary
- Automatic URL generation for media access
- Centralized error middleware
- Custom ApiError and ApiResponse utilities
- Proper HTTP status codes
- JWT-based authentication
- OAuth 1.0a for X/Twitter
- OAuth 2.0 for Google and LinkedIn
- PKCE implementation for OAuth flows
- Password hashing with bcrypt
- CORS configuration
The API includes separate worker processes for handling background tasks:
Processes Queued Posts in development
npm run worker:dev-postProcesses posts queued in Production
npm run worker:postThe API uses a centralized error handling middleware that catches and formats all errors with consistent response structures:
{
"statusCode": 400,
"data": null,
"message": "Error message",
"success": false
}Winston logger is configured for:
- Application logging
- Error tracking
- Request/response logging
- File and console output
- ESLint configuration for code standards
- TypeScript strict mode enabled
Test files are located in src/__test__/ directory
- Create a feature branch
- Make your changes
- Run linting:
npm run lint:fix - Test your changes
- Submit a pull request
ISC
For issues and questions, please open an issue in the repository.