Next.js PWA for Pulih, a recovery support platform with psychologist consultation booking. It provides patient and psychologist screens for auth, onboarding, recovery tracking, education, community, AI coach, emergency support, profile, psychologist sessions, and consultation booking flows.
- Overview
- Platform Context
- Service Boundary
- Screens
- API Integration
- Tech Stack
- Getting Started
- Environment
- Scripts
- Testing
- Project Structure
- Demo Flow
- Deployment
- Security
- Contribution
Pulih Frontend renders mobile-first PWA experiences for patients and psychologists. It stores access tokens in browser storage, calls Pulih API REST endpoints, and keeps provider-specific work behind the backend.
Core capabilities:
- Patient login and registration.
- Psychologist login, registration, and onboarding.
- Patient onboarding and recovery goal setup.
- Daily check-in, relapse support, emergency guidance, and statistics.
- Education and help center surfaces.
- AI coach chat.
- Community post browsing, detail, and creation.
- Psychologist directory, consultation detail, and booking screens.
- Patient profile management.
- Psychologist home, profile, session, pricing, schedule, and chat screens.
- PWA manifest and install-friendly metadata.
| Component | Responsibility |
|---|---|
| Pulih Frontend | Patient/psychologist UI, browser navigation, client-side state |
| Pulih API | Auth, validation, workflows, persistence, integrations, REST contracts |
| Supabase Postgres | Durable relational data store, accessed only through Pulih API |
| Pakasir | Payment simulation/status, accessed only through Pulih API |
| Resend | Transactional emails, accessed only through Pulih API |
| SumoPod AI | AI coach responses, accessed only through Pulih API |
| Cloudflare R2 | Credential files, accessed only through Pulih API |
Frontend should call Pulih API only. It should not call DB, payment, email, AI, or storage providers directly.
Pulih Frontend owns:
- Page rendering and navigation.
- Form input collection and basic client-side validation.
- Browser session token storage.
- Mobile-first layout and PWA metadata.
- Calling Pulih API endpoints and showing API messages.
Pulih Frontend does not own:
- Auth verification, roles, or ownership rules.
- Payment provider verification.
- Email delivery.
- AI safety policy enforcement.
- Database access.
- Credential storage access.
- Admin UI/API for MVP.
| Area | Routes |
|---|---|
| Auth | /, /register, /login/psikolog, /register/psikolog |
| Patient | /home, /profile, /daily-checkin, /relapse, /stats, /education, /emergency |
| Onboarding | /onboarding/* |
| Help | /help, /help/coach, /help/community, /help/consultation |
| Consultation | /help/consultation/[id], /help/consultation/bookings |
| Community | /help/community, /help/community/[id], /help/community/create |
| Psychologist | /psikolog/home, /psikolog/profile, /psikolog/sessions, /psikolog/practice-schedule |
| Psychologist | /psikolog/setup-pricing, /psikolog/session-detail, /psikolog/chat |
| Legal | /privacy |
Default local API base URL:
http://localhost:3002
Default API prefix:
/api/v1
Expected response envelope:
{
"success": true,
"message": "Request processed successfully",
"data": {},
"meta": null
}Auth token storage key:
auth_token
| Area | Choice |
|---|---|
| Framework | Next.js 16 |
| Language | TypeScript |
| UI runtime | React 19 |
| Styling | Tailwind CSS 4 |
| Icons | Lucide React |
| PWA | Next PWA + manifest |
| Package manager | npm |
| Linting | ESLint 9 |
Install deps:
npm installCreate local env:
cp .env.example .env.localIf .env.example does not exist yet, create .env.local manually using variables from Environment.
Start dev server:
npm run devOpen app:
http://localhost:3000
Run Pulih API separately, usually on:
http://localhost:3002
Important files:
| File | Purpose |
|---|---|
.env.local |
Local frontend env, gitignored |
.env.example |
Safe template when available |
Variables:
| Variable | Purpose |
|---|---|
NEXT_PUBLIC_API_BASE_URL |
Pulih API base URL, for example http://localhost:3002 |
NEXT_PUBLIC_API_TOKEN |
Optional local fallback token for development only |
Example:
NEXT_PUBLIC_API_BASE_URL=http://localhost:3002
# NEXT_PUBLIC_API_TOKEN=Never commit real tokens or private credentials. NEXT_PUBLIC_* variables are exposed to browsers.
| Script | Purpose |
|---|---|
npm run dev |
Start Next dev server |
npm run build |
Build production app |
npm run start |
Start production server |
npm run lint |
Run ESLint |
Fast local verification:
npm run lint
npm run buildManual smoke checks:
- Login/register patient.
- Complete onboarding path.
- Open home, check-in, relapse, stats, education, emergency.
- Open AI coach and community screens.
- Browse consultation/psychologist screens.
- Login/register psychologist.
- Open psychologist home, profile, schedule, pricing, sessions, chat.
.
|-- app/ # Next App Router pages, layout, manifest, global CSS
| |-- help/ # Help, AI coach, community, consultation screens
| |-- onboarding/ # Patient onboarding flow
| |-- psikolog/ # Psychologist workspace screens
| `-- ...
|-- components/ # Shared UI components
|-- lib/ # Client-side stores/helpers
|-- public/ # Static assets and icons
|-- eslint.config.mjs
|-- next.config.ts
|-- package.json
|-- package-lock.json
|-- postcss.config.mjs
`-- tsconfig.json
UI conventions:
| Area | Convention |
|---|---|
| Layout | Mobile-first, centered max-width shell |
| Routes | App Router directories under app/ |
| Components | Shared reusable UI under components/ |
| Assets | Static images under public/assets/ |
| API calls | Browser fetch to Pulih API |
| Auth | Bearer token from localStorage.auth_token |
- Patient registers/logs in.
- Patient completes onboarding.
- Patient opens recovery home.
- Patient records check-in or relapse.
- Patient opens education, stats, emergency support, AI coach, or community.
- Patient browses consultation/psychologist screens.
- Patient creates or views bookings where available.
- Psychologist registers/logs in.
- Psychologist completes onboarding/profile flow.
- Psychologist manages schedule/pricing/sessions.
- Psychologist opens chat/session detail screens.
Build:
npm run buildStart production server:
npm run startDeployment expectations:
- Build from committed source and
package-lock.json. - Provide
NEXT_PUBLIC_API_BASE_URLthrough deployment env. - Keep staging/prod API URLs separate.
- Do not expose private API keys through
NEXT_PUBLIC_*variables. - Confirm PWA manifest assets exist under
public/assets/.
Pulih handles sensitive mental-health and consultation data.
Rules:
- Never commit
.env.local, real tokens, API keys, or private credentials. - Treat
NEXT_PUBLIC_*values as public browser-visible config. - Do not log passwords, tokens, raw journals, relapse triggers, sensitive AI prompts, credential content, or meet links.
- Do not call DB, payment, email, AI, or storage providers directly from frontend.
- Preserve backend auth/ownership checks; frontend checks are UX only.
- Keep patient and psychologist flows separated by role-aware navigation.
- Use HTTPS in deployed environments.
Before changing behavior:
- Read relevant Pulih API docs/contracts for touched flow.
- Inspect existing route/component patterns.
- Keep changes small and scoped.
- Preserve English user-facing API error messages from backend where shown.
- Add/update docs when env vars, setup, routes, or workflows change.
- Avoid unrelated formatting or cleanup.
Before handoff:
npm run lint
npm run buildRun narrower checks for small changes, but document skipped verification.