Skip to content

bos-com/Bugema-E-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

E-Bugema - Full-Stack Digital Library Management System

A modern, feature-rich e-library management system built with Django REST Framework and React, featuring cloud-based file storage with Cloudinary, PostgreSQL database on NEON, and a beautiful, responsive UI with advanced reading capabilities.

✨ Features

πŸ“š Core Features

  • Digital Book Management: Upload, categorize, and manage books in PDF format
  • Online Reading: Read books directly in the browser with progress tracking
  • Cloud Storage: Secure file storage and delivery via Cloudinary CDN
  • JWT Authentication: Secure token-based authentication with automatic refresh
  • Advanced Search: Full-text search with filtering and sorting
  • Personal Library: Like, bookmark, and track reading progress
  • Analytics Dashboard: Comprehensive analytics for users and administrators

πŸ‘₯ User Features

  • Reading Progress Tracking: Automatic tracking of reading progress with page location and completion percentage
  • Personal Dashboard: View reading history, in-progress books, completed books, and statistics
  • Book Interaction: Like, bookmark, and organize favorite books
  • Reading Statistics: Track reading time, pages read, and reading goals
  • Responsive Reader: Optimized PDF reader with zoom and navigation controls

πŸ”§ Admin Features

  • Book Management: Full CRUD operations for books and categories
  • User Management: View and manage user accounts with role-based access
  • Rich Analytics:
    • Most read books and trending content
    • User activity and engagement metrics
    • Popular categories and search terms
    • Peak usage time analysis with interactive charts
  • Content Moderation: Control book visibility and manage content

πŸ”’ Technical Features

  • Security: JWT token rotation, role-based permissions, secure file streaming
  • Cloud Infrastructure: Cloudinary for file storage, NEON PostgreSQL database
  • Real-time Updates: Optimistic UI updates with TanStack Query
  • Modern UI: Beautiful, accessible design with dark mode support
  • Performance: Optimized with caching (Redis), pagination, and lazy loading

πŸ›  Tech Stack

Backend

  • Framework: Django 4.2.7 + Django REST Framework 3.14.0
  • Database: PostgreSQL (NEON Cloud Database)
  • File Storage: Cloudinary (Cloud-based media storage and CDN)
  • Authentication: JWT with djangorestframework-simplejwt 5.3.0
  • Caching: Redis 5.0.1
  • API Documentation: drf-spectacular (OpenAPI/Swagger)
  • Rate Limiting: django-ratelimit
  • Web Server: Gunicorn with WhiteNoise for static files
  • Additional Libraries:
    • django-cors-headers - CORS handling
    • django-filter - Advanced filtering
    • psycopg[binary] - PostgreSQL adapter
    • python-dotenv - Environment variable management
    • Pillow - Image processing

Frontend

  • Framework: React 18.3.1 with TypeScript 5.5.4
  • Build Tool: Vite 5.4.0 (Fast, modern build tool)
  • Routing: React Router v6.26.2
  • Styling: TailwindCSS 3.4.10 with custom design system
  • State Management: Zustand 4.5.5 (Lightweight state management)
  • Data Fetching: TanStack Query (React Query) 5.40.0
  • HTTP Client: Axios 1.7.3
  • Form Handling: React Hook Form 7.51.3 with Zod validation
  • Charts: Recharts 2.10.4 (for analytics visualization)
  • Notifications: react-hot-toast 2.4.1
  • Icons: Lucide React 0.469.0
  • Utilities:
    • clsx - Conditional className utility
    • date-fns - Date formatting and manipulation

Infrastructure & DevOps

  • Deployment: Vercel (Frontend), Render/Railway (Backend)
  • Database Hosting: NEON (Serverless PostgreSQL)
  • File Storage: Cloudinary (Cloud-based CDN)
  • Caching: Redis (for rate limiting and session management)
  • Version Control: Git

πŸ“ Project Structure

