Fullstack web application for intelligent text analysis, rewriting, and chat powered by AI.
Backend: FastAPI + SQLAlchemy + SQLite/PostgreSQL
Frontend: React 18 + TypeScript + Zustand + Vite
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
Windows (PowerShell):
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
.\start.ps1Linux/Mac (Bash):
chmod +x start.sh
./start.shBackend:
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 8000Frontend (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- Frontend: http://localhost:5173
- Backend: http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Quick deployment in 3 steps:
# Windows
.\deploy.ps1
# Linux/Mac
chmod +x deploy.sh
./deploy.shThen 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
POST /auth/register- Register new accountPOST /auth/login- User loginGET /auth/me- Get current user infoPUT /auth/profile- Update profile settings
POST /texts/from-text- Upload plain textPOST /texts/from-url- Extract text from URLPOST /texts/from-file- Upload file (PDF, DOCX, TXT)GET /texts/- List all documentsGET /texts/{id}- Get document detailsDELETE /texts/{id}- Delete document
POST /analysis/analyze- Analyze document (reader/writer mode)GET /analysis/history- Get analysis history
POST /rewrite/- Rewrite paragraph with goalGET /rewrite/presets- Get available rewrite goalsGET /rewrite/history- Get rewrite history
POST /chat/- Ask question about documentGET /chat/sessions- List chat sessionsGET /chat/sessions/{id}- Get chat conversationDELETE /chat/sessions/{id}- Delete session
GET /history/all- Get all activitiesGET /history/analyses- Analysis historyGET /history/rewrites- Rewrite historyGET /history/chats- Chat historyGET /history/stats- User statistics
Total: 26+ API endpoints
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"}
}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]
}'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?"
}'Start with detailed logging:
cd backend
source venv/bin/activate
PYTHONUNBUFFERED=1 uvicorn main:app --reload --log-level debugTest backend directly:
# Open browser: http://localhost:8000/docs
# This opens Swagger UI to test all endpointsCheck database:
# List all tables (if using SQLite)
sqlite3 backend/llmagik.db ".tables"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_URLinfrontend/.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
See DEBUGGING_GUIDE.md for:
- Detailed troubleshooting steps
- API testing tools (Postman, curl, REST Client)
- Common issues & solutions
- Testing checklists
- Backend: http://localhost:8000/docs accessible
- Frontend: http://localhost:5173 loads
- No CORS errors in browser console
- Register new account
- Login with credentials
- View profile information
- Update user preferences
- Upload text document
- Upload from URL
- Upload file (PDF/TXT)
- View document list
- Delete document
- Analyze document (Reader mode)
- Analyze document (Writer mode)
- Chat with document AI
- Rewrite paragraph
- View activity history
Test all endpoints in Swagger UI: http://localhost:8000/docs
- README.md - This file
- DEBUGGING_GUIDE.md - Troubleshooting & testing
- PROJECT_SUMMARY.md - Complete project overview
- COMPLETION_CHECKLIST.md - Features & status
- backend/SETUP_GUIDE.md - Backend deployment
- backend/REVIEW_SUMMARY.md - Code review notes
- frontend/SETUP_GUIDE.md - Frontend deployment
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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:
- User action in React component
- Call Zustand store action
- Store calls API client
- API client sends HTTP request + JWT token
- Backend validates token
- Backend processes request
- Backend returns JSON response
- Store updates state
- React re-renders component
β
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)
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.)
- Setup & Run - Start both servers
- Test Application - Validate all features
- Configure AI - Set real AI provider
- Deploy to Production - Go live
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
-
PhαΊ‘m KhΓ΄i NguyΓͺn
https://github.com/thisIsAnVariableOfACoder -
Δinh Quang Minh
https://github.com/minhhdinh192 -
VΕ© Minh HoΓ ng
https://github.com/GetInHod