Skip to content

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.

License

Notifications You must be signed in to change notification settings

raihanwebmaster/GraphQL-Blog-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Blog Application

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.

Table of Contents

Technologies Used

Backend

  • Node.js
  • Prisma
  • GraphQL
  • TypeScript
  • PostgreSQL

Frontend

  • React.js
  • Tailwind CSS
  • GraphQL

Prerequisites

  • Node.js (v20.x or later)
  • PostgreSQL
  • Yarn or npm

Installation

  1. Clone the repository:
git clone https://github.com/raihanwebmaster/blog-application.git
cd blog-application
  1. 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"
  1. Install dependencies for both backend and frontend:
# Install backend dependencies
cd backend
yarn install

# Install frontend dependencies
cd ../frontend
yarn install
  1. Apply the Prisma migrations to set up the database:
cd ../backend
npx prisma migrate dev

Database Schema

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")
}

Database Relations

The database schema defines the following relations:

  1. 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.

  2. 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 many Posts.
  • A Post belongs to a single User.
  • A User has one Profile.
  • A Profile belongs to a single User.

Running the Application

Backend

To start the backend server:

cd backend
yarn start

Frontend

To start the frontend development server:

cd frontend
yarn start

Folder Structure

The project structure is as follows:

blog-application/
├── server/
│   ├── src/
│   ├── prisma/
│   ├── package.json
│   └── ...
├── client/
│   ├── src/
│   ├── public/
│   ├── package.json
│   └── ...
└── README.md

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Note

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published