English | 简体中文
A modern AI application built with Next.js, PostgreSQL, and Prisma.
- Frontend Framework: Next.js 14 (App Router)
- Database: PostgreSQL 15
- ORM: Prisma
- Styling: Tailwind CSS
- Type Checking: TypeScript
- Containerization: Docker & Docker Compose
my-nextjs-app/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ │ ├── users/ # User-related APIs
│ │ └── posts/ # Post-related APIs
│ ├── posts/ # Post pages
│ ├── users/ # User pages
│ └── layout.tsx # Root layout
├── components/ # React components
├── lib/ # Utility libraries
│ └── prisma.ts # Prisma client
├── prisma/ # Database related
│ ├── schema.prisma # Database schema
│ ├── migrations/ # Migration files
│ └── seed.ts # Seed data
├── .env # Environment variables
├── docker-compose.yml # Docker services config
├── package.json
└── README.md
- User: User information
- Post: Article content
- Comment: Comments
- Tag: Tags
- ApiUsage: API usage records
Make sure you have installed:
- Node.js 18+
- Docker & Docker Compose
- Git
git clone <your-repo-url>
cd my-nextjs-appnpm installCreate a .env file:
# Database connection
DATABASE_URL="postgresql://myuser:mypassword@localhost:5432/myapp_development"
# Next.js configuration
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-here"# Start PostgreSQL database
docker-compose up -d postgres
# Verify database status
docker-compose ps# Run database migrations
npx prisma migrate dev --name init
# Generate Prisma Client
npx prisma generate
# Seed data (optional)
npx prisma db seednpm run devThe application will start at http://localhost:3000.
# Development
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
# Database management
npm run db:up # Start database services
npm run db:down # Stop database services
npm run db:reset # Reset database (delete all data)
npm run db:seed # Run seed data
npm run db:studio # Start Prisma Studio
npm run db:migrate # Run migrations
npm run db:generate # Generate Prisma Client
# Management interfaces
npm run db:admin # Start pgAdmin (http://localhost:8080)
npm run db:adminer # Start Adminer (http://localhost:8081)npm run db:studioAccess: http://localhost:5555
docker-compose up -d pgadminAccess: http://localhost:8080
- Email: [email protected]
- Password: admin123
docker-compose up -d adminerAccess: http://localhost:8081
- Server: postgres
- Username: myuser
- Password: mypassword
- Database: myapp_development
# Connect via Docker
npm run db:psql
# Or use psql directly
psql -h localhost -p 5432 -U myuser -d myapp_development- Edit
prisma/schema.prismato add new models - Create migration:
npx prisma migrate dev --name add_new_model
- Generate client:
npx prisma generate
# Complete reset (delete all data)
npm run db:reset
# Restart development environment
npm run dev# Backup database
docker exec my-app-postgres pg_dump -U myuser myapp_development > backup.sql
# Restore database
docker exec -i my-app-postgres psql -U myuser myapp_development < backup.sqlGET /api/users- Get user listPOST /api/users- Create new user
GET /api/posts- Get post listGET /api/posts?published=true- Get published postsPOST /api/posts- Create new post
/- Home page/posts- Post list page/users- User list page/posts/[slug]- Post detail page (needs implementation)
- Ensure Docker services are running:
docker-compose ps
- Check environment variable configuration
- Restart database service:
docker-compose restart postgres
# Check migration status
npx prisma migrate status
# Reset database if needed
npx prisma migrate reset# Ensure Prisma Client is up to date
npx prisma generate
# Restart
npx prisma studioIf you encounter port conflicts, modify port mapping in docker-compose.yml:
ports:
- "5433:5432" # Change local port to 5433Then update DATABASE_URL in .env.
npm run build
npm run start# Build production image
docker build -t my-app .
# Start with production config
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
MIT License - see the LICENSE file for details.
If you encounter issues:
- Check the Troubleshooting section
- Look at existing Issues
- Create a new Issue describing your problem
- ✅ Modern Next.js 14 with App Router
- ✅ Type-safe database operations with Prisma
- ✅ PostgreSQL with Docker setup
- ✅ Multiple database management interfaces
- ✅ Seed data and migrations
- ✅ API routes for CRUD operations
- ✅ Responsive UI with Tailwind CSS
- ✅ TypeScript for type safety
- ✅ Development and production configurations
- Authentication with NextAuth.js
- File upload functionality
- Search and filtering
- Pagination
- Email notifications
- Admin dashboard
- API rate limiting
- Comprehensive testing suite