E-bugema/
β”‚
β”œβ”€β”€ backend/                          # Django REST API
β”‚   β”œβ”€β”€ elibrary/                     # Django project configuration  
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ settings.py               # Settings (DB, Cloudinary, JWT, CORS)
β”‚   β”‚   β”œβ”€β”€ urls.py                   # Main URL configuration
β”‚   β”‚   β”œβ”€β”€ wsgi.py                   # WSGI configuration
β”‚   β”‚   └── asgi.py                   # ASGI configuration
β”‚   β”‚
β”‚   β”œβ”€β”€ accounts/                     # User authentication & management
β”‚   β”‚   β”œβ”€β”€ models.py                 # Custom User model
β”‚   β”‚   β”œβ”€β”€ serializers.py            # User/auth serializers
β”‚   β”‚   β”œβ”€β”€ views.py                  # Auth endpoints (login, register, etc.)
β”‚   β”‚   β”œβ”€β”€ urls.py                   # Auth routes
β”‚   β”‚   └── permissions.py            # Custom permissions
β”‚   β”‚
β”‚   β”œβ”€β”€ catalog/                      # Books and categories management
β”‚   β”‚   β”œβ”€β”€ models.py                 # Book, Category, Author models
β”‚   β”‚   β”œβ”€β”€ serializers.py            # Catalog serializers
β”‚   β”‚   β”œβ”€β”€ views.py                  # Book CRUD, search, filtering
β”‚   β”‚   β”œβ”€β”€ urls.py                   # Catalog routes
β”‚   β”‚   └── utils.py                  # Helper functions
β”‚   β”‚
β”‚   β”œβ”€β”€ reading/                      # Reading progress tracking
β”‚   β”‚   β”œβ”€β”€ models.py                 # ReadingProgress model
β”‚   β”‚   β”œβ”€β”€ serializers.py            # Progress serializers
β”‚   β”‚   β”œβ”€β”€ views.py                  # Progress tracking endpoints
β”‚   β”‚   β”œβ”€β”€ urls.py                   # Reading routes
β”‚   β”‚   └── utils.py                  # Progress calculation utilities
β”‚   β”‚
β”‚   β”œβ”€β”€ analytics/                    # Analytics and event tracking
β”‚   β”‚   β”œβ”€β”€ models.py                 # AnalyticsEvent model
β”‚   β”‚   β”œβ”€β”€ serializers.py            # Analytics serializers
β”‚   β”‚   β”œβ”€β”€ views.py                  # Analytics endpoints
β”‚   β”‚   β”œβ”€β”€ urls.py                   # Analytics routes
β”‚   β”‚   └── middleware.py             # Request tracking middleware
β”‚   β”‚
β”‚   β”œβ”€β”€ manage.py                     # Django management script
β”‚   β”œβ”€β”€ requirements.txt              # Python dependencies
β”‚   β”œβ”€β”€ runtime.txt                   # Python version specification
β”‚   β”œβ”€β”€ build.sh                      # Build script for deployment
β”‚   β”œβ”€β”€ seed.py                       # Database seeding script
β”‚   └── env.example.txt               # Environment variables template
β”‚
β”œβ”€β”€ frontend/                         # React Frontend Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                      # Application pages and layouts
β”‚   β”‚   β”‚   β”œβ”€β”€ layouts/              # Layout components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ MainLayout.tsx    # Main user layout
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AdminLayout.tsx   # Admin dashboard layout
β”‚   β”‚   β”‚   β”‚   └── AuthLayout.tsx    # Authentication pages layout
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   └── pages/                # Page components
β”‚   β”‚   β”‚       β”œβ”€β”€ HomePage.tsx      # Landing/home page
β”‚   β”‚   β”‚       β”œβ”€β”€ LoginPage.tsx     # User login
β”‚   β”‚   β”‚       β”œβ”€β”€ RegisterPage.tsx  # User registration
β”‚   β”‚   β”‚       β”œβ”€β”€ CatalogPage.tsx   # Book catalog with search
β”‚   β”‚   β”‚       β”œβ”€β”€ BookDetailPage.tsx# Individual book details
β”‚   β”‚   β”‚       β”œβ”€β”€ ReaderPage.tsx    # PDF reader
β”‚   β”‚   β”‚       β”œβ”€β”€ DashboardPage.tsx # User dashboard
β”‚   β”‚   β”‚       β”œβ”€β”€ ProfilePage.tsx   # User profile
β”‚   β”‚   β”‚       └── admin/            # Admin pages
β”‚   β”‚   β”‚           β”œβ”€β”€ AdminOverviewPage.tsx  # Analytics overview
β”‚   β”‚   β”‚           β”œβ”€β”€ AdminBooksPage.tsx     # Book management
β”‚   β”‚   β”‚           β”œβ”€β”€ AdminUsersPage.tsx     # User management
β”‚   β”‚   β”‚           └── AdminCategoriesPage.tsx# Category management
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ components/               # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ cards/                # Card components
β”‚   β”‚   β”‚   β”‚   └── StatCard.tsx      # Statistics card with icons
β”‚   β”‚   β”‚   β”œβ”€β”€ catalog/              # Catalog-specific components
β”‚   β”‚   β”‚   β”‚   └── BookCard.tsx      # Book card display
β”‚   β”‚   β”‚   β”œβ”€β”€ feedback/             # User feedback components
β”‚   β”‚   β”‚   β”‚   └── LoadingOverlay.tsx# Loading indicator
β”‚   β”‚   β”‚   β”œβ”€β”€ forms/                # Form components
β”‚   β”‚   β”‚   β”œβ”€β”€ HamburgerMenu.tsx     # Mobile navigation menu
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileDropdown.tsx   # User profile dropdown
β”‚   β”‚   β”‚   β”œβ”€β”€ ThemeToggle.tsx       # Dark/light mode toggle
β”‚   β”‚   β”‚   └── ProtectedRoute.tsx    # Route protection wrapper
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ lib/                      # Core utilities and configurations
β”‚   β”‚   β”‚   β”œβ”€β”€ api/                  # API client modules
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ client.ts         # Axios client with interceptors
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth.ts           # Authentication API calls
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ catalog.ts        # Catalog API calls
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ reading.ts        # Reading progress API
β”‚   β”‚   β”‚   β”‚   └── analytics.ts      # Analytics API calls
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   β”œβ”€β”€ store/                # Zustand state stores
β”‚   β”‚   β”‚   β”‚   └── auth.ts           # Authentication state
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   └── types/                # TypeScript type definitions
β”‚   β”‚   β”‚       └── index.ts          # Shared type definitions
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ hooks/                    # Custom React hooks
β”‚   β”‚   β”‚   └── useAutoRefreshToken.ts# Auto token refresh hook
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ routes/                   # Routing configuration
β”‚   β”‚   β”‚   └── AppRoutes.tsx         # Main app routes
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ styles/                   # Global styles
β”‚   β”‚   β”‚   └── globals.css           # Tailwind + custom styles
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ App.tsx                   # Root App component
β”‚   β”‚   └── main.tsx                  # Application entry point
β”‚   β”‚
β”‚   β”œβ”€β”€ public/                       # Static assets
β”‚   β”œβ”€β”€ index.html                    # HTML entry point
β”‚   β”œβ”€β”€ package.json                  # Node dependencies
β”‚   β”œβ”€β”€ tsconfig.json                 # TypeScript configuration
β”‚   β”œβ”€β”€ tailwind.config.js            # Tailwind CSS configuration
β”‚   β”œβ”€β”€ vite.config.ts                # Vite build configuration
β”‚   β”œβ”€β”€ postcss.config.js             # PostCSS configuration
β”‚   └── .env.example                  # Frontend environment variables template
β”‚
β”œβ”€β”€ .git/                             # Git repository
β”œβ”€β”€ README.md                         # This file
β”œβ”€β”€ render.yaml                       # Render deployment configuration
└── setup.sh                          # Setup script

