diff --git a/AGENTS.md b/AGENTS.md index 8bd0e39..45e1436 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,5 +1,31 @@ + # This is NOT the Next.js you know +# 📄 Documentation Files + +## AGENTS.md + +Berisi: + +- struktur project +- aturan coding +- best practices + +## CLAUDE.md + +Berisi: + +- instruksi untuk AI assistant +- cara generate code +- constraint development + +## Rules + +- Semua developer wajib mengikuti AGENTS.md +- AI harus membaca AGENTS.md sebelum generate code +- Jangan duplikasi aturan di banyak file + This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` before writing any code. Heed deprecation notices. + diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..4fa0b10 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,281 @@ +# 🚀 SeTrip Project Architecture Guide + +## 📌 Overview + +Dokumen ini menjelaskan standar struktur project untuk aplikasi **SeTrip** menggunakan Next.js (App Router). + +Tujuan: + +- Menjaga code tetap rapi & scalable +- Menghindari spaghetti code +- Memudahkan AI / developer kontribusi + +--- + +# 🧠 Core Principles + +1. **Feature-based structure (WAJIB)** +2. **Separation client vs server logic** +3. **Colocation (file dekat dengan fitur)** +4. **No over-engineering (keep it simple)** + +--- + +# 🏗️ Project Structure + +```bash +src/ +├── app/ # Next.js App Router (UI & routing) +│ ├── (public)/ # halaman publik +│ ├── (auth)/ # login/register +│ ├── trips/ # halaman trip +│ ├── create-trip/ +│ └── profile/ +│ +├── features/ # 🔥 Business logic per domain +│ ├── auth/ +│ ├── user/ +│ ├── trip/ +│ ├── booking/ +│ └── review/ +│ +├── server/ # 🔒 Backend-only logic +│ ├── db/ +│ ├── services/ +│ └── repositories/ +│ +├── components/ # reusable UI components +│ ├── ui/ +│ └── shared/ +│ +├── lib/ # helpers & utilities +│ ├── prisma.ts +│ ├── auth.ts +│ └── utils.ts +│ +├── hooks/ # custom react hooks +├── types/ # global types +└── config/ # config (env, constants) +``` + +--- + +# 📂 Folder Rules + +## 1. `/app` (Routing Layer) + +Hanya untuk: + +- page.tsx +- layout.tsx +- UI rendering +- data fetching ringan + +❌ DILARANG: + +- business logic +- query database langsung + +--- + +## 2. `/features` (Domain Layer) 🔥 + +Setiap fitur punya folder sendiri: + +```bash +features/trip/ +├── components/ +├── services/ +├── hooks/ +├── api/ +└── types.ts +``` + +Digunakan untuk: + +- business logic +- validation +- orchestration + +--- + +## 3. `/server` (Backend Layer) + +```bash +server/ +├── db/ +│ └── prisma.ts +├── services/ +│ └── trip.service.ts +└── repositories/ + └── trip.repo.ts +``` + +Digunakan untuk: + +- database access +- heavy logic +- internal backend + +--- + +## 4. `/components` + +```bash +components/ +├── ui/ # button, input, modal +└── shared/ # navbar, header +``` + +--- + +## 5. `/lib` + +Utility global: + +- prisma instance +- auth helper +- formatter + +--- + +# 🔄 Data Flow Standard + +```text +UI (app/) + ↓ +Feature (features/) + ↓ +Service (server/services) + ↓ +Repository (server/repositories) + ↓ +Database +``` + +--- + +# 🧩 Example Flow (Create Trip) + +1. User klik create trip (UI) +2. Call feature service +3. Feature validate data +4. Call server service +5. Service call repository +6. Repository insert ke database + +--- + +# ⚠️ Anti-Pattern (DILARANG) + +❌ Jangan: + +- query Prisma langsung di page.tsx +- campur UI + logic +- buat folder controller/service ala backend di Next.js +- over abstraction di awal + +--- + +# ✅ Best Practice + +✔ Gunakan: + +- Zod untuk validation +- Prisma untuk ORM +- Server Actions / API route secukupnya + +✔ Naming: + +- `trip.service.ts` +- `trip.repo.ts` +- `useTrip.ts` + +--- + +# 🚀 Development Phases + +## Phase 1 (MVP) + +- Auth +- Create Trip +- Join Trip + +## Phase 2 + +- Review +- Limit & validation + +## Phase 3 + +- Payment +- Organizer role + +--- + +# 🧠 Final Principle + +> Build fast → validate → refactor later + +Jangan terlalu fokus ke arsitektur sempurna di awal. + +--- + +# 📌 Notes for AI / Contributors + +- Ikuti struktur ini tanpa pengecualian +- Jangan membuat folder baru tanpa alasan jelas +- Semua fitur baru harus masuk ke `/features` +- Semua akses DB harus lewat `/server` + +--- + +# 📦 Tech Stack (MVP - Ideal) + +Project SeTrip menggunakan stack berikut: + +## Core + +- Next.js (App Router) +- TypeScript +- Tailwind CSS + +## Backend & Database + +- Prisma (ORM) +- PostgreSQL + +## Authentication + +- NextAuth + +## Validation + +- Zod + +## Utility + +- Axios +- Dayjs +- Clsx +- Bcryptjs + +--- + +# ⚠️ Rules for Dependencies + +- Gunakan hanya library yang dibutuhkan untuk MVP +- Hindari menambahkan dependency tanpa alasan jelas +- Jangan install: + - state management kompleks (Redux, Zustand) + - realtime (socket.io) + - queue system + - payment gateway (di phase awal) + +--- + +# 📌 Philosophy + +> Minimal dependencies → faster development → easier maintenance + +**End of Document** diff --git a/CLAUDE.md b/CLAUDE.md index 64f3176..1dce0c5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,233 +1,26 @@ -# 🚀 SeTrip Project Architecture Guide +# 🤖 Claude / AI Instructions -## 📌 Overview +## General Rules -Dokumen ini menjelaskan standar struktur project untuk aplikasi **SeTrip** menggunakan Next.js (App Router). +- Gunakan TypeScript +- Ikuti struktur feature-based +- Jangan letakkan business logic di `/app` +- Semua database access harus melalui `/server` -Tujuan: +## Code Rules -- Menjaga code tetap rapi & scalable -- Menghindari spaghetti code -- Memudahkan AI / developer kontribusi +- Gunakan Prisma untuk database +- Gunakan Zod untuk validation +- Gunakan service layer untuk business logic ---- +## Forbidden -# 🧠 Core Principles +- Jangan query database langsung di component +- Jangan buat arsitektur over-engineered +- Jangan menambahkan dependency tanpa kebutuhan jelas -1. **Feature-based structure (WAJIB)** -2. **Separation client vs server logic** -3. **Colocation (file dekat dengan fitur)** -4. **No over-engineering (keep it simple)** +## Output Style ---- - -# 🏗️ Project Structure - -```bash -src/ -├── app/ # Next.js App Router (UI & routing) -│ ├── (public)/ # halaman publik -│ ├── (auth)/ # login/register -│ ├── trips/ # halaman trip -│ ├── create-trip/ -│ └── profile/ -│ -├── features/ # 🔥 Business logic per domain -│ ├── auth/ -│ ├── user/ -│ ├── trip/ -│ ├── booking/ -│ └── review/ -│ -├── server/ # 🔒 Backend-only logic -│ ├── db/ -│ ├── services/ -│ └── repositories/ -│ -├── components/ # reusable UI components -│ ├── ui/ -│ └── shared/ -│ -├── lib/ # helpers & utilities -│ ├── prisma.ts -│ ├── auth.ts -│ └── utils.ts -│ -├── hooks/ # custom react hooks -├── types/ # global types -└── config/ # config (env, constants) -``` - ---- - -# 📂 Folder Rules - -## 1. `/app` (Routing Layer) - -Hanya untuk: - -- page.tsx -- layout.tsx -- UI rendering -- data fetching ringan - -❌ DILARANG: - -- business logic -- query database langsung - ---- - -## 2. `/features` (Domain Layer) 🔥 - -Setiap fitur punya folder sendiri: - -```bash -features/trip/ -├── components/ -├── services/ -├── hooks/ -├── api/ -└── types.ts -``` - -Digunakan untuk: - -- business logic -- validation -- orchestration - ---- - -## 3. `/server` (Backend Layer) - -```bash -server/ -├── db/ -│ └── prisma.ts -├── services/ -│ └── trip.service.ts -└── repositories/ - └── trip.repo.ts -``` - -Digunakan untuk: - -- database access -- heavy logic -- internal backend - ---- - -## 4. `/components` - -```bash -components/ -├── ui/ # button, input, modal -└── shared/ # navbar, header -``` - ---- - -## 5. `/lib` - -Utility global: - -- prisma instance -- auth helper -- formatter - ---- - -# 🔄 Data Flow Standard - -```text -UI (app/) - ↓ -Feature (features/) - ↓ -Service (server/services) - ↓ -Repository (server/repositories) - ↓ -Database -``` - ---- - -# 🧩 Example Flow (Create Trip) - -1. User klik create trip (UI) -2. Call feature service -3. Feature validate data -4. Call server service -5. Service call repository -6. Repository insert ke database - ---- - -# ⚠️ Anti-Pattern (DILARANG) - -❌ Jangan: - -- query Prisma langsung di page.tsx -- campur UI + logic -- buat folder controller/service ala backend di Next.js -- over abstraction di awal - ---- - -# ✅ Best Practice - -✔ Gunakan: - -- Zod untuk validation -- Prisma untuk ORM -- Server Actions / API route secukupnya - -✔ Naming: - -- `trip.service.ts` -- `trip.repo.ts` -- `useTrip.ts` - ---- - -# 🚀 Development Phases - -## Phase 1 (MVP) - -- Auth -- Create Trip -- Join Trip - -## Phase 2 - -- Review -- Limit & validation - -## Phase 3 - -- Payment -- Organizer role - ---- - -# 🧠 Final Principle - -> Build fast → validate → refactor later - -Jangan terlalu fokus ke arsitektur sempurna di awal. - ---- - -# 📌 Notes for AI / Contributors - -- Ikuti struktur ini tanpa pengecualian -- Jangan membuat folder baru tanpa alasan jelas -- Semua fitur baru harus masuk ke `/features` -- Semua akses DB harus lewat `/server` - ---- - -**End of Document** +- Clean code +- Modular +- Readable diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..7b38c1b --- /dev/null +++ b/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,6 @@ +import NextAuth from "next-auth"; +import { authOptions } from "@/lib/auth"; + +const handler = NextAuth(authOptions); + +export { handler as GET, handler as POST }; diff --git a/app/create-trip/page.tsx b/app/create-trip/page.tsx new file mode 100644 index 0000000..a02974b --- /dev/null +++ b/app/create-trip/page.tsx @@ -0,0 +1,229 @@ +"use client"; + +import { useState } from "react"; +import { useRouter } from "next/navigation"; +import { useSession } from "next-auth/react"; +import Link from "next/link"; +import { createTripAction } from "@/features/trip/actions"; + +const SAMPLE_MOUNTAINS = [ + { name: "Gunung Papandayan", location: "Garut, Jawa Barat" }, + { name: "Gunung Ciremai", location: "Kuningan, Jawa Barat" }, + { name: "Gunung Pangrango", location: "Bogor/Cianjur, Jawa Barat" }, + { name: "Gunung Gede", location: "Bogor/Cianjur, Jawa Barat" }, + { name: "Gunung Tangkuban Parahu", location: "Bandung, Jawa Barat" }, + { name: "Gunung Bukit Tunggul", location: "Bandung, Jawa Barat" }, + { name: "Gunung Malabar", location: "Bandung, Jawa Barat" }, + { name: "Gunung Guntur", location: "Garut, Jawa Barat" }, +]; + +export default function CreateTripPage() { + const { data: session } = useSession(); + const router = useRouter(); + const [error, setError] = useState(""); + const [loading, setLoading] = useState(false); + + if (!session?.user) { + return ( +
+ Kamu harus login untuk membuat trip. +
+ + Login + ++ Ajak teman baru naik gunung bareng! +
+[]>(arg: [...P], options?: { isolationLevel?: Prisma.TransactionIsolationLevel }): runtime.Types.Utils.JsPromise