scientific-backend / QUICK_START.py
Dama12's picture
Initial clean backend deployment
0bd4ab4
Raw
History Blame
9.04 kB
#!/usr/bin/env python3
"""
Quick Start Guide - Step-by-step instructions
"""
QUICK_START = """
╔══════════════════════════════════════════════════════════════════════════════╗
β•‘ AI Scientific Co-Investigator - QUICK START β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
πŸš€ OPTION 1: Docker Compose (Recommended - 5 minutes)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Prerequisites:
βœ“ Install Docker: https://www.docker.com/products/docker-desktop
βœ“ Install Docker Compose (included with Docker Desktop)
2. Setup:
$ cp .env.example .env
$ # Edit .env - add your API keys
3. Start services:
$ chmod +x deploy.sh
$ ./deploy.sh up
βœ“ API: http://localhost:8000
βœ“ Docs: http://localhost:8000/docs
βœ“ Qdrant: http://localhost:6333
βœ“ PostgreSQL: localhost:5432
4. Verify health:
$ curl http://localhost:8000/health/ready
β†’ Should return: {"ready": true, ...}
5. Stop:
$ ./deploy.sh down
πŸ› οΈ OPTION 2: Local Python Development
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Prerequisites:
βœ“ Python 3.10+
βœ“ PostgreSQL 13+
βœ“ Redis
βœ“ Qdrant
2. Setup environment:
$ python -m venv .venv
$ source .venv/bin/activate # or .venv\\Scripts\\activate on Windows
3. Install dependencies:
$ pip install -r requirements.txt
4. Configure:
$ cp .env.example .env
$ # Edit .env with your local DB credentials
5. Start services (in separate terminals):
Terminal 1 - PostgreSQL:
$ psql -U user -d scoinvestigator
Terminal 2 - Redis:
$ redis-server
Terminal 3 - Qdrant:
$ docker run -p 6333:6333 qdrant/qdrant
Terminal 4 - API:
$ uvicorn app.main:app --reload
β†’ http://localhost:8000
πŸ“š COMMON OPERATIONS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Health Check:
$ curl http://localhost:8000/health/ready
View API Docs:
β†’ Open browser: http://localhost:8000/docs
View Logs:
$ ./deploy.sh logs
Run Tests:
$ ./deploy.sh test
Database: psql connection
$ psql -U user -d scoinvestigator -h localhost
Stop Everything:
$ ./deploy.sh down
πŸš€ FIRST API CALL
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Run an analysis:
$ curl -X POST http://localhost:8000/api/v1/analysis/run \\
-H "Content-Type: application/json" \\
-d '{
"documents": ["Document text here..."],
"analysis_type": "comprehensive"
}'
View results:
$ curl http://localhost:8000/api/v1/analysis/{analysis_id}/results
πŸ“Š DATABASE SETUP
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Create database (first time):
$ psql -U postgres
postgres=# CREATE DATABASE scoinvestigator;
postgres=# CREATE USER user WITH PASSWORD 'onion123';
postgres=# GRANT ALL PRIVILEGES ON DATABASE scoinvestigator TO user;
Tables are created automatically by SQLAlchemy on first run.
πŸ” TROUBLESHOOTING
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Problem: Import errors
Solution: pip install --upgrade -r requirements.txt
Problem: Database connection failed
Solution: Check DATABASE_URL in .env
Check PostgreSQL is running
psql -U user -d scoinvestigator
Problem: Qdrant not responding
Solution: docker run -p 6333:6333 qdrant/qdrant
curl http://localhost:6333/health
Problem: Ports already in use
Solution: Check what's using the port:
lsof -i :8000 # for API
lsof -i :5432 # for DB
Kill the process: kill -9 <PID>
Or change ports in docker-compose.yml
πŸ“– STRUCTURE OVERVIEW
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
/app
/api β†’ API routes
/db β†’ Database models & sessions
/services β†’ Business logic
/reasoning β†’ AI orchestration (LangGraph)
/rag β†’ Document processing
/modules β†’ Analysis modules
/core β†’ Configuration & utilities
main.py β†’ FastAPI app
🎯 NEXT STEPS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Verify all services running:
$ curl http://localhost:8000/health/ready
2. Try the API with sample data:
β†’ Visit http://localhost:8000/docs
β†’ Try POST /api/v1/analysis/run
3. Check logs for errors:
$ ./deploy.sh logs
4. Monitor resources:
$ docker stats
5. Setup frontend (separate project):
β†’ See FRONTEND_SCAFFOLD.md
πŸ“ž NEED HELP?
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Read the docs:
- README.md (project overview)
- DEPLOYMENT.md (deployment guide)
- STACK_ANALYSIS.md (tech stack details)
- FRONTEND_SCAFFOLD.md (frontend setup)
2. Check logs:
- Docker: docker-compose logs
- API: ./deploy.sh logs
- Database: psql logs
3. API Docs:
- Swagger: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
4. Health checks:
- All services: http://localhost:8000/health/ready
- API only: http://localhost:8000/health/
πŸ‘¨β€πŸ’» DEVELOPMENT WORKFLOW
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Edit code β†’ Changes auto-reload (with --reload flag)
Run tests β†’ ./deploy.sh test
View logs β†’ ./deploy.sh logs
Debug β†’ Add print statements β†’ Check logs
🎊 YOU'RE ALL SET!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Next: Start making requests to the API!
Happy coding! πŸš€
"""
if __name__ == "__main__":
print(QUICK_START)
# Additional interactive help
import sys
print(\"\\n\" + \"=\"*80)
print(\"INTERACTIVE QUICK START\")
print(\"=\"*80)
choice = input(\"\\nHow do you want to run the app?\\n1. Docker Compose (recommended)\\n2. Local Python\\n> \").strip()
if choice == '1':
print(\"\\n\" + \"=\"*80)
print(\"DOCKER COMPOSE SETUP\")
print(\"=\"*80)
print(\"\\nSteps:\")
print(\"1. cp .env.example .env\")
print(\"2. Edit .env with your API keys\")
print(\"3. chmod +x deploy.sh\")
print(\"4. ./deploy.sh up\")
print(\"\\nThen visit: http://localhost:8000/docs\")
elif choice == '2':
print(\"\\n\" + \"=\"*80)
print(\"LOCAL PYTHON SETUP\")
print(\"=\"*80)
print(\"\\nSteps:\")
print(\"1. python -m venv .venv\")
print(\"2. source .venv/bin/activate\")
print(\"3. pip install -r requirements.txt\")
print(\"4. Start PostgreSQL, Redis, Qdrant\")
print(\"5. uvicorn app.main:app --reload\")
print(\"\\nThen visit: http://localhost:8000/docs\")
print(\"\\n\" + \"=\"*80)
print(\"Questions? Check: README.md | DEPLOYMENT.md | STACK_ANALYSIS.md\")
print(\"=\"*80 + \"\\n\")