A Node.js backend API demonstrating advanced Prisma ORM patterns with PostgreSQL database integration.
PagePal is a book review and recommendation API that showcases advanced database modeling and ORM techniques. This project serves as a reference implementation for how to effectively use Prisma ORM with PostgreSQL in a Node.js environment.
- 🔐 Authentication: Secure JWT-based user sessions
- 👑 Role-Based Access Control: Tiered permissions with USER, AUTHOR, and ADMIN roles
- 📝 Audit Logging: Comprehensive activity tracking for all user actions
- 📖 Book Catalog: Complete CRUD operations for books including metadata (title, description, genre, author, published year, ISBN)
- 🏷️ Classification: Multi-faceted organization with genres and tags
- ⭐ Ratings & Reviews: Users can rate books (1-5 stars) and write detailed reviews
- ✍️ Author Application Process: Users can apply to become recognized authors
- 👨💼 Admin Moderation: Application review and approval workflow
- 📚 Collections: Create and manage personal book collections
- 🤝 Sharing: Collaborate on collections with other users
- 👥 Follow System: Stay updated on other users' reading activities
- ⚡ Rate Limiting & Pagination: Performance optimizations for large datasets
Our non-AI recommendation algorithm analyzes:
- User ratings history
- Review sentiment
- Content similarity
- Genre preferences
- Reading patterns
This creates a personalized book discovery experience without the complexity of machine learning implementation.
-
Core Schema Design & Relations: Implements complex many-to-many, one-to-many, and self-referential relationships using Prisma's relation fields. Features composite unique constraints and proper indexing for performance optimization.
-
CRUD Operations with Prisma Client: Leverages Prisma Client's type-safe API for all database interactions with full TypeScript integration.
-
Soft Deletes: Implements non-destructive record removal by maintaining
deletedAt
timestamps rather than performing hard deletes, preserving data integrity and referential consistency. -
Enums & Indexed Fields: Uses Prisma's Enum support for type-safe role definitions and strategic database indexing for query performance.
-
Pagination: Implements cursor-based pagination for efficient large dataset traversal with optimized query patterns.
-
JSON Support for Flexibility: Utilizes PostgreSQL's native JSON field support for storing semi-structured data like user preferences and book metadata.
-
Audit Logging: Comprehensive activity tracking through Prisma middleware that captures all model operations with before/after states.
-
Role-Based Access Control (RBAC): Tiered permission system using Prisma Enums with middleware validation for protected endpoints.
-
Rate Limiting: Implements request throttling to prevent API abuse and ensure system stability.
-
Transaction Management: Ensures data consistency for multi-table operations using Prisma's transaction support.
-
Authentication Flow: Secure JWT-based authentication with refresh token rotation.
-
Request Validation: Type-safe request validation using Prisma's generated TypeScript types.
-
Error Handling: Centralized error processing with appropriate HTTP status codes.
- Strategic database indexing on frequently queried fields
- Efficient relation loading with Prisma's include patterns
- Query performance monitoring and optimization
- Node.js (v14+)
- PostgreSQL (v13+)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd <repository-directory>
-
Install dependencies
npm install
-
Configure environment Create a
.env
file with your database connection:DATABASE_URL="postgresql://user:password@localhost:5432/db_name" JWT_REFRESH_SECRET="your-refresh-secret-key" JWT_ACCESS_SECRET="your-access-secret-key"
-
Set up the database
npx prisma migrate dev
-
Seed initial data
npx prisma db seed
-
Start the development server
npm run dev
-
Access the application Open your browser to
http://localhost:5000
- 🔍 Advanced Search: Full-text search capabilities across all book content
- 🤖 ML-powered Recommendations: Integration of machine learning models for more sophisticated book suggestions
- 📊 Analytics Dashboard: Insights into reading trends and user engagement
- 🌐 Social Features: Enhanced community interactions and book discussions
- 📱 Mobile Applications: Native iOS and Android clients
This project is licensed under the ISC License
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Runtime: Node.js with Express
- Language: TypeScript for type safety
- Database: PostgreSQL for relational data storage
- ORM: Prisma for database interactions
- Authentication: JWT with refresh token rotation
- Security: Helmet, CORS, and rate limiting
- Development: Concurrently for parallel process running