A scalable and robust RESTful API for a blog platform built with NestJS, Drizzle ORM, and PostgreSQL.
- 🔐 Authentication & Authorization:
- JWT-based authentication
- Role-Based Access Control (Admin, Author, Reader)
- Account verification via email
- Password reset flows
- 👥 User Management:
- Public & Private profiles
- Avatar uploads (Cloudinary)
- Admin dashboard stats
- 📝 Content Management:
- Posts: Rich CRUD operations, Cover images, Full-text Search over titles/content.
- Taxonomy: Categories and Tags management.
- Status: Draft, Published, Archived workflows.
- 💬 Engagement:
- Comments: Nested/Threaded comments system.
- Reactions: Like system for Posts and Comments.
- Bookmarks: Save posts for later.
- Views: Track post view counts.
- 📢 Communication:
- Newsletters: Subscription management and email handling.
- Contact Form: Direct inquiries sent to admins via email.
- 🛡️ Moderation:
- Report system for Posts, Comments, and Users.
- ⚙️ Technical Features:
- Media: Optimized image uploads via Cloudinary.
- Security: Helmet, Rate Limiting (Throttler), Compression.
- Docs: Interactive API documentation via Scalar.
- Framework: NestJS 11
- Language: TypeScript
- Database: PostgreSQL (NeonDB recommended)
- ORM: Drizzle ORM
- Mail: Nodemailer
- Storage: Cloudinary
- Documentation: @scalar/nestjs-api-reference
- Package Manager: pnpm
src/
├── common/ # Shared guards, decorators, filters, types
│ ├── decorators/ # Custom decorators (@CurrentUser, @Roles)
│ ├── guards/ # Auth & Roles guards
│ ├── swagger/ # Swagger/Scalar configuration
│ └── ...
├── database/ # Drizzle ORM configuration
│ ├── migrations/ # SQL migration files
│ └── schema/ # Database schema definitions
├── modules/ # Feature modules
│ ├── auth/ # Authentication & Account verification
│ ├── posts/ # Blog posts logic
│ ├── users/ # User management
│ ├── comments/ # Commenting system
│ ├── mail/ # Email service (Nodemailer)
│ └── ...
├── app.module.ts # Main application module
└── main.ts # Application entry pointThe system supports three user roles with hierarchical permissions:
- 👑 Admin (
admin):- Full system access.
- Manage all Users, Posts, Comments, Categories, and Tags.
- View System Stats and Reports.
- Manage Newsletters.
- ✍️ Author (
author):- Create and Manage their own Posts.
- Upload media.
- Manage comments on their posts.
- 📖 Reader (
reader) (Default):- Read posts and comments.
- Comment on posts.
- Bookmark posts.
- Like/React to content.
- Report content.
Ensure you have the following installed:
- Node.js (v20+ recommended)
- pnpm
- PostgreSQL
-
Clone the repository:
git clone https://github.com/misbahul-alam/blog-platform-api.git cd blog-platform-api -
Install dependencies:
pnpm install
-
Configure environment variables:
Copy the example file to create your own configuration:
cp .env.example .env
Configuration Reference:
Variable Description Example PORTApplication port 3000NODE_ENVEnvironment mode development/productionFRONTEND_URLFrontend App URL (for email links) http://localhost:3000DATABASE_URLPostgreSQL connection string postgresql://user:pass@host/dbJWT_SECRETSecret key for signing tokens supersecr3tCLOUDINARY_NAMECloudinary Cloud Name my-cloudCLOUDINARY_API_KEYCloudinary API Key 123456...CLOUDINARY_API_SECRETCloudinary Secret abcde...SMTP_HOSTMail server host smtp.gmail.comSMTP_USERMail server username user@gmail.comSMTP_PASSMail server password app-specific-password
This project uses Drizzle ORM for database management.
-
Generate Migrations:
pnpm run drizzle:generate
-
Run Migrations:
pnpm run drizzle:migrate
Applies the generated SQL changes to your connected database.
-
Seed Database (Optional):
pnpm run drizzle:seed
# development
pnpm run start
# watch mode
pnpm run start:dev
# production mode
pnpm run start:prodOnce the application is running, you can access the interactive API documentation at:
http://localhost:3000/docs
The documentation is powered by Scalar and provides a comprehensive view of all endpoints, schemas, and authentication methods.
# unit tests
pnpm run test
# e2e tests
pnpm run test:e2e
# test coverage
pnpm run test:covMigration Conflicts:
If you encounter relation "table" already exists errors during migration:
- Ensure your local DB is clean or matches the migration state.
- Use
pnpm run drizzle:pushto sync without creating a migration file if in early dev.
Scalar Docs White Screen:
Ensure helmet content security policy is correctly configured to allow inline scripts, or disabled for the docs path. This project already handles this in main.ts.
This project is licensed under the MIT License.