mongog setup

This commit is contained in:
2026-03-04 12:23:13 +05:30
parent bed32863da
commit a9eaa7599c
32 changed files with 2577 additions and 670 deletions

View File

@@ -14,14 +14,14 @@ _This file contains critical rules and patterns that AI agents must follow when
## Technology stack & versions
| Layer | Technology | Notes |
|-----------|--------------------------|--------------------------------------------|
| Frontend | React 19, TypeScript | Vite 7 build |
| Routing | react-router-dom 7 | Routes: `/`, `/history`, `/settings`, `/login` |
| Auth | Firebase 12 | Google sign-in only |
| Styling | Plain CSS | `src/index.css` (globals), `src/App.css` (components) |
| Backend | _Planned_ Python/FastAPI | Modular: one file per page/function |
| Database | _Planned_ MongoDB | To be set up after responsive UI |
| Layer | Technology | Notes |
| -------- | -------------------- | ----------------------------------------------------- |
| Frontend | React 19, TypeScript | Vite 7 build; port 8000 |
| Routing | react-router-dom 7 | Routes: `/`, `/history`, `/settings`, `/login` |
| Auth | Firebase 12 | Google sign-in only (no database) |
| Styling | Plain CSS | `src/index.css` (globals), `src/App.css` (components) |
| Backend | FastAPI 0.104 | Python; port 8001; modular routes |
| Database | MongoDB 6.x | Local instance; collections: users, entries, settings |
---
@@ -38,8 +38,10 @@ _This file contains critical rules and patterns that AI agents must follow when
### Backend (when implemented)
- **Framework:** FastAPI. APIs in Python only.
- **Modularity:** Separate file per page and its functions. Each app page (write, history, settings, auth) has its own backend module; avoid one monolithic API file.
- **Database:** MongoDB. Setup comes after frontend responsive work.
- **Modularity:** Separate file per route. Each feature (users, entries) has its own router module.
- **Database:** MongoDB. Setup instructions below.
- **Port:** 8001 (backend); 8000 (frontend). CORS configured between them.
- **Authentication:** Relies on Firebase Google Auth token from frontend (passed in Authorization header).
### Conventions
@@ -52,16 +54,80 @@ _This file contains critical rules and patterns that AI agents must follow when
## File layout (reference)
```
src/
App.tsx, App.css # Root layout, routes, global page styles
index.css # Resets, :root vars, base typography
src/ # Frontend
App.tsx, App.css # Root layout, routes, global page styles
index.css # Resets, :root vars, base typography
main.tsx
pages/ # HomePage, HistoryPage, SettingsPage, LoginPage
components/ # BottomNav, LoginCard, GoogleSignInButton, ProtectedRoute
contexts/ # AuthContext (Firebase)
lib/ # firebase.ts, firestoreService.ts
pages/ # HomePage, HistoryPage, SettingsPage, LoginPage
components/ # BottomNav, LoginCard, GoogleSignInButton, ProtectedRoute
contexts/ # AuthContext (Firebase Google Auth)
lib/
firebase.ts # Firebase auth config (Firestore removed)
backend/ # FastAPI backend (Port 8001)
main.py # FastAPI app, CORS, routes, lifespan
config.py # Settings, environment variables
db.py # MongoDB connection manager
models.py # Pydantic models (User, JournalEntry, Settings)
requirements.txt # Python dependencies
.env.example # Environment variables template
routers/
users.py # User registration, update, delete endpoints
entries.py # Entry CRUD, date filtering endpoints
```
---
_Last updated from session context and codebase review._
_Last updated: 2026-03-04_
## Recent Changes & Status
### Port Configuration (Updated)
✅ Frontend port changed to **8000** (was 5173)
✅ Backend port remains **8001**
✅ CORS configuration updated in FastAPI
✅ Vite config updated with server port 8000
### Backend Setup (Completed)
✅ FastAPI backend initialized (port 8001)
✅ MongoDB connection configured (local instance)
✅ Pydantic models for User, JournalEntry, UserSettings
✅ Route structure: `/api/users/*` and `/api/entries/*`
✅ CORS enabled for frontend (localhost:8000)
✅ Firestore database files removed (`firestoreService.ts`, `firestoreConfig.ts`)
✅ Firebase authentication kept (Google sign-in only)
### API Ready
- User registration, profile updates, deletion
- Entry CRUD (create, read, update, delete)
- Entry filtering by date
- Pagination support
### Frontend-Backend Integration (Completed)
**API Service Layer** — Created `src/lib/api.ts` with all backend calls
**AuthContext Updated** — Now syncs users with MongoDB on login
- Auto-registers new users in MongoDB
- Fetches existing user profiles
- Provides `userId` (MongoDB ID) to all pages
**HomePage** — Entry creation via POST `/api/entries/{userId}`
- Save with success/error feedback
- Clears form after save
**HistoryPage** — Fetches entries via GET `/api/entries/{userId}`
- Calendar shows days with entries
- Lists recent entries with timestamps
- Filters by current month
**SettingsPage** — Updates user settings via PUT `/api/users/update/{userId}`
- Theme selector (light/dark) with MongoDB persistence
- Profile info from Firebase
### Next Steps (Implementation)
🔄 Add entry detail view / edit functionality
🔄 Firebase token verification in backend middleware
🔄 Search/filter entries by date range
🔄 Client-side encryption for entries