- User Authentication: Secure authentication powered by Better-Auth.
- Post Management: Full CRUD operations for blog posts with support for tags, featured posts, and drafts.
- Commenting System: Interactive comments with nested replies (threading) and moderation control.
- Admin Tools: Built-in scripts for seeding admin accounts.
- Type Safety: Fully written in TypeScript with Prisma for end-to-end type safety.
- Email Integration: Integrated with Nodemailer for system notifications.
The frontend client for this project is available at: https://github.com/amisadman/papertrail-client
Below is the Entity-Relationship Diagram (ERD) representing the database structure:
erDiagram
USER ||--o{ SESSION : "has"
USER ||--o{ ACCOUNT : "has"
USER ||--o{ POST : "authors"
USER ||--o{ COMMENT : "writes"
POST ||--o{ COMMENT : "contains"
COMMENT ||--o{ COMMENT : "replies to"
USER {
string id PK
string name
string email UK
boolean emailVerified
string image
string role
string phone
string status
datetime createdAt
datetime updatedAt
}
SESSION {
string id PK
string token UK
datetime expiresAt
string userId FK
string ipAddress
string userAgent
}
ACCOUNT {
string id PK
string accountId
string providerId
string userId FK
string accessToken
string refreshToken
datetime accessTokenExpiresAt
}
POST {
string id PK
string title
string content
string thumbnail
boolean isFeatured
enum status
string[] tags
int views
string authorId FK
datetime createdAt
datetime updatedAt
}
COMMENT {
string id PK
string content
string authorId FK
string postId FK
string parentId FK
enum status
datetime createdAt
datetime updatedAt
}
VERIFICATION {
string id PK
string identifier
string value
datetime expiresAt
}
- Runtime: Node.js
- Framework: Express.js
- ORM: Prisma
- Database: PostgreSQL
- Language: TypeScript
- Auth: Better-Auth
- Logging: Morgan
- Node.js (v18+)
- pnpm (preferred) or npm
- PostgreSQL database
-
Clone the repository:
git clone https://github.com/amisadman/papertrail-server.git cd papertrail-server -
Install dependencies:
pnpm install
-
Setup environment variables: Create a
.envfile in the root directory and add your configuration (see.env.example). -
Generate Prisma Client:
npx prisma generate
-
Run database migrations:
npx prisma migrate dev
-
Development Mode:
pnpm run dev
-
Seed Admin:
pnpm run seed:admin
