Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Dependencies
node_modules/
*/node_modules/

# Production builds
dist/
build/
.next/

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
*.log

# Python
__pycache__/
*.py[cod]
*$py.class
*.pyc
*.pyo
*.pyd
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
venv/
env/
ENV/
env.bak/
venv.bak/

# Database files
*.db
*.sqlite3
*.sqlite

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
94 changes: 92 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,92 @@
# ai-book-reader
AI assisted book reader
# AI Book Reader

An AI-assisted book reader application with note-taking and bookmarking capabilities.

## Project Structure

```
ai-book-reader/
├── frontend/ # Next.js 15 React application
├── backend/ # FastAPI Python application
└── README.md
```

## Setup Instructions

### Prerequisites

- Node.js 18+ and npm
- Python 3.8+
- pip

### Frontend Setup (Next.js 15)

1. Navigate to the frontend directory:
```bash
cd frontend
```

2. Install dependencies:
```bash
npm install
```

3. Start the development server:
```bash
npm run dev
```

The frontend will be available at `http://localhost:3000`

### Backend Setup (FastAPI + SQLite)

1. Navigate to the backend directory:
```bash
cd backend
```

2. Create a virtual environment:
```bash
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```

3. Install dependencies:
```bash
pip install -r requirements.txt
```

4. Start the development server:
```bash
python run.py
```

The backend API will be available at `http://localhost:8000`
- API documentation: `http://localhost:8000/docs`
- Alternative docs: `http://localhost:8000/redoc`

## API Endpoints

### Notes
- `GET /api/notes/` - Get all notes
- `GET /api/notes/{note_id}` - Get specific note
- `POST /api/notes/` - Create new note
- `PUT /api/notes/{note_id}` - Update note
- `DELETE /api/notes/{note_id}` - Delete note

### Bookmarks
- `GET /api/bookmarks/` - Get all bookmarks
- `GET /api/bookmarks/{bookmark_id}` - Get specific bookmark
- `POST /api/bookmarks/` - Create new bookmark
- `PUT /api/bookmarks/{bookmark_id}` - Update bookmark
- `DELETE /api/bookmarks/{bookmark_id}` - Delete bookmark

## Database

The application uses SQLite for data persistence. The database file (`ai_book_reader.db`) will be created automatically when you first run the backend server.

## Development

- Frontend uses Next.js 15 with TypeScript and Tailwind CSS
- Backend uses FastAPI with SQLAlchemy ORM
- CORS is configured to allow frontend-backend communication
111 changes: 111 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# SQLite database files
*.db
*.sqlite3
*.sqlite
1 change: 1 addition & 0 deletions backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty file to make app a Python package
1 change: 1 addition & 0 deletions backend/app/database/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty file to make database a Python package
32 changes: 32 additions & 0 deletions backend/app/database/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sqlite3
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import os

# Database configuration
DATABASE_URL = "sqlite:///./ai_book_reader.db"

# Create SQLAlchemy engine
engine = create_engine(
DATABASE_URL,
connect_args={"check_same_thread": False} # Needed for SQLite
)

# Create session maker
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

# Create base class for ORM models
Base = declarative_base()

# Dependency to get DB session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()

# Create all tables
def create_tables():
Base.metadata.create_all(bind=engine)
39 changes: 39 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

# Import models to ensure they are registered with SQLAlchemy
from app.models import note, bookmark
from app.database.database import create_tables
from app.routers import notes, bookmarks

app = FastAPI(
title="AI Book Reader API",
description="Backend API for AI-assisted book reader application",
version="1.0.0"
)

# Configure CORS for frontend communication
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:3000"], # Next.js default port
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

# Create database tables on startup
@app.on_event("startup")

Copilot AI Oct 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @app.on_event("startup") decorator is deprecated in FastAPI. Use @app.lifespan context manager instead for better resource management and compatibility with newer FastAPI versions.

Copilot uses AI. Check for mistakes.
async def startup_event():
create_tables()

# Include routers
app.include_router(notes.router, prefix="/api/notes", tags=["notes"])
app.include_router(bookmarks.router, prefix="/api/bookmarks", tags=["bookmarks"])

@app.get("/")
async def read_root():
return {"message": "AI Book Reader API", "version": "1.0.0"}

@app.get("/health")
async def health_check():
return {"status": "healthy"}
1 change: 1 addition & 0 deletions backend/app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty file to make models a Python package
15 changes: 15 additions & 0 deletions backend/app/models/bookmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from sqlalchemy import Column, Integer, String, Text, DateTime
from sqlalchemy.sql import func
from app.database.database import Base

class Bookmark(Base):
__tablename__ = "bookmarks"

id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False)
book_title = Column(String(255), nullable=False)
page_number = Column(Integer, nullable=False)
chapter = Column(String(255), nullable=True)
description = Column(Text, nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
15 changes: 15 additions & 0 deletions backend/app/models/note.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from sqlalchemy import Column, Integer, String, Text, DateTime
from sqlalchemy.sql import func
from app.database.database import Base

class Note(Base):
__tablename__ = "notes"

id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False)
content = Column(Text, nullable=False)
book_title = Column(String(255), nullable=True)
page_number = Column(Integer, nullable=True)
chapter = Column(String(255), nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
Loading