Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ Blog-API β€” Full-Stack Blogging Platform

A modern blogging platform built with Node.js, React, Express, Prisma, and PostgreSQL. Features an admin dashboard for managing posts and comments, plus a public blog interface for readers.

Quick Links: Features | Setup | API Docs | Learnings


🎬 Demo

demo.mp4

πŸ“Έ Screenshots

Client

Client Home Client Login Client Register Client Comments Edit Comment Modal

Admin

Admin Login Admin Dashboard Create Post Edit Post

Database

Database


✨ Features

πŸ” Authentication & Authorization

  • User Registration & Login with secure JWT-based authentication
  • Role-Based Access Control (AUTHOR & USER roles)
  • Protected Routes ensuring only authenticated users can access specific features
  • Secure Password Hashing using bcrypt

πŸ“ Blog Management

  • Create & Edit Posts with rich content support
  • Publish/Unpublish posts with one-click toggle
  • Delete Posts with cascading comment removal
  • View Author-Specific Posts in admin dashboard
  • Manage Post Metadata (title, content, published status)

πŸ’¬ Comments System

  • Add Comments to published posts
  • View Comments with commenter information
  • Delete Comments (by comment owner or post author)
  • Comment Moderation for post owners
  • Edit Comments with a beautiful modal interface
  • Real-time Updates when comments are modified
  • Self-Service Registration with automatic session establishment

🎨 User Interface

  • Admin Dashboard with post management interface
  • Public Blog Page showcasing published posts
  • Login Page with session management
  • Responsive Design built with Tailwind CSS
  • Smooth Navigation using React Router v7
  • Real-Time UI Updates without page reloads

πŸ›  Tech Stack

Backend

  • Node.js & Express.js β€” Server runtime and framework
  • Prisma ORM β€” Type-safe database access
  • PostgreSQL β€” Relational database
  • JWT (jsonwebtoken) β€” Authentication tokens
  • bcrypt β€” Password hashing
  • Nodemon β€” Development server auto-reload

Frontend (Admin)

  • React 19 β€” UI library
  • React Router v7 β€” Client-side routing
  • Tailwind CSS v4 β€” Utility-first styling
  • Vite β€” Fast build tool
  • ESLint β€” Code quality

Frontend (Client)

  • React 19 β€” UI library
  • React Router v7 β€” Navigation
  • Tailwind CSS v4 β€” Styling
  • Vite β€” Build system

Database Schema

User (id, username, email, password, role, posts[], comments[])
Post (id, title, content, published, authorId, author, comments[], createdAt, updatedAt)
Comment (id, content, postId, post, userId, user, createdAt, editedAt)

πŸš€ Installation

Prerequisites

  • Node.js (v18 or higher)
  • PostgreSQL (v12 or higher)
  • npm or yarn

Step 1: Clone & Setup

cd Blog-API

Step 2: Install Dependencies

Backend

cd api
npm install

Admin Frontend

cd ../admin
npm install

Client Frontend

cd ../client
npm install

Step 3: Configure Environment

Create .env file in the api directory:

DATABASE_URL="postgresql://user:password@localhost:5432/blog_db"
JWT_SECRET="your-secret-key-here"
PORT=5000

Step 4: Database Setup

Initialize Prisma and run migrations:

cd api
npx prisma migrate dev --name init
npm run seed  # Populate with demo data

Step 5: Run Development Servers

Terminal 1 β€” Backend API

cd api
npm run dev
# Runs on http://localhost:5000

Terminal 2 β€” Admin Dashboard

cd admin
npm run dev
# Runs on http://localhost:5173

Terminal 3 β€” Client Blog

cd client
npm run dev
# Runs on http://localhost:5174

πŸ“š API Documentation

Authentication Endpoints

Register User

POST /auth/register
Content-Type: application/json

{
  "username": "john_doe",
  "email": "john@example.com",
  "password": "SecurePass123",
  "role": "AUTHOR"
}

Login

POST /auth/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "SecurePass123"
}

Response: { token: "jwt-token", username, role }

Post Endpoints

Get All Public Posts

GET /posts
Authorization: Bearer {token} (optional)

Get Author's Posts

GET /posts/my-posts
Authorization: Bearer {token}

Create Post

POST /posts
Authorization: Bearer {token}
Content-Type: application/json

{
  "title": "My First Blog Post",
  "content": "This is the content...",
  "published": true
}

Update Post

PUT /posts/:id
Authorization: Bearer {token}
Content-Type: application/json

{
  "title": "Updated Title",
  "content": "Updated content...",
  "published": true
}

