This is a modern Next.js rewrite of the original Pink Diary app. It supports Node 18/20/22 and uses MongoDB via Mongoose.
- Sign up, log in (JWT cookie)
- Home calendar showing logged period days and simple predictions
- Log symptoms: flow, mood, pain, sex
- Help requests (basic stub)
- Copy env and install dependencies:
Copy-Item .env.example .env.local
# Edit .env.local to set MONGODB_URI, JWT_SECRET, GEMINI_API_KEY (optional)
npm install
npm run devDev server runs at http://127.0.0.1:3500
| Name | Purpose |
|---|---|
MONGODB_URI |
Connection string for MongoDB database |
JWT_SECRET |
Secret used to sign JWT auth cookie |
GEMINI_API_KEY |
(Optional) Key for AI advice/chat; if omitted, fallbacks show static tips |
Provide these in .env.local for local dev or as host/container environment variables in production.
npm run build
npm run startnext start serves the optimized build on port 3500 as configured in package.json.
Build and run the included Dockerfile:
docker build -t pink-diary:prod ./New_version
docker run -d -p 3500:3500 --name pink-diary ^
-e MONGODB_URI="mongodb://host.docker.internal:27017/pink-diary-next" ^
-e JWT_SECRET="replace_me" ^
-e GEMINI_API_KEY="optional_key" ^
pink-diary:prodOn Linux/macOS replace PowerShell line continuation ^ with \.
- Push repository to GitHub.
- In Vercel dashboard: New Project → Import → Select
New_versiondirectory as root. - Add Environment Variables (Production & Preview):
MONGODB_URI,JWT_SECRET, optionalGEMINI_API_KEY. - Deploy. Vercel will run
npm installthennext buildautomatically.
You can create an ecosystem.config.js like:
module.exports = {
apps: [{
name: 'pink-diary',
script: 'npm',
args: 'run start',
env: { PORT: 3500 }
}]
};Then run:
pm2 start ecosystem.config.js
pm2 save- Mongo connectivity errors: ensure
MONGODB_URIis reachable from host/container. - JWT issues: confirm
JWT_SECRETidentical across all running instances. - AI endpoints returning 404: supply
GEMINI_API_KEY; otherwise static fallback advice is used.
app/– Next.js App Router pages & API routesmodels/– Mongoose schemaslib/db.js– Lazy Mongo connection (pool size 10)Dockerfile– Multi-stage build producing minimal runtime image
- JWT cookie is httpOnly; ensure
NODE_ENV=productionso Next sets secure flags when served over HTTPS. - Never commit real secrets; keep only
.env.examplein version control.
- Use MongoDB Atlas for managed DB (set
MONGODB_URI). - Add an index on
Entrycollection if query volume grows (e.g.,{ userId: 1, date: 1 }). - Consider enabling image optimization domains in
next.config.jsif external avatars are added.
| Symptom | Likely Cause | Fix |
|---|---|---|
| App boots but API 401 | Missing JWT cookie | Log in; check JWT_SECRET consistency |
| Build fails on Mongo var | MONGODB_URI absent |
Set in environment before build/start |
| AI endpoints 500/404 | Missing/invalid Gemini key | Set GEMINI_API_KEY or rely on fallback |
| Container can’t reach DB | Network bridge / host mapping | Use host.docker.internal (Mac/Win) or link container |
Minimum for production: set env vars, npm run build, run npm run start (or use Docker image). For a managed platform, point root to New_version and configure environment variables.
- API routes live under
app/api/*(App Router) - Mongo connection is cached for hot reload
- Auth uses httpOnly JWT cookie
token - Styling uses Tailwind CSS; utility classes are available out of the box
- Fallback AI logic activates automatically when
GEMINI_API_KEYmissing