πŸš€ Quick Start

Prerequisites

  • Python 3.11 or higher
  • Node.js 18+ and npm
  • PostgreSQL database (or NEON account)
  • Cloudinary account
  • Redis (optional, for caching)

Backend Setup

  1. Clone the repository

    git clone <your-repository-url>
    cd E-bugema/backend
  2. Create and activate virtual environment

    python -m venv .venv
    
    # On Windows
    .venv\Scripts\activate
    
    # On Linux/Mac
    source .venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    Create a .env file in the backend/ directory:

    SECRET_KEY=your-secret-key-here
    DEBUG=True
    
    # Database (NEON PostgreSQL)
    DATABASE_URL=postgresql://username:password@host/database?sslmode=require
    
    # Cloudinary Configuration
    CLOUDINARY_CLOUD_NAME=your-cloud-name
    CLOUDINARY_API_KEY=your-api-key
    CLOUDINARY_API_SECRET=your-api-secret
    
    # JWT Configuration
    JWT_ACCESS_TOKEN_LIFETIME=900
    JWT_REFRESH_TOKEN_LIFETIME=604800
    
    # CORS Configuration
    CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:5174,http://localhost:3000
    
    # Redis (optional)
    REDIS_URL=redis://127.0.0.1:6379/1
  5. Run migrations

    python manage.py migrate
  6. Create a superuser

    python manage.py createsuperuser
  7. Seed the database (optional)

    python seed.py
  8. Run the development server

    python manage.py runserver

    Backend API will be available at: http://localhost:8000/api Admin panel: http://localhost:8000/admin API documentation: http://localhost:8000/api/docs

Frontend Setup

  1. Navigate to frontend directory

    cd frontend
  2. Install dependencies

    npm install
  3. Set up environment variables

    Create a .env file in the frontend/ directory:

    VITE_API_URL=http://localhost:8000/api
  4. Start the development server

    npm run dev

    Frontend will be available at: http://localhost:5173

πŸ“š API Documentation

The API documentation is automatically generated and available at /api/docs when running the backend server.

Main API Endpoints

