This document describes the reorganized project structure for better maintainability and separation of concerns.
docquery/
├── backend/ # FastAPI Backend
│ ├── app/ # Application code
│ │ ├── routers/ # API endpoints
│ │ ├── services/ # Business logic (search, cache, embeddings, etc.)
│ │ └── tasks/ # Celery background tasks
│ ├── scripts/ # Utility scripts (init_db, create_admin)
│ ├── tests/ # Backend tests
│ ├── uploads/ # User uploaded files and FAISS indexes
│ ├── requirements.txt # Python dependencies
│ ├── pytest.ini # Pytest configuration
│ ├── .env # Environment variables
│ └── Dockerfile # Backend Docker image
│
├── frontend/ # Next.js Frontend (Phase 6)
│ ├── app/ # Next.js 14 app directory
│ ├── components/ # React components
│ ├── lib/ # Utilities and API client
│ ├── hooks/ # Custom React hooks
│ ├── store/ # Zustand state management
│ ├── public/ # Static assets
│ └── package.json # Node dependencies
│
├── docs/ # Documentation
│ ├── backend/ # Backend-specific docs
│ │ ├── PHASE2_COMPLETE.md
│ │ ├── PHASE3_SEARCH.md
│ │ ├── PHASE4_RAG.md
│ │ ├── PHASE5_SETUP_GUIDE.md
│ │ └── ...
│ ├── frontend/ # Frontend-specific docs (Phase 6)
│ └── architecture/ # System architecture docs
│ └── ARCHITECTURE.md
│
├── docker-compose.yml # Multi-service Docker orchestration
├── Makefile # Development commands
├── README.md # Main project README
└── .gitignore # Git ignore rules
main.py- FastAPI application entry pointauth.py- JWT authentication logicmodels.py- SQLAlchemy database modelsschemas.py- Pydantic request/response schemasdatabase.py- Database connection and session managementconfig.py- Configuration and settingsredis_client.py- Redis connection and utilities
API endpoint definitions:
auth.py- Login, logout, user infodocuments.py- Document upload and managementquery.py- Search endpointsrag.py- RAG answer generation (streaming and non-streaming)cache.py- Cache management (admin only)
Business logic services:
search.py- Hybrid search (FAISS + PostgreSQL FTS)embedding.py- OpenAI embedding generationvector_index.py- FAISS vector index managementcache.py- Redis caching (queries, embeddings, token blacklist)rag_generator.py- RAG answer generationcitation_tracker.py- Citation extraction and mappingdocument_processor.py- Document parsing and chunking
celery_app.py- Celery configurationdocument_tasks.py- Background document processing
Next.js 14 app directory with file-based routing:
/login- Login page/dashboard- Main dashboard/documents- Document management/chat- Chat-style query interface/admin- Admin panel
Reusable React components:
ui/- shadcn/ui componentsauth/- Authentication componentsdocuments/- Document-related componentschat/- Chat interface componentslayout/- Layout components (navbar, sidebar, etc.)
Utilities and core functionality:
api.ts- Axios API client with interceptorsauth.ts- Authentication utilitiesutils.ts- Helper functions
Zustand state management:
authStore.ts- Authentication statedocumentStore.ts- Document statechatStore.ts- Chat state
- FastAPI - Modern Python web framework
- PostgreSQL - Relational database with full-text search
- Redis - Caching and token blacklist
- FAISS - Vector similarity search
- Celery - Background task processing
- OpenAI API - Embeddings and chat completion
- Next.js 14 - React framework with App Router
- TypeScript - Type-safe JavaScript
- TailwindCSS - Utility-first CSS
- shadcn/ui - Beautiful UI components
- Axios - HTTP client
- React Query - Data fetching and caching
- Zustand - State management
- Framer Motion - Animations
Backend:
cd backend
python -m venv venv
source venv/Scripts/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reloadFrontend:
cd frontend
npm install
npm run dev# Start all services
make up
# View logs
make logs
# Stop services
make down# Database
POSTGRES_USER=docquery_user
POSTGRES_PASSWORD=your_password
POSTGRES_DB=docquery
DATABASE_URL=postgresql://user:pass@localhost:5432/docquery
# Redis
REDIS_URL=redis://localhost:6379/0
# JWT
SECRET_KEY=your-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30
# OpenAI
OPENAI_API_KEY=your-openai-keyNEXT_PUBLIC_API_URL=http://localhost:8000- Backend changes: Edit files in
/backend/app/, tests auto-reload - Frontend changes: Edit files in
/frontend/, hot module replacement active - Database migrations: Use Alembic (future enhancement)
- API testing: Use
/docsfor Swagger UI,/redocfor ReDoc
# Backend tests
cd backend
pytest -v
# Frontend tests (after Phase 6)
cd frontend
npm test- Backend API: http://localhost:8000/docs
- Architecture: docs/architecture/ARCHITECTURE.md
- Phase Docs: docs/backend/
- Uploads: Stored in
/backend/uploads/with user-specific folders - FAISS Indexes: Stored per-user in
/backend/uploads/indexes/ - Caching: Redis caches queries (1h TTL) and embeddings (24h TTL)
- Authentication: JWT tokens with refresh token support
- ✅ Phase 1-5: Backend complete
- 🚧 Phase 6: Frontend (in progress)
- 📋 Phase 7: Deployment and monitoring