Skip to content

steamgiathieu/LLMagik_Project_v1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

53 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ InfoLens AI - AI Text Analysis Application

Fullstack web application for intelligent text analysis, rewriting, and chat powered by AI.

Backend: FastAPI + SQLAlchemy + SQLite/PostgreSQL
Frontend: React 18 + TypeScript + Zustand + Vite

πŸ“ Project Structure

InfoLens AI/
β”œβ”€β”€ backend/                    # FastAPI backend
β”‚   β”œβ”€β”€ main.py                # App entry point, CORS, router registration  
β”‚   β”œβ”€β”€ database.py            # SQLAlchemy engine, session, Base
β”‚   β”œβ”€β”€ auth.py                # JWT utils, password hashing, get_current_user
β”‚   β”œβ”€β”€ models.py              # User, UserProfile models
β”‚   β”œβ”€β”€ models_text.py         # Document, Paragraph models
β”‚   β”œβ”€β”€ models_analysis.py     # Analysis result model
β”‚   β”œβ”€β”€ models_rewrite.py      # Rewrite result model
β”‚   β”œβ”€β”€ models_chat.py         # ChatSession, ChatMessage models
β”‚   β”œβ”€β”€ schemas_*.py           # Pydantic request/response schemas (4 files)
β”‚   β”œβ”€β”€ routers/               # API routers
β”‚   β”‚   β”œβ”€β”€ auth_router.py     # /auth/* (register, login, profile)
β”‚   β”‚   β”œβ”€β”€ texts_router.py    # /texts/* (upload, list, get, delete)
β”‚   β”‚   β”œβ”€β”€ analysis_router.py # /analysis/* (analyze, history)
β”‚   β”‚   β”œβ”€β”€ rewrite_router.py  # /rewrite/* (rewrite, presets, history)
β”‚   β”‚   β”œβ”€β”€ chat_router.py     # /chat/* (chat, sessions, history)
β”‚   β”‚   └── history_router.py  # /history/* (all activities, stats)
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ ai_service.py      # AI provider abstraction (Mock/OpenAI/Anthropic)
β”‚   β”‚   └── text_processor.py  # Text utilities
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ .env
β”‚   └── test_imports.py
β”‚
β”œβ”€β”€ frontend/                   # React + Vite frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx            # Main app component
β”‚   β”‚   β”œβ”€β”€ main.tsx           # React entry point
β”‚   β”‚   β”œβ”€β”€ index.tsx          # HTML entry point
β”‚   β”‚   β”œβ”€β”€ pages/             # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Home.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Reader.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Profile.tsx
β”‚   β”‚   β”‚   └── History.tsx
β”‚   β”‚   β”œβ”€β”€ components/        # Reusable components
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ UploadModal.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ AnalysisPanel.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatBox.tsx
β”‚   β”‚   β”‚   └── RewritePanel.tsx
β”‚   β”‚   β”œβ”€β”€ store/             # Zustand stores
β”‚   β”‚   β”‚   β”œβ”€β”€ authStore.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ documentStore.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ analysisStore.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ chatStore.ts
β”‚   β”‚   β”‚   └── historyStore.ts
β”‚   β”‚   β”œβ”€β”€ hooks/             # Custom hooks
β”‚   β”‚   β”‚   β”œβ”€β”€ useApi.ts
β”‚   β”‚   β”‚   └── usePagination.ts
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── client.ts      # Centralized API client
β”‚   β”‚   β”œβ”€β”€ types/
β”‚   β”‚   β”‚   └── index.ts       # TypeScript type definitions
β”‚   β”‚   └── *.css              # Page/component styles
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”œβ”€β”€ vite.config.ts
β”‚   β”œβ”€β”€ .env
β”‚   └── public/
β”‚
β”œβ”€β”€ start.sh                   # Bash startup script (Linux/Mac)
β”œβ”€β”€ start.ps1                  # PowerShell startup script (Windows)
β”œβ”€β”€ README.md                  # This file
β”œβ”€β”€ PROJECT_SUMMARY.md         # Complete project overview
β”œβ”€β”€ COMPLETION_CHECKLIST.md    # Feature checklist
β”œβ”€β”€ backend/SETUP_GUIDE.md     # Backend setup guide
β”œβ”€β”€ backend/REVIEW_SUMMARY.md  # Code review notes
└── frontend/SETUP_GUIDE.md    # Frontend setup guide