Authentication

  • POST /api/auth/register/ - User registration
  • POST /api/auth/login/ - User login (returns access & refresh tokens)
  • POST /api/auth/token/refresh/ - Refresh access token
  • GET /api/auth/me/ - Get current user profile
  • PATCH /api/auth/me/ - Update user profile
  • POST /api/auth/logout/ - User logout

Catalog

  • GET /api/catalog/categories/ - List all categories
  • GET /api/catalog/books/ - List books (supports search, filtering, pagination)
  • GET /api/catalog/books/{id}/ - Get book details
  • GET /api/catalog/books/{id}/cover/ - Get book cover image
  • GET /api/catalog/books/{id}/read/stream/ - Stream book file (secure)
  • POST /api/catalog/books/{id}/like/ - Toggle book like
  • POST /api/catalog/books/{id}/bookmark/ - Toggle book bookmark

Admin (Requires Admin Role)

  • POST /api/catalog/books/ - Create a new book
  • PATCH /api/catalog/books/{id}/ - Update book details
  • DELETE /api/catalog/books/{id}/ - Delete a book
  • GET /api/admin/users/ - List all users
  • POST /api/catalog/categories/ - Create category
  • PATCH /api/catalog/categories/{id}/ - Update category

Reading Progress

  • GET /api/reading/progress/{book_id}/ - Get reading progress for a book
  • PATCH /api/reading/progress/{book_id}/ - Update reading progress
  • GET /api/reading/dashboard/ - Get user's dashboard data

Analytics

  • GET /api/analytics/admin/overview/ - Admin analytics overview (charts, stats)
  • GET /api/analytics/user/stats/ - User reading statistics

πŸ”§ Configuration

Cloudinary Setup

  1. Create a Cloudinary account at cloudinary.com
  2. Get your Cloud Name, API Key, and API Secret from the dashboard
  3. Add credentials to your .env file
  4. Files will be automatically uploaded to Cloudinary when books are created

NEON PostgreSQL Setup

  1. Create a NEON account at neon.tech
  2. Create a new project and database
  3. Copy the connection string
  4. Add to DATABASE_URL in your .env file

Redis Setup (Optional but Recommended)

Redis is used for caching and rate limiting:

# Using Docker
docker run -d -p 6379:6379 redis:latest

# Or install locally
# Windows: Download from https://redis.io/download
# Mac: brew install redis
# Linux: sudo apt-get install redis-server

🎨 Design System

The frontend features a modern, premium design system:

  • Color Palette: Vibrant blues, emeralds, violets, ambers, and roses
  • Background: Soft gray (slate-50) for reduced eye strain
  • Typography: Inter font family with responsive scaling
  • Components: Glassmorphism effects, gradient buttons, smooth animations
  • Dark Mode: Full dark mode support with optimized colors
  • Accessibility: WCAG AA compliant, keyboard navigation

πŸš€ Deployment

Backend Deployment (Render/Railway)

  1. Push code to GitHub
  2. Connect to Render/Railway
  3. Set environment variables:
    • All variables from .env template
    • Set DEBUG=False
    • Set proper CORS_ALLOWED_ORIGINS
  4. Deploy: Platform will automatically run build.sh

Frontend Deployment (Vercel)

  1. Push code to GitHub
  2. Import project to Vercel
  3. Configure:
    • Framework: Vite
    • Build Command: npm run build
    • Output Directory: dist
    • Install Command: npm install
  4. Set environment variable: VITE_API_URL=<your-backend-url>/api
  5. Deploy

πŸ”’ Security Features

  • JWT Authentication: Secure token-based auth with automatic rotation
  • Role-Based Access Control: Separate admin and user permissions
  • Secure File Streaming: Cloudinary signed URLs with expiration
  • Rate Limiting: Protection against API abuse
  • CORS Protection: Configured allowed origins
  • Input Validation: Comprehensive validation on all endpoints
  • SQL Injection Protection: Django ORM prevents SQL injection
  • XSS Protection: React automatically escapes output

πŸ§ͺ Testing

Backend Tests

cd backend
python -m pytest

Frontend Tests

cd frontend
npm run test

🀝 Contributing

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

πŸ“ License

This project is licensed under the MIT License.

🎯 Roadmap

  • Advanced reading features (annotations, highlights, bookmarks with notes)
  • Social features (reviews, ratings, book discussions)
  • Reading challenges and achievement badges
  • Personalized AI-powered book recommendations
  • Offline reading support (PWA)
  • Mobile app (React Native)
  • Advanced analytics and export features
  • Multi-language support
  • EPUB reading support
  • Audio book support

πŸ†˜ Support

For questions and support:


Built with ❀️ using Django, React, PostgreSQL, and Cloudinary

About

E-library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •