The Blogging Platform is a modern web application designed to mimic the functionality of popular platforms like Medium, allowing users to create, update, and manage blog posts. The project utilizes a comprehensive tech stack including React for the frontend, Cloudflare Workers for serverless backend processing, and PostgreSQL as the database, all tied together with Prisma ORM for efficient database interactions. It ensures secure user authentication through JWT (JSON Web Tokens), while Zod is employed to validate incoming data and infer types for better type safety with TypeScript. The project emphasizes a clean, scalable structure by separating frontend, backend, and shared modules into different parts. Key features include user signup, login, blog post creation, editing, and retrieval. This project demonstrates best practices in serverless architecture, database management, and type-safe development, making it a valuable learning experience for developers aiming to build robust, scalable web applications.
The stack used for building the application is:
- Frontend: React
- Backend: Cloudflare Workers
- Validation: Zod (with type inference)
- Language: TypeScript
- ORM: Prisma (with connection pooling)
- Database: PostgreSQL
- Authentication: JWT (JSON Web Tokens)
The project is divided into two main sections:
- Backend: Implements APIs and handles requests using Cloudflare Workers.
- Frontend: Provides the user interface built with React.
- User Authentication:
- Sign-up and sign-in functionality with JWT-based authentication.
- Passwords are securely stored using hashing.
- Blog Management:
- Users can create, update, and retrieve blogs.
- Protected routes ensure only authenticated users can create or edit blogs.
Ensure you have the following installed:
- Node.js
- npm or yarn
- PostgreSQL database
-
Clone the repository:
git clone https://github.com/miravanisri/MediumBloggingApp.git cd MEDIUM_BLOGGING_APP/backend
-
Install backend dependencies:
npm install
-
Initialize the project with Cloudflare Workers and Hono framework:
npm create hono@latest
-
Configure environment variables:
- Create an
.env
file in thebackend
directory:
DATABASE_URL="postgres://yourusername:yourpassword@host/db" JWT_SECRET="your_jwt_secret"
- Create an
-
Initialize the Prisma ORM:
npx prisma init
-
Migrate the Prisma schema:
npx prisma migrate dev --name init_schema
-
Start the backend server:
npm start
-
Navigate to the frontend folder:
cd ../frontend
-
Install frontend dependencies:
npm install
-
Start the frontend server:
npm start
POST /api/v1/user/signup
: Sign up a new user.POST /api/v1/user/signin
: Sign in an existing user.POST /api/v1/blog
: Create a new blog post.PUT /api/v1/blog
: Update an existing blog post.GET /api/v1/blog/:id
: Get a single blog post by ID.GET /api/v1/blog/bulk
: Get all blog posts.
The database schema for users and blogs is defined using Prisma:
model User {
id String @id @default(uuid())
email String @unique
name String?
password String
posts Post[]
}
model Post {
id String @id @default(uuid())
title String
content String
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId String
}
- Log into Cloudfare
wrangler login
- Deploy the Application
npm run deploy
- Test the production URL using Postman or any other API client.