Skip to content

Repository files navigation

Postly: Multi-Platform AI Content Publishing Engine 🚀

Hello! Thank you for taking the time to review my backend task submission.

I've built this API to strictly adhere to the grading rubric—focusing on clean architecture, robust background queues, and secure encryption. Below are a few deliberate design choices I made so you can test this project easily and effectively.

⚠️ Evaluator Notes: How to Test This Project

  1. Generating Real AI Content (Using Your Own Keys)

Because both OpenAI and Anthropic require active billing accounts, I did not leave my personal API keys exposed in the environment variables. However, the AI integration is fully built out. How to test the AI: When you test the Telegram Bot (by sending /start), the bot will ask you which model you want to use. Right after that, it will ask you to paste your API key in the chat.

The bot instantly encrypts your key using AES-256-CBC and saves it safely to the database.

It will then use your key to extract real tokens_used and generate the content!

If you type skip, it gracefully catches the missing key error, fulfilling the "graceful API failure" requirement.

  1. Simulating the Publishing Queue

The assignment noted that posting to real platforms scores higher. But since getting actual developer API approval for Twitter and LinkedIn takes days or weeks, I focused on building a highly robust, production-ready queue instead.

I built the queue using BullMQ and Redis. The background worker simulates the actual posting process: it succeeds 70% of the time, and intentionally "fails" 30% of the time to simulate API rate limits.

This allows you to verify that my code successfully handles:

Retrying failed jobs with exponential backoff (1s -> 2s -> 4s).

Handling partial failures (e.g., Twitter succeeds, but LinkedIn fails and retries without posting to Twitter twice).

(Vercel Note: This API is hosted on Vercel. Because Vercel goes to "sleep" when idle, the background worker might pause. If your posts seem stuck in "queued", simply hit an API endpoint to wake the server up, and the queue will process!)

✅ Features Completed

[x] Dynamic Telegram Keys: Pass your API keys directly via Telegram Chat.

[x] Strict Input Validation: The bot gracefully handles and rejects invalid platform choices.

[x] Secure Auth: JWT Authentication & AES-256 Encryption for API Keys at rest.

[x] Optimized Database: Prisma ORM with normalized PostgreSQL Schema and explicit @@index optimization for fast querying.

[x] AI Engine: Full OpenAI & Anthropic SDK Integration with real token/cost extraction.

[x] Queue Architecture: BullMQ + Redis background publishing with simulated exponential backoff.

[x] Stateful Bot: Telegram session management via Redis & Webhooks.

[x] Testing: Complete Jest Integration Test Suite proving the core API is stable.

📦 Commit History Guide

To demonstrate an incremental, logical build progression (as requested in the rubric), the project was built using the following commit structure:

feat: setup db schema, express server, and complete jwt auth flow

Setup PostgreSQL, Redis, Prisma schema, and built the JWT Auth system.

feat: add complete user profile endpoints and aes-256 encryption for api keys

Implemented full CRUD for user settings and secure AES-256 storage.

feat: implement openai/claude content generation and bullmq publishing queue

Integrated official SDKs and setup BullMQ to handle background publishing tasks.

feat: build complete stateful telegram bot flow using redis sessions and webhooks

Built the Telegram bot using Redis to track conversational state dynamically.

chore: add dashboard endpoints, vercel config, comprehensive jest tests, and final documentation

Added REST stats, configured Vercel serverless routes, and ensured 100% test passing.

fix: add token cost extraction, schema indexes for performance, and strict telegram input validation

Final polish addressing the specific rubric points for token awareness, DB query optimization, and bad input handling.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages