# 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 key - `telegram_id` - Unique Telegram user ID (indexed) - `token` - Unique auth token (indexed) - `username` - Telegram username - `status` - Auth status ('pending' or 'success') - `created_at` - Timestamp - `updated_at` - Timestamp ### Profiles Table - `id` - Auto-increment primary key - `email` - Unique email (indexed) - `name`, `position`, `competencies`, `experience`, `skills` - `country`, `languages`, `employment_format`, `rate`, `relocation` - `cv_url` - Link to uploaded CV in MinIO - `created_at` - Timestamp - `updated_at` - Timestamp ## Setup Instructions ### 1. Prerequisites - Python 3.10+ - PostgreSQL 14+ - Docker (for MinIO) ### 2. Install Dependencies ```bash # 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: ```env # 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 ```bash # Start PostgreSQL and MinIO using Docker docker-compose up -d # Verify services are running docker ps ``` ### 5. Initialize Database ```bash # 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** ```bash python bot.py ``` **Option B: Run separately** ```bash # 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 URL - `GET /check-auth/{token}` - Check authentication status - `GET /database/tokens` - List all tokens (debug) ### Profiles - `POST /profile` - Create/update profile with CV upload - `GET /profile/{email}` - Get profile by email - `GET /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 ``` 3. **Monitoring** - Add logging - Set up error tracking (Sentry) - Monitor database performance ## License MIT