SimpleBlog CMS is a headless Content Management System (CMS) for a simple blog application. It provides a RESTful API for managing users, posts, and comments.
- User Authentication: Secure user registration and login using JSON Web Tokens (JWT).
- Post Management: Full CRUD (Create, Read, Update, Delete) functionality for blog posts.
- Comment System: Users can add comments and replies to posts. Full CRUD on comments is also supported.
- Markdown to HTML: Automatically converts post content from Markdown to HTML.
- Password Hashing: Securely hashes user passwords before storing them in the database.
- Environment-based Configuration: Easy setup using environment variables.
- Backend: Node.js, Koa.js
- Database: PostgreSQL with Sequelize ORM
- Language: TypeScript
- Authentication: JSON Web Tokens (JWT), bcrypt.js for hashing
- Content:
markedfor Markdown to HTML conversion andDomPurifyfor converted HTML sanitization. - Emailing:
nodemailerfor sending emails (email verification, password resets).
/src
├── /config # Environment variables and configuration
├── /controllers # Request handlers and business logic
├── /middleware # Koa middleware (e.g., auth)
├── /models # Sequelize schemas and models
├── /routes # API route definitions
├── /utils # Utility functions
└── app.ts # Application entry point
sequenceDiagram
participant Client
participant API as "API (Koa.js)"
participant DB as "DB (PostgreSQL)"
Client->>API: POST /api/auth/register (name, email, password)
API->>API: Hash password (e.g., bcrypt)
API->>DB: INSERT INTO users (...)
DB-->>API: Return created user row
API->>API: Generate JWT
API-->>Client: Respond with User Info & JWT
Client->>API: POST /api/auth/login (email, password)
API->>DB: SELECT * FROM users WHERE email = ?
DB-->>API: Return user row (with hashed password)
API->>API: Compare provided password with stored hash
alt Passwords Match
API->>API: Generate JWT
API-->>Client: Respond with JWT
else Passwords Do Not Match
API-->>Client: Respond with 401 Unauthorized
end
Client->>API: GET /api/posts (Authorization: Bearer JWT)
API->>API: Verify JWT
alt JWT is Valid
API->>DB: SELECT * FROM posts
DB-->>API: Return post rows
API-->>Client: Respond with posts data
else JWT is Invalid
API-->>Client: Respond with 401 Unauthorized
end
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
- Node.js (v20+ recommended)
- PostgreSQL is installed and running.
- Clone the repository:
git clone https://github.com/ujarhr/simpleblog-cms.git
cd simpleblog-cms
- Install dependencies:
pnpm install
- Set up environment variables:
Create a
.envfile in the root of the project by copying the example file:
cp .env.example .env
- Now, open the
.envfile and fill in the required values:
ENV=development
PORT=3000
JWT_SECRET=A_Long_Random_Secret
# Project Info
PROJECT_NAME=SimpleBlog CMS
PROJECT_EMAIL=hello@rhraju.com
# Database Configurations
DB_TYPE=postgres
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USER=root
DB_PASS=password
DB_NAME=simpleblog
# SMTP Configurations
SMTP_HOST=smtp.ethereal.email
SMTP_PORT=587
SMTP_USER=demo@ethereal.email
SMTP_PASS=Your_Ethereal_Password
- Running the Application:
pnpm run dev
Overall Project Details -> Markdown Note-taking App
This project is licensed under the MIT License - see the LICENSE file for details.