This is a modified version of the Next.js App Router Course dashboard application, adapted to use MySQL instead of PostgreSQL.
-
Clone the repository
-
Install dependencies:
$ pnpm i
-
Set up MySQL database using Docker:
$ docker compose up -d
-
Create
.env
file:$ cp .env.example .env
-
Run the development server:
$ pnpm dev # or npm run dev
-
Seed the database:
$ node scripts/seed.js
-
MySQL Database: localhost:3306
- Username: admin
- Password: admin123
- Database: nextjs_dashboard
-
PHPMyAdmin: http://localhost:5050
- Server: db
- Username: admin
- Password: admin123
/app
: Directory - Main Application Code- Core application structure using Next.js App Router
- Contains routes, layouts, and page components
- Example: page.tsx contains the landing page with Acme logo and login button
/app/lib
: Directory - Core Utilitiesdata.ts
: Database query functionsfetchRevenue()
: Gets revenue datafetchLatestInvoices()
: Gets recent invoicesfetchCardData()
: Gets dashboard statistics
actions.ts
: Server actions for form handlingcreateInvoice()
: Handles invoice creation
definitions.ts
: TypeScript type definitions- Defines interfaces for Users, Customers, Invoices, etc.
- placeholder-data.ts: Sample data for development
/app/ui
: UI components (cards, tables, forms)/dashboard
: Dashboard-specific components -cards.tsx
: Statistics display cards -latest-invoices.tsx
: Recent invoices list/invoices
: Invoice-related componentstable.tsx
: Invoice listing table
- Common UI elements like buttons, forms, etc.
/public
: Static assets- Images (like hero-desktop.png, hero-mobile.png)
- Customer profile pictures
- Other static resources
/scripts
: Database seeding and utility scriptsmysql-local.js
: Database connection management- Creates singleton MySQL connection
- Handles SQL template literals
- Manages connection errors
seed.js
: Database seeding functionality- Creates database tables
- Populates initial data
docker-compose.yml
: MySQL and PHPMyAdmin container configurationnext.config.js
: Next.js configuration.env
: Environment variables (database connection, auth)
If you need to reset the database:
-
Stop the application
-
Remove existing containers and volumes:
$ docker compose down -v
-
Start fresh containers:
$ node scripts/seed.js
Email: user@nextmail.com Password: 123456
- Next.js: ^15.0.0
- Node.js: >=18.17.0
- MySQL: 8.0
- Docker Compose: v2.x
This is a modified version of the original Next.js dashboard example, adapted to use MySQL instead of PostgreSQL. The core functionality remains the same, but the database layer has been updated to work with MySQL.
If you encounter database connection issues:
- Ensure Docker containers are running:
docker-compose ps
- Check container logs:
docker-compose logs db
- Verify
.env
configuration matches Docker settings - Try restarting containers:
docker-compose restart
- Use PHPMyAdmin to inspect database structure and data
- Check Docker container status with
docker-compose ps
- Monitor logs with
docker-compose logs -f
To seed the database:
$ node scripts/seed.js
$ git diff > last-changes.log
- Request Flow:
graph LR
A[Request] --> B[middleware.ts]
B --> C{Protected Route?}
C -->|Yes| D[Check Auth]
C -->|No| E[Allow Access]
D -->|Authenticated| F[Allow Access]
D -->|Not Authenticated| G[Redirect to Login]
- Login Flow:
graph LR
A[Login Form] --> B[auth.ts]
B --> C[Validate Credentials]
C --> D[Check Database]
D --> E[Verify Password]
E -->|Success| F[Create Session]
E -->|Failure| G[Return Error]
https://mermaid.live/ for previewing the flowcharts
- Protection Logic:
middleware.ts
intercepts requests- Checks
auth.config.ts
rules - Uses
auth.ts
to verify session - Handles redirects if needed
- Heriicons