A FastAPI-based backend service that provides AI-enhanced journaling capabilities with semantic search, summarization, and interactive chat features.
- FastAPI - High-performance Python backend
- Google Gemini LLM - AI-driven journal insights
- Qdrant + SentenceTransformers - Vector search for context retrieval
- Versioning + Testing - Scalable API
- 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
- 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
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
Create a .env file with:
QDRANT_URL=http://localhost:6333
FIREBASE_CREDENTIALS_BASE64=<base64_encoded_firebase_credentials>
GEMINI_API_KEY=<your_gemini_api_key>
- Clone the repository
git clone https://github.com/Badar25/Journal-backend- Install dependencies
pip install -r requirements.txt- Start Qdrant (using Docker)
docker run -p 6333:6333 qdrant/qdrant- Run the application
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000All endpoints require Firebase authentication token in the header:
Authorization: Bearer <firebase_token>
- POST
/v1/journals/ - Body:
{
"title": "string",
"content": "string"
}- PUT
/v1/journals/{journal_id} - Body:
{
"title": "string (optional)",
"content": "string (optional)"
}- GET
/v1/journals/ - Query Params:
days(optional, int)
- GET
/v1/journals/summary - Query Params:
days(optional, int, default=7)
- GET
/v1/journals/search - Query Params:
query(required),limit(optional, default=3)
- Title: Max 200 characters
- Content: Max 999 words
- At least one field (title or content) must be provided
| 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 |
All API responses follow this structure:
{
"success": boolean,
"message": string,
"data": object | null,
"error": string | null
}Run tests using pytest:
pytest tests -v