Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Circle API

Backend REST API untuk Circle Web, dibangun menggunakan Node.js, Express.js, TypeScript, PostgreSQL, Prisma ORM, dan Socket.IO untuk mendukung komunikasi real-time.


🚀 Tech Stack

  • Node.js
  • Express.js
  • TypeScript
  • PostgreSQL
  • Prisma ORM
  • Socket.IO
  • JWT Authentication
  • Bcrypt
  • Multer

📌 Base URL

Server berjalan pada port 2323.

http://localhost:2323/api

Seluruh routing API berada pada folder:

src/routes

Authentication

Endpoint: /api/auth

Route File

src/routes/authRoute.ts

Controller

src/controllers/authController.ts

Authentication menggunakan:

  • JWT (JSON Web Token)
  • Token Expired : 1 Hari (1d)
  • Password Hashing : bcrypt (10 rounds)

Register

POST

POST /api/auth/register

Request Body

{
  "username": "string",
  "email": "string",
  "password": "string",
  "full_name": "string"
}

full_name bersifat opsional.


Login

POST

POST /api/auth/login

Request Body

{
  "email": "string",
  "password": "string"
}

Success Response

{
  "message": "Login Successfully",
  "token": "JWT_TOKEN"
}

User

Endpoint: /api/user

Route File

src/routes/userRoute.ts

Controller

userController.ts
follow.ts

Semua endpoint di bawah memerlukan Authorization Header.

Authorization: Bearer <token>

Get My Profile

GET /api/user/profile

Mengambil data profil user yang sedang login beserta:

  • Profile
  • Followers Count
  • Following Count
  • Semua Thread
  • Status Like (isLiked) pada setiap thread

Update Profile

PATCH /api/user/profile

Request Body

{
  "username": "string",
  "full_name": "string",
  "bio": "string"
}

Get All Users

GET /api/user/allUser

Mengambil daftar seluruh pengguna selain user yang sedang login.

Response juga menyertakan:

  • Status Follow (isFollowing)

Get Followers & Following

GET /api/user/follow

Mengambil daftar:

  • Followers
  • Following

Get User By ID

GET /api/user/:id

Mengambil profil user berdasarkan ID beserta seluruh thread yang dimiliki.


Follow / Unfollow User

POST /api/user/follow/:id

Toggle Follow:

  • Follow User
  • Unfollow User

Threads

Endpoint: /api/thread

Route File

src/routes/threadRoute.ts

Controller

threadController.ts
detailThread.ts

Seluruh endpoint membutuhkan JWT Authentication.

Authorization: Bearer <token>

Create Thread

POST /api/thread/posting

Membuat postingan baru.

Menggunakan multipart/form-data

Field Type
content Text
image File

Socket Event

thread:new

Dipancarkan setelah thread berhasil dibuat.


Get Home Threads

GET /api/thread/home

Mengambil seluruh thread terbaru beserta:

  • Informasi penulis
  • Total Like
  • Total Reply
  • Status Like (isLiked)

Like / Unlike Thread

POST /api/thread/:id/like

Melakukan toggle:

  • Like
  • Unlike

Socket Event

like:update

Payload:

{
  "threadId": 1,
  "userId": 2,
  "liked": true,
  "likeTotal": 10
}

Get Thread Detail

GET /api/thread/:threadId

Mengambil detail thread beserta seluruh replies.


Reply Thread

POST /api/thread/:threadId/reply

Mengirim balasan ke thread.

Menggunakan multipart/form-data

Field Type
content Text
image File

Socket Events

Reply Baru

reply:new

Reply Notification

reply-notification

Notifikasi dikirim ke room:

user-<creator_id>

Contoh pesan:

username mengomentari postingan kamu

Socket.IO Events

Socket.IO diinisialisasi pada:

src/index.ts

CORS diizinkan untuk:

http://localhost:5173

thread:new

Mengirim thread baru ke seluruh client yang sedang aktif.


like:update

Payload

{
  "threadId": 1,
  "userId": 2,
  "liked": true,
  "likeTotal": 5
}

reply:new

Payload

{
  "threadId": 1,
  "reply": {}
}

reply-notification

Mengirim notifikasi kepada pemilik thread ketika thread mendapat balasan.

Contoh:

username mengomentari postingan kamu

Database Schema

Database menggunakan PostgreSQL dengan Prisma ORM.

User

Menyimpan data pengguna.

Field utama:

  • username
  • full_name
  • email
  • password
  • photo_profile
  • bio

Follow

Tabel relasi Many-to-Many untuk sistem Follow & Followers.


Threads

Menyimpan seluruh postingan pengguna.


Replies

Menyimpan komentar atau balasan pada thread.

Relasi:

  • User
  • Threads

Like

Menyimpan data like dari user terhadap thread tertentu.


Authentication Header

Untuk seluruh endpoint yang membutuhkan autentikasi, gunakan:

Authorization: Bearer YOUR_JWT_TOKEN

Features

  • ✅ JWT Authentication
  • ✅ Register & Login
  • ✅ User Profile
  • ✅ Update Profile
  • ✅ Follow / Unfollow
  • ✅ Thread Posting
  • ✅ Image Upload (Multer)
  • ✅ Like / Unlike
  • ✅ Replies
  • ✅ Real-time Socket.IO
  • ✅ PostgreSQL Database
  • ✅ Prisma ORM
  • ✅ TypeScript

About

RESTful social media API with real-time features.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages