Skip to content

nasirmasud/Fable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

45 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“š Fable โ€“ E-book Sharing Platform

Project Overview


๐ŸŽฏ Project Summary

Fable is a full-stack e-book digital marketplace that connects readers, writers, and administrators. The platform enables writers to publish and monetize original e-books, allows readers to discover and purchase content, and provides administrators with comprehensive management and analytics tools. Built with modern web technologies, it emphasizes user experience, security, and scalability.

Live URL: https://fable-amber.vercel.app


๐Ÿ—๏ธ Architecture Overview

Tech Stack

Frontend (Client)

  • Framework: Next.js 16 (React 19) with App Router
  • Styling: Tailwind CSS 4 + PostCSS
  • UI Components: shadcn/ui (Base UI + Radix UI primitives)
  • Authentication: BetterAuth (Email/Password + Google OAuth)
  • Forms: React Hook Form
  • Animations: Framer Motion
  • Charts: Recharts
  • Payments: Stripe (Client SDK)
  • Icons: Lucide React + React Icons
  • Notifications: Sonner (Toast library)
  • Carousel: Swiper
  • Theme: next-themes (Dark mode support)

Backend (Server)

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB
  • Authentication: BetterAuth with MongoDB adapter
  • Payments: Stripe (Server SDK)
  • CORS: Enabled for cross-origin requests
  • Environment: Dotenv for configuration

Deployment

  • Client: Vercel
  • Server: Node.js server (custom deployment)
  • Database: MongoDB Atlas

๐Ÿ“Š Database Schema

Collections

1. users

  • User profiles (readers and writers)
  • Managed by BetterAuth
  • Fields: email, name, role (reader/writer), avatar, metadata

2. ebooks

  • E-book metadata and content
  • Fields: title, description, author (writer), cover image, price, genre, status, content, upload date, view count

3. soldbooks

  • Purchase transactions and sales history
  • Fields: book id, buyer id, seller id, price, purchase date, transaction status

4. bookmarks

  • User bookmarks/wishlist entries
  • Fields: user id, book id, created date

๐Ÿ—‚๏ธ Project Structure

fable/
โ”œโ”€โ”€ client/                          # Next.js Frontend Application
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ page.js                  # Home page
โ”‚   โ”‚   โ”œโ”€โ”€ layout.js                # Root layout
โ”‚   โ”‚   โ”œโ”€โ”€ globals.css              # Global styles
โ”‚   โ”‚   โ”œโ”€โ”€ api/                     # API routes (Auth, Checkout)
โ”‚   โ”‚   โ”œโ”€โ”€ all-books/               # Public ebook catalog
โ”‚   โ”‚   โ”œโ”€โ”€ authors/                 # Author profile pages
โ”‚   โ”‚   โ”œโ”€โ”€ login/                   # Login & authentication
โ”‚   โ”‚   โ”œโ”€โ”€ signup/                  # User registration
โ”‚   โ”‚   โ”œโ”€โ”€ dashboard/               # Role-based dashboards
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ admin/               # Admin overview & controls
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ reader/              # Reader dashboard
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ writer/              # Writer dashboard
โ”‚   โ”‚   โ””โ”€โ”€ unauthorized/            # Access denied page
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ pageContent/             # Full-page components
โ”‚   โ”‚   โ”œโ”€โ”€ tools/                   # Utility components
โ”‚   โ”‚   โ””โ”€โ”€ ui/                      # Reusable UI components (15+)
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js                  # BetterAuth configuration
โ”‚   โ”‚   โ”œโ”€โ”€ stripe.js                # Stripe integration
โ”‚   โ”‚   โ”œโ”€โ”€ actions/                 # Server actions
โ”‚   โ”‚   โ”œโ”€โ”€ api/                     # API integration layer
โ”‚   โ”‚   โ”œโ”€โ”€ core/                    # Core utilities
โ”‚   โ”‚   โ””โ”€โ”€ utils/                   # Helper utilities
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ public/                      # Static assets
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ next.config.mjs
โ”‚   โ”œโ”€โ”€ tailwind.config.js
โ”‚   โ””โ”€โ”€ README.md
โ”‚
โ””โ”€โ”€ server/                          # Express.js Backend
    โ”œโ”€โ”€ index.js                     # Main server file
    โ”œโ”€โ”€ package.json
    โ”œโ”€โ”€ vercel.json                  # Deployment config
    โ””โ”€โ”€ .env                         # Environment variables

๐Ÿ”„ Data Flow

Authentication Flow

User Registration/Login
  โ†’ BetterAuth (Email/Google)
  โ†’ JWT Session Token (7-day expiration)
  โ†’ Role Selection (Reader/Writer)
  โ†’ Dashboard Access

