first topic
Vefa Çağlar Personal Website Monorepo
Welcome to the personal developer website and API monorepo of Vefa Çağlar. This project is built using a highly efficient and modern TypeScript tech stack.
---
🚀 Tech Stack
- Monorepo Manager: Turborepo
- Package Manager: pnpm
- Frontend: Next.js (`apps/web`)
- Backend: Fastify (`apps/api`)
- Database / ORM: Drizzle ORM & Drizzle Kit (`packages/db`)
- Shared Utilities: TypeScript shared package (`packages/shared`)
- Validation: TypeBox (Runtime Validation & Schema Serialization)
- API Documentation: OpenAPI/Swagger (`@fastify/swagger` & `@fastify/swagger-ui`)
---
📁 Repository Structure
apps/
├── web/ # Next.js Frontend Application
└── api/ # Fastify Backend REST API
packages/
├── db/ # Drizzle ORM, Schemas, Migrations, and Seeders
└── shared/ # Shared TypeScript utilities and helpers---
⚙️ Architectural Conventions (API)
The backend (`apps/api`) strictly implements the Feature Folder / Handler Pattern (similar to .NET's MediatR or CQRS approach):
- Single Source of Truth: Schemas are defined using `@sinclair/typebox`. TypeScript types are automatically inferred via `Static<typeof Schema>`.
- Feature Folders: Endpoint modules are located in isolated feature folders under `src/modules/<module>/<feature>/`. Each feature consists of:
- `*.schema.ts`: Request / Response TypeBox schemas and types.
- `*.handler.ts`: Business logic and database interaction within a dedicated Handler class.
- Thin Routes: Routers under `src/modules/<module>/<module>.routes.ts` act as thin dispatchers that validate inputs, invoke the correct handler, and map responses/errors.
- Autogenerated Documentation: Every schema registered in the Fastify route option is automatically compiled into interactive OpenAPI docs available at `/swagger`.
---
🛠️ Getting Started
Prerequisites
- Node.js: v20 or higher
- pnpm: v11 or higher
- PostgreSQL Database (e.g., Neon Postgres, Local Postgres)
Installation
First, clone the repository and install all workspace dependencies from the root directory:
pnpm installConfigure your environment variables by creating a `.env` file in the root directory (you can copy `.env.example` as a starting point):
cp .env.example .env---
💻 Running the Project
All commands should be executed from the project root directory:
Development Mode
Runs Next.js frontend, Fastify API, and all workspace development servers in parallel:
pnpm devBuild Workspace
Compiles all apps and packages for production:
pnpm buildCode Quality & Formatting
Run typescript verification and code style checking across all packages:
pnpm typecheck
pnpm lint---
🗄️ Database Management (Code-First)
Database operations use [Drizzle Kit] and are executed from the root directory:
1. Direct Push (Fast Prototyping / Local Dev)
Instantly synchronize schema changes from TypeScript files directly into the database without generating migration files:
pnpm --filter @vefacaglar/db db:push2. Generate Migrations
Generate SQL migration files from your schema changes (saved under `packages/db/drizzle/`):
pnpm --filter @vefacaglar/db db:generate3. Run Migrations (Production / Staging)
Apply generated SQL migration files onto your remote/live database sequentially:
pnpm --filter @vefacaglar/db db:migrate4. Database Seeding
Seed your database with default initial data (adds a default admin user `admin@vefacaglar.com` with password `123` securely hashed with `scrypt`):
pnpm --filter @vefacaglar/db db:seed5. Drizzle Studio (Görsel Arayüz)
Explore your PostgreSQL database, manage tables, and edit data in a clean UI inside your browser:
pnpm --filter @vefacaglar/db db:studio---
🌐 API Endpoints & Swagger
Once the API server is running (`pnpm dev`), you can explore and test all auth endpoints interactively via Swagger UI:
- Swagger Documentation: `http://localhost:3001/swagger`
- Health Check Endpoint: `http://localhost:3001/health`