3.8 KiB
3.8 KiB
RAG AI Assistant
A FastAPI application with Telegram bot integration for user authentication and profile management.
Features
- User Authentication via Telegram Bot
- Profile Management with CV upload to MinIO
- PostgreSQL Database with async SQLAlchemy ORM
- RESTful API endpoints for profiles and vacancies
Architecture
- Backend: FastAPI (Python)
- Database: PostgreSQL with async support (asyncpg)
- File Storage: MinIO (S3-compatible)
- Bot: Telegram Bot (aiogram 3.x)
- ORM: SQLAlchemy with async sessions
Database Schema
Users Table
id- Auto-increment primary keytelegram_id- Unique Telegram user ID (indexed)token- Unique auth token (indexed)username- Telegram usernamestatus- Auth status ('pending' or 'success')created_at- Timestampupdated_at- Timestamp
Profiles Table
id- Auto-increment primary keyemail- Unique email (indexed)name,position,competencies,experience,skillscountry,languages,employment_format,rate,relocationcv_url- Link to uploaded CV in MinIOcreated_at- Timestampupdated_at- Timestamp
Setup Instructions
1. Prerequisites
- Python 3.10+
- PostgreSQL 14+
- Docker (for MinIO)
2. Install Dependencies
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
3. Configure Environment
Copy and configure your .env file:
# Bot Configuration
BOT_API_KEY=your_telegram_bot_token
HOST=localhost
PORT=8000
# PostgreSQL Configuration
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=rag_ai_assistant
POSTGRES_PORT=5432
POSTGRES_HOST=localhost
# MinIO Configuration
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=minioadmin
MINIO_ENDPOINT=localhost:9000
MINIO_PORT=9000
MINIO_CONSOLE_PORT=9001
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_BUCKET=resumes
4. Start Services
# Start PostgreSQL and MinIO using Docker
docker-compose up -d
# Verify services are running
docker ps
5. Initialize Database
# Run database initialization script
python init_db.py
# Or manually create tables
python -c "from database.database import init_db; import asyncio; asyncio.run(init_db())"
6. Run Application
Option A: Run bot and API together
python bot.py
Option B: Run separately
# Terminal 1 - API
uvicorn app:app --reload --host localhost --port 8000
# Terminal 2 - Bot
python -c "from bot import start_bot; import asyncio; asyncio.run(start_bot())"
API Endpoints
Authentication
GET /login- Generate auth token and Telegram bot URLGET /check-auth/{token}- Check authentication statusGET /database/tokens- List all tokens (debug)
Profiles
POST /profile- Create/update profile with CV uploadGET /profile/{email}- Get profile by emailGET /profile/cv/{file_id}- Download CV file
Vacancies
GET /vacancies- List all vacancies
Development
Project Structure
.
├── app.py # FastAPI application
├── bot.py # Telegram bot
├── config.py # Configuration
├── init_db.py # Database initialization script
├── requirements.txt # Python dependencies
├── .env # Environment variables
├── database/
│ ├── database.py # Database models and session management
│ └── minio-processor.py # MinIO utilities
├── tests/ # Test files
└── docker-compose.yml # Docker services
- Monitoring
- Add logging
- Set up error tracking (Sentry)
- Monitor database performance
License
MIT