E-book Purchase Flow

Browse Catalog
  โ†’ View E-book Details
  โ†’ Click "Buy Now"
  โ†’ Stripe Checkout Session
  โ†’ Secure Payment Processing
  โ†’ Add to "Purchased" Collection
  โ†’ Content Unlock & Access

Writer Publishing Flow

Writer Dashboard
  โ†’ Click "Add New E-book"
  โ†’ Fill Complete Metadata (Title, Price, Genre, Cover, Description)
  โ†’ Upload Content
  โ†’ Publish/Draft Toggle
  โ†’ Appears in Catalog (if published)

๐Ÿ” API Endpoints

Backend API (Express Server)

Users

  • GET /api/users โ€“ Fetch all users (admin)
  • DELETE /api/users/:id โ€“ Remove a user account (admin)

E-books

  • GET /api/ebooks โ€“ Fetch all published e-books
  • GET /api/ebooks/:id โ€“ Get single e-book details
  • POST /api/ebooks โ€“ Create new e-book (authenticated writer)
  • PUT /api/ebooks/:id โ€“ Update e-book metadata (writer/admin)
  • DELETE /api/ebooks/:id โ€“ Delete e-book (writer/admin)

Sales & Transactions

  • GET /api/soldbooks โ€“ Fetch all sales (admin)
  • GET /api/soldbooks/writer/:id โ€“ Get writer's sales history
  • POST /api/soldbooks โ€“ Record new purchase

Bookmarks

  • GET /api/bookmarks/:userId โ€“ Get user's bookmarks
  • POST /api/bookmarks โ€“ Add bookmark
  • DELETE /api/bookmarks/:id โ€“ Remove bookmark

Frontend API Routes (Next.js)

  • POST /api/auth/[...all] โ€“ BetterAuth endpoints (login, signup, logout)
  • POST /api/checkout_sessions โ€“ Create Stripe checkout session

๐Ÿ›ก๏ธ Security Considerations

  1. Authentication: BetterAuth manages secure JWT session tokens with 7-day expiration
  2. Protected Routes: Role-based access control (Reader, Writer, Admin) with middleware guards
  3. CORS Configuration: Strict CORS policy on backend for safe cross-origin requests
  4. Payment Security: Stripe handles PCI compliance and secure payment processing
  5. Database Security: MongoDB connections secured with environment variables and authentication
  6. Session Persistence: No data loss on page reload; sessions stored securely
  7. Environment Management: All sensitive keys stored in .env and .env.local files (never committed to git)

๐Ÿ‘ฅ User Roles & Permissions

Feature Reader Writer Admin
Browse E-books โœ… โœ… โœ…
Purchase E-books โœ… โœ… โœ…
Create Bookmarks โœ… โœ… โœ…
Publish E-books โŒ โœ… โœ…
Manage Own E-books โŒ โœ… โœ…
Manage All E-books โŒ โŒ โœ…
Manage All Users โŒ โŒ โœ…
View Own Analytics โŒ โœ… โœ…
View Platform Analytics โŒ โŒ โœ…

๐Ÿ“ˆ Performance & Scalability

  • Pagination: Efficient server-side pagination for handling large datasets
  • Skeleton Loaders: Improves perceived performance during content loading
  • Image Optimization: Next.js Image component for responsive, optimized images
  • Code Splitting: Modular component architecture enabling automatic route-based code splitting
  • Caching Strategy: Leverages Next.js built-in caching and HTTP caching headers
  • Database Indexing: MongoDB collections indexed on frequently queried fields
  • CDN Delivery: Vercel's edge network for ultra-fast static asset delivery globally

๐Ÿ”ฎ Future Enhancement Opportunities

  • User Reviews & Ratings: Enable readers to review and rate purchased e-books
  • Search Optimization: Full-text search with Elasticsearch for advanced filtering
  • Social Features: Author follow system, community comments, and discussions
  • Content Features: Series/Collections, table of contents, highlights, annotations, reading progress tracking
  • Payment Features: Multiple payment gateways (PayPal, Apple Pay), subscription plans, promotional codes
  • Internationalization: Multi-language support and currency conversion
  • Content Management: WYSIWYG editor for e-book creation, DRM protection, version control
  • Mobile App: Native iOS/Android apps for better reading experience

About

Fable is a full-stack digital marketplace for e-books, connecting readers and writers in a secure environment. Built with Next.js 16, Express.js, and MongoDB, the platform features role-based dashboards for managing content, tracking sales, and purchasing books via Stripe integration.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages