- Fixed PostgreSQL database creation error by using ALTER DATABASE instead of createdb - Rewrote README.md to be project-specific instead of generic boilerplate - Created comprehensive ROADMAP.md with short, medium, and long-term plans - Verified unit tests are working (7 tests passing) Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
6.7 KiB
Next.js Application with PostgreSQL
A production-ready Next.js 16 application with integrated PostgreSQL database, built with TypeScript, Tailwind CSS, and modern development tools.
Overview
This project is a full-stack web application featuring:
- Next.js 16 with App Router for server-side rendering and static site generation
- PostgreSQL 15 database with DrizzleORM for type-safe database operations
- Authentication using Clerk with support for multiple auth providers
- TypeScript for type safety across the entire stack
- Tailwind CSS 4 for modern, responsive styling
- Docker support for easy deployment
- Comprehensive testing with Vitest, Playwright, and Storybook
Features
- ⚡ Next.js 16 with App Router support
- 🔥 TypeScript for type safety
- 💎 Tailwind CSS 4 for styling
- 🔒 Clerk Authentication with social login support
- 📦 DrizzleORM with PostgreSQL database
- 🐳 Docker support with all-in-one container
- 🧪 Testing Suite - Vitest for unit tests, Playwright for E2E
- 🎨 Storybook for UI component development
- 📏 ESLint & Prettier for code quality
- 🔍 TypeScript strict mode
- 🌐 Multi-language (i18n) support with next-intl
- 🚨 Error Monitoring with Sentry
- 🔐 Security with Arcjet (bot detection, rate limiting)
Quick Start
Prerequisites
- Node.js 20+ and npm
- Docker (optional, for containerized deployment)
Local Development
- Clone the repository:
git clone https://github.com/johndoe6345789/postgres.git
cd postgres
- Install dependencies:
npm install
- Set up environment variables:
Create a
.env.localfile:
# Database
DATABASE_URL=postgresql://docker:docker@localhost:5432/postgres
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_key
CLERK_SECRET_KEY=your_secret
# Optional: Admin user creation
CREATE_ADMIN_USER=true
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin123
- Run the development server:
npm run dev
- Open http://localhost:3000 in your browser.
Docker Deployment
Build and run the application with Docker:
docker build -t postgres-app .
docker run -p 3000:3000 -p 5432:5432 \
-e JWT_SECRET=your_secret_here \
postgres-app
The Docker container includes both PostgreSQL and the Next.js application in a single image.
Project Structure
├── src/
│ ├── app/ # Next.js App Router pages
│ ├── components/ # React components
│ ├── models/ # Database models (DrizzleORM schemas)
│ ├── utils/ # Utility functions
│ ├── libs/ # Third-party library configurations
│ └── locales/ # i18n translations
├── tests/
│ ├── integration/ # Integration tests
│ └── e2e/ # End-to-end tests
├── migrations/ # Database migrations
├── public/ # Static assets
├── Dockerfile # Docker configuration
└── docker-compose.yml # Docker Compose setup
Available Scripts
Development
npm run dev- Start development server with live reloadnpm run build- Build production bundlenpm run start- Start production servernpm run build-local- Build with local database
Database
npm run db:generate- Generate database migrationsnpm run db:migrate- Apply database migrationsnpm run db:studio- Open Drizzle Studio (database GUI)npm run db:seed-admin- Seed admin user
Testing
npm run test- Run unit testsnpm run test:e2e- Run end-to-end testsnpm run storybook- Start Storybook for component development
Code Quality
npm run lint- Run ESLintnpm run lint:fix- Fix linting issues automaticallynpm run check:types- Type check with TypeScriptnpm run check:deps- Check for unused dependenciesnpm run check:i18n- Validate translations
Utilities
npm run commit- Interactive commit message generator (Conventional Commits)npm run generate:password- Generate secure passwords
Database Schema
Database schemas are defined in src/models/Schema.ts using DrizzleORM. To modify the schema:
- Edit
src/models/Schema.ts - Generate migration:
npm run db:generate - Apply migration:
npm run db:migrate
Authentication
This project uses Clerk for authentication. To set up:
- Create a Clerk account and application
- Copy your API keys to
.env.local:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_...
CLERK_SECRET_KEY=sk_...
Features include:
- Email/password authentication
- Social login (Google, GitHub, etc.)
- Multi-factor authentication (MFA)
- User management dashboard
Testing
Unit Tests
Run unit tests with Vitest:
npm run test
Unit tests are located alongside source files with .test.ts or .test.tsx extensions.
E2E Tests
Run end-to-end tests with Playwright:
npx playwright install # First time only
npm run test:e2e
E2E tests are in the tests/e2e directory with .e2e.ts extensions.
Component Development
Use Storybook for isolated component development:
npm run storybook
Deployment
Environment Variables
Required environment variables for production:
DATABASE_URL- PostgreSQL connection stringNEXT_PUBLIC_CLERK_PUBLISHABLE_KEY- Clerk public keyCLERK_SECRET_KEY- Clerk secret keyJWT_SECRET- Secret for JWT token signingNODE_ENV=production
Optional:
CREATE_ADMIN_USER- Set totrueto create admin user on startupADMIN_USERNAME- Admin username (default: admin)ADMIN_PASSWORD- Admin password (default: admin123)
Docker
The application can be deployed using the included Dockerfile:
# Build image
docker build -t postgres-app .
# Run container
docker run -d \
-p 3000:3000 \
-e DATABASE_URL="postgresql://..." \
-e CLERK_SECRET_KEY="sk_..." \
-e NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_..." \
-e JWT_SECRET="your-secret" \
postgres-app
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes using conventional commits (
npm run commit) - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Commit Convention
This project follows Conventional Commits. Use the interactive commit tool:
npm run commit
Roadmap
See ROADMAP.md for planned features and improvements.
License
Licensed under the MIT License. See LICENSE for more information.
Support
For issues, questions, or contributions, please open an issue on the GitHub repository.