πŸš€ Quick Start

Option 1: Automated (Recommended)

Windows (PowerShell):

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
.\start.ps1

Linux/Mac (Bash):

chmod +x start.sh
./start.sh

Option 2: Manual Setup

Backend:

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate              # Linux/Mac
# or
venv\Scripts\activate                 # Windows

# Install dependencies  
pip install -r requirements.txt

# Generate SECRET_KEY
python -c "import secrets; print(secrets.token_urlsafe(32))"

# Configure .env (single source of truth)
# Edit backend/.env and paste the generated SECRET_KEY

# Run backend
uvicorn main:app --reload --port 8000

Frontend (in new terminal):

cd frontend

# Install dependencies
npm install

# Configure .env (single source of truth)
# VITE_API_URL should be http://localhost:8000

# Run dev server
npm run dev

πŸ“ Access Points


οΏ½ Deploy to Production (GitHub Pages + Render)

Quick deployment in 3 steps:

# Windows
.\deploy.ps1

# Linux/Mac
chmod +x deploy.sh
./deploy.sh

Then follow DEPLOYMENT_GUIDE.md for:

  • βœ… Frontend β†’ GitHub Pages (free)
  • βœ… Backend β†’ Render (free tier available)
  • βœ… Custom domain setup (optional)

Result:

  • Frontend: https://YOUR-USERNAME.github.io/LLMagik
  • Backend: https://your-backend.onrender.com

οΏ½πŸ“‘ API Endpoints Overview

Authentication (6 endpoints)

  • POST /auth/register - Register new account
  • POST /auth/login - User login
  • GET /auth/me - Get current user info
  • PUT /auth/profile - Update profile settings

Document Management (6 endpoints)

  • POST /texts/from-text - Upload plain text
  • POST /texts/from-url - Extract text from URL
  • POST /texts/from-file - Upload file (PDF, DOCX, TXT)
  • GET /texts/ - List all documents
  • GET /texts/{id} - Get document details
  • DELETE /texts/{id} - Delete document

Analysis (2 endpoints)

  • POST /analysis/analyze - Analyze document (reader/writer mode)
  • GET /analysis/history - Get analysis history

Rewriting (3 endpoints)

  • POST /rewrite/ - Rewrite paragraph with goal
  • GET /rewrite/presets - Get available rewrite goals
  • GET /rewrite/history - Get rewrite history

Chat (4 endpoints)

  • POST /chat/ - Ask question about document
  • GET /chat/sessions - List chat sessions
  • GET /chat/sessions/{id} - Get chat conversation
  • DELETE /chat/sessions/{id} - Delete session

History (5 endpoints)

  • GET /history/all - Get all activities
  • GET /history/analyses - Analysis history
  • GET /history/rewrites - Rewrite history
  • GET /history/chats - Chat history
  • GET /history/stats - User statistics

Total: 26+ API endpoints


πŸ”— API Usage Examples

Example 1: Register & Login

Register:

curl -X POST http://localhost:8000/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "john",
    "email": "john@example.com",
    "password": "secret123",
    "nickname": "John Doe"
  }'

Login:

curl -X POST http://localhost:8000/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username": "john", "password": "secret123"}'

Response (save access_token for next requests):

{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "bearer",
  "user": {"id": 1, "username": "john", "email": "john@example.com"}
}

Example 2: Upload Document & Analyze

Upload text:

TOKEN="your_access_token"
curl -X POST http://localhost:8000/texts/from-text \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My Article",
    "content": "Your text here..."
  }'

Analyze document (Reader mode):

curl -X POST http://localhost:8000/analysis/analyze \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "document_id": 1,
    "mode": "reader",
    "paragraphs": [0, 1, 2]
  }'

Example 3: Ask Question to Document

curl -X POST http://localhost:8000/chat/ \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "document_id": 1,
    "question": "What is the main topic?"
  }'

πŸ› Debugging & Logging

Backend Debugging

Start with detailed logging:

cd backend
source venv/bin/activate
PYTHONUNBUFFERED=1 uvicorn main:app --reload --log-level debug

