This is a full-stack blog application built with Node.js, Prisma, GraphQL, TypeScript on the backend and React.js, Tailwind CSS, GraphQL on the frontend.
- Technologies Used
- Prerequisites
- Installation
- Database Schema
- Database Relations
- Running the Application
- Folder Structure
- Contributing
- License
- Note
- Node.js
- Prisma
- GraphQL
- TypeScript
- PostgreSQL
- React.js
- Tailwind CSS
- GraphQL
- Node.js (v20.x or later)
- PostgreSQL
- Yarn or npm
- Clone the repository:
git clone https://github.com/raihanwebmaster/blog-application.git
cd blog-application
- Set up the environment variables. Create a
.env
file in the root directory and add the following:
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
- Install dependencies for both backend and frontend:
# Install backend dependencies
cd backend
yarn install
# Install frontend dependencies
cd ../frontend
yarn install
- Apply the Prisma migrations to set up the database:
cd ../backend
npx prisma migrate dev
The database schema is defined using Prisma. The schema is as follows:
model Post {
id Int @id @default(autoincrement())
title String
content String
authorId Int
author User @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean @default(false)
@@map("posts")
}
model User {
id Int @id @default(autoincrement())
name String
email String
password String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
posts Post[]
profile Profile?
@@map("users")
}
model Profile {
id Int @id @default(autoincrement())
bio String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int @unique
user User @relation(fields: [userId], references: [id])
@@map("profiles")
}
The database schema defines the following relations:
-
User and Post: A one-to-many relation where a user can have multiple posts. Each post is linked to a single user via the
authorId
field. -
User and Profile: A one-to-one relation where each user can have one profile, and each profile is linked to a single user via the
userId
field.
Here is a visual representation of the relations:
- A
User
has manyPost
s. - A
Post
belongs to a singleUser
. - A
User
has oneProfile
. - A
Profile
belongs to a singleUser
.
To start the backend server:
cd backend
yarn start
To start the frontend development server:
cd frontend
yarn start
The project structure is as follows:
blog-application/
├── server/
│ ├── src/
│ ├── prisma/
│ ├── package.json
│ └── ...
├── client/
│ ├── src/
│ ├── public/
│ ├── package.json
│ └── ...
└── README.md
Contributions are welcome! Please fork the repository and submit a pull request.
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature-branch
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
The frontend part of this project is not fully completed as the focus is on the backend development. Contributions to complete the frontend part are welcome.