A functional coffee shop demo built with Next.js, PostgreSQL, and TypeScript. This application demonstrates a complete e-commerce workflow with user authentication, product catalog, shopping cart, and admin portal.
- User Authentication: Registration and login system
- Product Catalog: Browse coffee and pastry offerings
- Shopping Cart: Add items, manage quantities, and checkout
- Order Management: Track purchase history
- Admin Portal: Manage products and view all orders
- Database Integration: PostgreSQL with proper schema design
- Node.js 18+
- Docker and Docker Compose
- Git
Single command for agents to get everything running:
# Option 1: Use the agent setup script
./agent-setup.sh
# Option 2: One-line command
npm install && echo 'DATABASE_URL=postgresql://admin:password@localhost:5432/coffee_shop
JWT_SECRET=coffee-shop-secret-key-2024
NEXT_PUBLIC_APP_URL=http://localhost:3000' > .env.local && docker compose up -d && sleep 10 && npm run dev-
Clone and setup the project:
git clone <repository-url> cd coffee-shop ./scripts/setup.sh
-
Start the development server:
npm run dev
-
Access the application:
- Main Store: http://localhost:3000 (or http://localhost:3001 if port 3000 is occupied)
- Admin Panel: http://localhost:3000/admin
If you're an AI agent or automated system setting up this repository:
-
Complete Setup Command:
# Run this single command to get everything working npm install && \ echo 'DATABASE_URL=postgresql://admin:password@localhost:5432/coffee_shop JWT_SECRET=coffee-shop-secret-key-2024 NEXT_PUBLIC_APP_URL=http://localhost:3000' > .env.local && \ docker compose up -d && \ sleep 10 && \ npm run dev
-
Verification Steps:
# Test database connection docker exec coffee-shop-db psql -U admin -d coffee_shop -c "SELECT COUNT(*) FROM users;" # Test admin login (run in separate terminal after app starts) curl -X POST http://localhost:3000/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email": "admin@coffeeshop.com", "password": "admin123"}' # Test products API curl http://localhost:3000/api/products
-
Important Notes for Agents:
- Wait time: Always wait 10+ seconds after
docker compose up -dfor database initialization - Port handling: App auto-switches to port 3001 if 3000 is occupied
- Database reset: If issues occur, run
docker compose down -v && docker compose up -dto reset - Log monitoring: Check
docker compose logs postgresfor database issues
- Wait time: Always wait 10+ seconds after
- Admin Account:
- Email:
admin@coffeeshop.com - Password:
admin123
- Email:
coffee-shop/
├── app/ # Next.js app directory
│ ├── api/ # API routes
│ │ ├── auth/ # Authentication endpoints
│ │ ├── products/ # Product management
│ │ └── orders/ # Order processing
│ ├── components/ # React components
│ ├── admin/ # Admin portal pages
│ └── globals.css # Global styles
├── lib/ # Utility libraries
│ ├── db.ts # Database connection
│ ├── auth.ts # Authentication utilities
│ └── middleware.ts # Request middleware
├── database/ # Database schema and migrations
│ └── init.sql # Initial schema and seed data
├── scripts/ # Setup and utility scripts
└── docker-compose.yml # Database container setup
POST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutGET /api/auth/me- Get current user
GET /api/products- List all productsPOST /api/products- Create product (admin only)PUT /api/products/[id]- Update product (admin only)DELETE /api/products/[id]- Delete product (admin only)
GET /api/orders- List orders (user's orders or all for admin)POST /api/orders- Create new order
The application uses PostgreSQL with the following main tables:
users- User accounts and authenticationproducts- Coffee shop inventoryorders- Purchase ordersorder_items- Individual items within orders
# Start database
docker-compose up -d
# Stop database
docker-compose down
# View logs
docker-compose logs postgres
# Connect to database
docker exec -it coffee-shop-db psql -U admin -d coffee_shopThe application will create .env.local automatically, but you can also create it manually:
DATABASE_URL=postgresql://admin:password@localhost:5432/coffee_shop
JWT_SECRET=coffee-shop-secret-key-2024
NEXT_PUBLIC_APP_URL=http://localhost:3000-
As a Customer:
- Register a new account or login
- Browse products in the catalog
- Add items to cart
- Complete checkout process
- View order history
-
As an Admin:
- Login with admin credentials
- Access admin panel from the main page
- Add, edit, or delete products
- View all customer orders
- Manage inventory levels
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Node.js
- Database: PostgreSQL 15
- Authentication: JWT with HTTP-only cookies
- Password Hashing: bcrypt
- Containerization: Docker Compose
This is a demo application designed for demonstration and testing purposes. For production use, additional security measures and features would be required.
For security testing information, see vulnerabilityinfo.md.
After setup, verify everything works:
# Test admin login
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "admin@coffeeshop.com", "password": "admin123"}'
# Test product listing
curl http://localhost:3000/api/products
# Test user registration
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "test@example.com", "password": "test123"}'Expected responses:
- Login:
{"message":"Login successful","user":{"id":1,"email":"admin@coffeeshop.com","role":"admin"}} - Products: Array of 8 coffee/pastry products with numeric prices
- Registration:
{"message":"Registration successful","user":{"id":2,"email":"test@example.com","role":"user"}}