-
Notifications
You must be signed in to change notification settings - Fork 0
App Scaffolding: Complete React/Next.js 15 frontend and FastAPI backend with SQLite #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Empty file to make app a Python package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Empty file to make database a Python package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| 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"} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Empty file to make models a Python package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.lifespancontext manager instead for better resource management and compatibility with newer FastAPI versions.