Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WriteIt - Blog API

WriteIt is a RESTful blogging API built using Express, TypeScript, and Prisma ORM with PostgreSQL as the database. It provides a modular and scalable structure for handling blog operations such as user registration, authentication, post creation, and comments.


🧩 Features

  • ✅ User registration & login (JWT-based auth)
  • 📝 Create, update, delete blog posts
  • 💬 Commenting system with nested replies
  • 🔒 Auth middleware with token validation and blacklisting
  • 🧪 Input validation using Zod
  • 🌐 Swagger (OpenAPI) documentation
  • 🏷️ Modular folder structure (User, Post, Comment modules)

📁 Project Structure

src/
├── app.ts                # Express app setup
├── server.ts             # Server bootstrap
├── lib/                  # Utility functions (hashing, JWT)
├── middlewares/          # Auth, error handling, validators
├── modules/
│   ├── users/
│   │   ├── user.controller.ts
│   │   ├── user.service.ts
│   │   ├── user.route.ts
│   │   ├── user.model.prisma
│   │   └── user.docs.ts
│   ├── posts/
│   └── comments/
├── prisma/
│   ├── schema.prisma     # Main Prisma schema file
│   └── migrations/
├── routes/
│   └── index.ts          # Centralized route importer
├── docs/
│   └── swagger.ts        # Swagger configuration
└── index.ts              # Entry point

🛠 Tech Stack

  • Node.js + Express
  • TypeScript
  • Prisma ORM
  • PostgreSQL
  • Redis (for token blacklisting)
  • Zod (request validation)
  • Swagger (API docs)

🚀 Getting Started

1. Clone Repo

git clone https://github.com/LmOpe/write-it.git
cd writeit

2. Install Dependencies

npm install

3. Setup Environment

Create a .env file with the following:

DATABASE_URL=postgresql://username:password@localhost:5432/writeit
JWT_SECRET=your_jwt_secret
REDIS_URL=redis://localhost:6379
PORT=5000

4. Migrate DB

npx prisma migrate dev --name init

5. Start Server

npm run dev

🔐 Authentication

  • JWT-based token authentication
  • Login generates accessToken
  • Protected routes require Authorization: Bearer <token>

Token Blacklisting

Redis is used to track and expire blacklisted tokens.


📘 API Documentation

Once server is running:


✅ Example Request

Register

POST /api/users/register
{
  "username": "johnDoe",
  "email": "john@example.com",
  "password": "MySecurePass123!"
}

👨‍💻 Author

Muhammed Lawal GitHub

About

WriteIt is a modular and scalable RESTful API for a blogging platform. Built with Express, TypeScript, Prisma, and PostgreSQL, it supports user authentication, post and comment management, and token-based access control. Ideal for modern web applications with a clean, organized codebase.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages