https://github.com/badar25/journal-backend
AI Journal is a stateless API that brings your journal entries to life! Powered by FastAPI, Googleβs Gemini LLM, and Qdrant, it delivers context-aware insights through Retrieval-Augmented Generation (RAG).
https://github.com/badar25/journal-backend
fastapi qdrant rag
Last synced: about 2 months ago
JSON representation
AI Journal is a stateless API that brings your journal entries to life! Powered by FastAPI, Googleβs Gemini LLM, and Qdrant, it delivers context-aware insights through Retrieval-Augmented Generation (RAG).
- Host: GitHub
- URL: https://github.com/badar25/journal-backend
- Owner: Badar25
- Created: 2025-02-27T06:33:47.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-03T14:07:47.000Z (over 1 year ago)
- Last Synced: 2025-03-09T09:34:29.739Z (over 1 year ago)
- Topics: fastapi, qdrant, rag
- Language: Python
- Homepage:
- Size: 173 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Journal AI Backend
A FastAPI-based backend service that provides AI-enhanced journaling capabilities with semantic search, summarization, and interactive chat features.
## β‘ Tech Stack
- FastAPI - High-performance Python backend
- Google Gemini LLM - AI-driven journal insights
- Qdrant + SentenceTransformers - Vector search for context retrieval
- Versioning + Testing - Scalable API
## π Features
- Journal entry creation and management
- Semantic search using Qdrant vector database
- AI-powered journal summarization using Google's Gemini Pro
- Interactive chat with your journal entries
- Firebase authentication
- Structured error handling and logging
- API versioning
## π Tech Stack
- **Framework:** FastAPI
- **Authentication:** Firebase Admin SDK
- **Vector Database:** Qdrant
- **AI Models:**
- Google Gemini 1.5 Pro (for chat and summarization)
- Sentence Transformer (all-MiniLM-L6-v2 for embeddings)
- **Logging:** Custom colored logging with rotation
- **Validation:** Pydantic
## π Project Structure
```plaintext
src/
βββ api/
β βββ v1/
β βββ endpoints/
β β βββ journals.py
β βββ router.py
βββ core/
β βββ config.py
β βββ firebase.py
β βββ logger.py
β βββ prompt_templates.py
βββ models/
β βββ journal.py
β βββ response.py
βββ services/
β βββ gemini_service.py
β βββ qdrant_service.py
βββ utils/
β βββ journal_validator.py
βββ main.py
```
## βοΈ Environment Variables
Create a `.env` file with:
```plaintext
QDRANT_URL=http://localhost:6333
FIREBASE_CREDENTIALS_BASE64=
GEMINI_API_KEY=
```
## π Getting Started
1. Clone the repository
```bash
git clone https://github.com/Badar25/Journal-backend
```
2. Install dependencies
```bash
pip install -r requirements.txt
```
3. Start Qdrant (using Docker)
```bash
docker run -p 6333:6333 qdrant/qdrant
```
4. Run the application
```bash
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000
```
## π API Endpoints
### Authentication
All endpoints require Firebase authentication token in the header:
```
Authorization: Bearer
```
### Journals
#### Create Journal
- **POST** `/v1/journals/`
- **Body:**
```json
{
"title": "string",
"content": "string"
}
```
#### Update Journal
- **PUT** `/v1/journals/{journal_id}`
- **Body:**
```json
{
"title": "string (optional)",
"content": "string (optional)"
}
```
#### Get Journals
- **GET** `/v1/journals/`
- **Query Params:** `days` (optional, int)
#### Get Summary
- **GET** `/v1/journals/summary`
- **Query Params:** `days` (optional, int, default=7)
#### Search Journals
- **GET** `/v1/journals/search`
- **Query Params:** `query` (required), `limit` (optional, default=3)
## π Validation Rules
### Journal Content
- Title: Max 200 characters
- Content: Max 999 words
- At least one field (title or content) must be provided
## β οΈ Error Codes
| Code | Description |
|------|-------------|
| TOKEN_EXPIRED | Authentication token has expired |
| TOKEN_REVOKED | Authentication token has been revoked |
| TOKEN_INVALID | Invalid authentication token |
| AUTH_ERROR | General authentication failure |
| EMPTY_FIELDS | Required fields are empty |
| TITLE_TOO_LONG | Title exceeds 200 characters |
| CONTENT_TOO_LONG | Content exceeds 999 words |
| MISSING_FIELDS | Required fields are missing |
| JOURNAL_NOT_FOUND | Requested journal doesn't exist |
| UNAUTHORIZED | Not authorized to access the journal |
| GEMINI_ERROR | AI processing error |
| SEARCH_ERROR | Vector search failed |
| INITIALIZATION_ERROR | Service initialization failed |
## π Response Format
All API responses follow this structure:
```json
{
"success": boolean,
"message": string,
"data": object | null,
"error": string | null
}
```
## π§ͺ Testing
Run tests using pytest:
```bash
pytest tests -v
```