Skip to content

Commit 1f2d3dc

Browse files
authored
Merge pull request #173 from mongodb-developer/interactive_journal
Adds code for an interactive journalizing app
2 parents 5d2d372 + f12017c commit 1f2d3dc

30 files changed

+5765
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Environment files
2+
.env
3+
.env.local
4+
.env.*.local
5+
6+
# Python
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
*.so
11+
.Python
12+
venv/
13+
.venv/
14+
env/
15+
.eggs/
16+
*.egg-info/
17+
.pytest_cache/
18+
19+
# Node.js
20+
node_modules/
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# Build outputs
26+
dist/
27+
build/
28+
*.local
29+
30+
# IDE
31+
.idea/
32+
.vscode/
33+
*.swp
34+
*.swo
35+
36+
# OS
37+
.DS_Store
38+
Thumbs.db
39+
40+
# Logs
41+
*.log
42+
logs/

apps/interactive-journal/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Setup
2+
3+
### Backend
4+
5+
```bash
6+
cd backend
7+
8+
# Create virtual environment
9+
python -m venv venv
10+
source venv/bin/activate
11+
12+
# Install dependencies
13+
pip install -r requirements.txt
14+
15+
# Create .env file
16+
cp .env.example .env
17+
# Edit .env with your values:
18+
# MONGODB_URI=your-mongodb-connection-string
19+
# ANTHROPIC_API_KEY=your-anthropic-api-key
20+
# VOYAGE_API_KEY=your-voyage-api-key
21+
22+
# Run the server
23+
uvicorn app.main:app --reload
24+
```
25+
26+
Backend runs at http://localhost:8000
27+
28+
### Frontend
29+
30+
```bash
31+
cd frontend
32+
33+
# Install dependencies
34+
npm install
35+
36+
# Run the dev server
37+
npm run dev
38+
```
39+
40+
Frontend runs at http://localhost:5173
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# MongoDB Atlas connection string
2+
MONGODB_URI=your-mongodb-connection-string-here
3+
4+
# Database name
5+
DATABASE_NAME=memoir
6+
7+
# Anthropic API key
8+
ANTHROPIC_API_KEY=your-anthropic-api-key-here
9+
10+
# Anthropic model to use
11+
ANTHROPIC_MODEL=claude-sonnet-4-5
12+
13+
# Voyage AI API key (for V2 semantic search)
14+
VOYAGE_API_KEY=your-voyage-api-key-here
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Memoir - Interactive Journaling App
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
3+
# User config
4+
USER_ID = "Apoorva"
5+
6+
# MongoDB config
7+
MONGODB_URI = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
8+
DATABASE_NAME = os.getenv("DATABASE_NAME", "memoir")
9+
10+
# Anthropic config
11+
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
12+
ANTHROPIC_MODEL = os.getenv("ANTHROPIC_MODEL", "claude-sonnet-4-5")
13+
14+
# Voyage AI config
15+
VOYAGE_API_KEY = os.getenv("VOYAGE_API_KEY")
16+
VOYAGE_MULTIMODAL_MODEL = "voyage-multimodal-3.5"
17+
VOYAGE_TEXT_MODEL = "voyage-3-large"
18+
19+
# Vector search config
20+
VECTOR_INDEX_NAME = "vector_index"
21+
VECTOR_DIMENSIONS = 1024
22+
VECTOR_NUM_CANDIDATES = 100
23+
24+
# Image config
25+
IMAGE_SIZE = (1024, 1024)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from dotenv import load_dotenv
2+
3+
load_dotenv(override=True)
4+
5+
import logging
6+
from contextlib import asynccontextmanager
7+
8+
from fastapi import FastAPI
9+
from fastapi.middleware.cors import CORSMiddleware
10+
11+
from app.routers import routes
12+
from app.services.mongodb import close_db, connect_db
13+
14+
logging.basicConfig(
15+
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
16+
)
17+
logger = logging.getLogger(__name__)
18+
19+
20+
@asynccontextmanager
21+
async def lifespan(app: FastAPI):
22+
# Startup
23+
logger.info("Starting Memoir API...")
24+
connect_db()
25+
logger.info("Memoir API started successfully")
26+
yield
27+
# Shutdown
28+
logger.info("Shutting down Memoir API...")
29+
close_db()
30+
31+
32+
app = FastAPI(
33+
title="Memoir",
34+
description="AI-powered interactive journaling application",
35+
version="1.0.0",
36+
lifespan=lifespan,
37+
)
38+
39+
# CORS middleware for frontend
40+
app.add_middleware(
41+
CORSMiddleware,
42+
allow_origins=["http://localhost:5173"], # Vite default port
43+
allow_credentials=True,
44+
allow_methods=["*"],
45+
allow_headers=["*"],
46+
)
47+
48+
# Include routers
49+
app.include_router(routes.router, prefix="/api/entries", tags=["entries"])
50+
51+
52+
@app.get("/")
53+
def root():
54+
return {"message": "Welcome to Memoir API"}
55+
56+
57+
@app.get("/health")
58+
def health_check():
59+
return {"status": "healthy"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Routers module

0 commit comments

Comments
 (0)