Test backend directly:

# Open browser: http://localhost:8000/docs
# This opens Swagger UI to test all endpoints

Check database:

# List all tables (if using SQLite)
sqlite3 backend/llmagik.db ".tables"

Frontend Debugging

Browser DevTools (F12):

  • Console: Fetch errors, TypeScript issues
  • Network: Check API requests/responses
  • Application: localStorage for auth token and state
  • React DevTools: Inspect component state

Common Frontend Issues:

  • CORS error β†’ Check VITE_API_URL in frontend/.env
  • 401 error β†’ Token expired, logout and login again
  • Cannot find module β†’ rm -rf node_modules && npm install
  • Port in use β†’ npm run dev -- --port 5174

Full Debugging Guide

See DEBUGGING_GUIDE.md for:

  • Detailed troubleshooting steps
  • API testing tools (Postman, curl, REST Client)
  • Common issues & solutions
  • Testing checklists

βœ… Testing Checklist

Phase 1: Server Status (5 mins)

Phase 2: Authentication (10 mins)

  • Register new account
  • Login with credentials
  • View profile information
  • Update user preferences

Phase 3: Documents (10 mins)

  • Upload text document
  • Upload from URL
  • Upload file (PDF/TXT)
  • View document list
  • Delete document

Phase 4: AI Features (15 mins)

  • Analyze document (Reader mode)
  • Analyze document (Writer mode)
  • Chat with document AI
  • Rewrite paragraph
  • View activity history

Phase 5: API Endpoints (10 mins)

Test all endpoints in Swagger UI: http://localhost:8000/docs


πŸ“š Documentation Files


πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       React Frontend                         β”‚
β”‚  (Pages, Components, Zustand Stores, TypeScript)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚ HTTP/JSON
                       ↕ Bearer Token Auth
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     FastAPI Backend                          β”‚
β”‚  (Routers, Models, Services, Database)                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚ SQL Queries
                       ↕ 
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SQLite Database                           β”‚
β”‚  (Users, Documents, Analysis, Chat, History)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Frontend β†’ Backend Communication:

  1. User action in React component
  2. Call Zustand store action
  3. Store calls API client
  4. API client sends HTTP request + JWT token
  5. Backend validates token
  6. Backend processes request
  7. Backend returns JSON response
  8. Store updates state
  9. React re-renders component

πŸ” Security Features

βœ… Password hashing with bcrypt
βœ… JWT token authentication
βœ… CORS protection (origin validation)
βœ… Input validation with Pydantic
βœ… SQL injection prevention (SQLAlchemy ORM)
βœ… Automatic token expiration
βœ… User-scoped data access (can't access other users' data)


πŸ“Š Technology Stack

Frontend:

  • React 18.3 + TypeScript 5.4
  • Vite 5.1 (next-gen build tool)
  • Zustand 4.5 (lightweight state management)
  • React Router v6 (client routing)
  • CSS Modules (component styling)

Backend:

  • FastAPI 0.100+ (async web framework)
  • Python 3.9+
  • SQLAlchemy 2.0+ (ORM)
  • SQLite (dev) / PostgreSQL (production)
  • python-jose (JWT tokens)
  • bcrypt (password hashing)
  • Pydantic (data validation)

Deployment:

  • Frontend: Netlify, Vercel, or AWS S3 + CloudFront
  • Backend: Heroku, AWS EC2, DigitalOcean, or Docker
  • Database: PostgreSQL (managed by Neon, Render, etc.)

🎯 Next Steps

  1. Setup & Run - Start both servers
  2. Test Application - Validate all features
  3. Configure AI - Set real AI provider
  4. Deploy to Production - Go live

πŸ“„ License & Credits

This is an educational/portfolio project demonstrating:

  • Full-stack web development (Frontend + Backend)
  • TypeScript + Python best practices
  • AI integration patterns
  • Database design
  • API design
  • State management
  • Authentication & Security

Status: βœ… Ready for Development & Testing
Last Updated: February 21, 2025

For detailed guidance, see DEBUGGING_GUIDE.md

πŸ‘₯ Team LLMagik

Releases

No releases published

Packages

 
 
 

Contributors