Toggle Publish Status

PATCH /posts/:id/publish
Authorization: Bearer {token}

Delete Post

DELETE /posts/:id
Authorization: Bearer {token}

Comment Endpoints

Get All Comments

GET /comments

Add Comment

POST /comments
Authorization: Bearer {token}
Content-Type: application/json

{
  "content": "Great post!",
  "postId": 1
}

Delete Comment

DELETE /comments/:id
Authorization: Bearer {token}

πŸ“ Project Structure

Blog-API/
β”œβ”€β”€ api/                          # Backend server
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ authController.js     # Authentication logic
β”‚   β”‚   β”œβ”€β”€ postController.js     # Post CRUD operations
β”‚   β”‚   └── commentController.js  # Comment management
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ authMiddleware.js     # JWT verification
β”‚   β”‚   β”œβ”€β”€ optionalAuthMiddleware.js
β”‚   β”‚   └── roleMiddleware.js     # Role-based access
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”œβ”€β”€ postRoutes.js
β”‚   β”‚   └── commentRoutes.js
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”œβ”€β”€ schema.prisma         # Database schema
β”‚   β”‚   └── migrations/           # Database migrations
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   └── prisma.js             # Prisma client setup
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   └── seed.js               # Demo data seeding
β”‚   β”œβ”€β”€ app.js                    # Express app configuration
β”‚   └── package.json
β”‚
β”œβ”€β”€ admin/                        # Admin dashboard (React)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ CreatePost.jsx    # Create post form
β”‚   β”‚   β”‚   β”œβ”€β”€ EditPost.jsx      # Edit post form
β”‚   β”‚   β”‚   β”œβ”€β”€ MyPosts.jsx       # Dashboard with posts & comments
β”‚   β”‚   β”‚   └── LoginPage.jsx     # Admin login
β”‚   β”‚   β”œβ”€β”€ App.jsx               # Root component
β”‚   β”‚   β”œβ”€β”€ main.jsx
β”‚   β”‚   └── index.css             # Tailwind + custom styles
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ vite.config.js
β”‚   └── package.json
β”‚
β”œβ”€β”€ client/                       # Client blog (React)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx
β”‚   β”‚   β”‚   └── PostsPage.jsx
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ main.jsx
β”‚   β”‚   └── index.css
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ vite.config.js
β”‚   └── package.json
β”‚
└── README.md

πŸ“– What I've Learned

  • βœ… Express & Middleware β€” Request/response pipeline, error handling
  • βœ… Prisma ORM β€” Database queries, relationships, transactions
  • βœ… JWT Authentication β€” Token generation and validation
  • βœ… Role-Based Access Control β€” Permission management
  • βœ… React Hooks β€” useState, useEffect, custom hooks
  • βœ… React Router v7 β€” Client-side routing and navigation
  • βœ… Fetch API β€” HTTP requests with proper headers
  • βœ… Tailwind CSS β€” Responsive design and utility classes
  • βœ… Form Handling β€” Controlled components and validation
  • βœ… State Management β€” Lifting state and functional updates

πŸ”’ Security

  • JWT tokens stored in localStorage
  • Passwords hashed with bcrypt
  • Role-based access control on all endpoints
  • Input validation on client and server
  • SQL injection protection via Prisma ORM

Security & Production Notes

  • Rate limiting: added route- and action-specific limits to reduce abuse. See api/middleware/rateLimiters.js.

    • authLimiter β€” stricter login limiter (5 login attempts per minute).
    • commentLimiter β€” comment creation limiter (10 comments per minute).
    • A global limiter is also configured on the API to throttle general traffic (e.g. 100 requests / 15 minutes).
  • Pagination: server-side pagination implemented for public posts (GET /posts) and author posts (GET /posts/my-posts) using page and limit query parameters. API responses include a pagination object. Frontend UIs in client and admin were updated to use paged requests.

  • Delete confirmations: replaced native confirm() dialogs with a reusable styled modal on both frontends to avoid accidental deletions and improve UX. See client/src/components/ConfirmDeleteModal.jsx and admin/src/components/ConfirmDeleteModal.jsx.

  • Disable source maps in production: Vite configs for both frontends now disable source maps for production builds to avoid publishing original source mappings. See client/vite.config.js and admin/vite.config.js (build.sourcemap toggled by mode === "production").


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit changes (git commit -m 'Add feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a Pull Request

πŸ“„ License

ISC License


πŸŽ“ Created By

Mohamed Mosilhy β€” Full-Stack Developer


Built with ❀️ using Node.js, React, and PostgreSQL

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages