Skip to content

ijklim/demo-nestjs-nuxt-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Retro Console Explorer

A full-stack application for exploring and managing retro video game consoles, built with NestJS (Backend) and Nuxt 4 (Frontend). Features GitHub OAuth authentication, a beautiful glassmorphism UI, and Docker containerization with hot-reloading support.

โœจ Features

Frontend

  • ๐ŸŽฎ Browse Consoles - View retro gaming consoles with their top games
  • ๐Ÿ” GitHub OAuth Login - Secure authentication via GitHub
  • โž• Suggest Consoles - Authenticated users can add new consoles
  • ๐Ÿ—‘๏ธ Delete with Animation - Remove your consoles with animation effects
  • ๐ŸŽจ Modern UI - Glassmorphism design with Tailwind CSS
  • ๐Ÿ“ฑ Responsive - Works on all device sizes
  • โšก Hot Reloading - Development mode with instant updates (Docker + Windows compatible)

Backend

  • ๐Ÿ›ก๏ธ JWT Authentication - Secure API endpoints
  • ๐Ÿ”‘ OAuth 2.0 - GitHub login integration with Passport.js
  • ๐ŸŽฏ RESTful API - Clean, organized endpoints
  • ๐Ÿ‘ค User Ownership - Track who created each console
  • ๐Ÿ”’ Authorization - Users can only delete their own consoles
  • ๐Ÿณ Dockerized - Multi-stage builds for dev and production

๐Ÿ› ๏ธ Tech Stack

Backend

  • Framework: NestJS 10
  • Language: TypeScript
  • Authentication: Passport.js (GitHub Strategy)
  • JWT: @nestjs/jwt
  • Runtime: Node.js 22
  • Package Manager: pnpm
  • Containerization: Docker (multi-stage builds)

Frontend

  • Framework: Nuxt 4
  • Language: TypeScript
  • UI Library: Vue 3 (Composition API)
  • Styling: Tailwind CSS 3
  • State Management: Vue composables (useState)
  • HTTP Client: Nuxt $fetch
  • Containerization: Docker with hot-reloading support

DevOps

  • Container Orchestration: Docker Compose
  • Development: Hot-reloading with file watching (polling for Windows)
  • Production: Optimized multi-stage Docker builds
  • Startup Script: Interactive bash script for dev/prod mode selection

๐Ÿ“‹ Prerequisites

  • Node.js v22+ (or use Docker)
  • Docker & Docker Compose
  • GitHub OAuth App credentials
  • pnpm (if running locally without Docker)

๐Ÿš€ Quick Start

1. Configure Environment

Create a .env file in the backend directory:

GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GITHUB_CALLBACK_URL=http://localhost:3001/api/auth/callback

Note: Create a GitHub OAuth App at GitHub Developer Settings with the Authorization callback URL set to http://localhost:3001/api/auth/callback.

2. Run with Docker (Recommended)

Using the Interactive Startup Script

bash start-docker.sh

The script will prompt you to:

  1. Choose development (with hot-reloading) or production mode
  2. Decide whether to rebuild containers
  3. Optionally start the containers

Manual Docker Commands

Development Mode (with hot-reloading):

export FRONTEND_TARGET=stage-dev
docker compose up -d

Production Mode:

export FRONTEND_TARGET=stage-prod
docker compose up -d --build

Access the Application:

3. Run Locally (Without Docker)

Backend:

cd backend
pnpm install
pnpm run start:dev

Frontend:

cd frontend
pnpm install
pnpm run dev

๐Ÿ“ Project Structure

.
โ”œโ”€โ”€ backend/                 # NestJS backend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ auth/           # OAuth & JWT authentication
โ”‚   โ”‚   โ”œโ”€โ”€ console/        # Console CRUD operations
โ”‚   โ”‚   โ”œโ”€โ”€ user.controller.ts
โ”‚   โ”‚   โ””โ”€โ”€ main.ts
โ”‚   โ”œโ”€โ”€ Dockerfile          # Multi-stage Docker build
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ frontend/               # Nuxt 4 frontend
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ pages/          # Route pages (index, dashboard, suggest)
โ”‚   โ”‚   โ”œโ”€โ”€ composables/    # useAuth composable
โ”‚   โ”‚   โ”œโ”€โ”€ middleware/     # Auth middleware
โ”‚   โ”‚   โ””โ”€โ”€ assets/         # CSS and styles
โ”‚   โ”œโ”€โ”€ Dockerfile          # Multi-stage Docker build (dev/prod)
โ”‚   โ”œโ”€โ”€ nuxt.config.ts      # Nuxt configuration
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ docker-compose.yml      # Container orchestration
โ”œโ”€โ”€ start-docker.sh         # Interactive startup script
โ””โ”€โ”€ README.md

๐Ÿ”‘ API Endpoints

Public Endpoints

  • GET /api/consoles - List all consoles

Protected Endpoints (Require JWT)

  • GET /api/user/profile - Get authenticated user profile
  • POST /api/consoles - Create a new console (auto-assigns createdBy)
  • DELETE /api/consoles/:id - Delete a console (only if you created it)

Authentication

  • GET /api/auth/github - Initiate GitHub OAuth flow
  • GET /api/auth/callback - GitHub OAuth callback (redirects to frontend with JWT)

๐ŸŽจ Features in Detail

Authentication Flow

  1. User clicks "Log In with GitHub" on homepage
  2. Redirected to GitHub OAuth authorization
  3. After approval, redirected to backend callback
  4. Backend generates JWT and redirects to frontend dashboard with token
  5. Frontend stores token in cookie and fetches user profile
  6. User can now suggest and delete consoles

Console Management

  • View: All users can see all consoles
  • Create: Authenticated users can suggest new consoles
  • Delete: Users can only delete consoles they created
  • Validation: Duplicate ID and name checks before creation
  • Animation: Explosion effect when deleting

Docker Development

  • Hot Reloading: File changes instantly reflected (uses polling for Windows compatibility)
  • Volume Mounts: Source code mounted for live updates
  • Multi-Stage Builds: Separate stages for base, dev, build, and production
  • Optimized Images: Production images exclude dev dependencies

๐Ÿณ Docker Configuration

Frontend Stages

  • stage-base: Common dependencies and setup
  • stage-dev: Development with hot-reloading
  • stage-build: Build production assets
  • stage-prod: Serve production build

Environment Variables

  • FRONTEND_TARGET: Controls which Docker stage to use (stage-dev or stage-prod)
  • NUXT_PUBLIC_API_BASE: API base URL (default: http://localhost:3001/api)

๐Ÿ”ง Development Notes

Hot Reloading on Windows

The frontend uses Vite with polling enabled to support hot-reloading in Docker on Windows:

// nuxt.config.ts
vite: {
  server: {
    watch: {
      usePolling: true,
      interval: 1000,
    },
  },
}

CORS Configuration

The backend enables CORS for the frontend origin:

app.enableCors({
  origin: 'http://localhost:3000',
  credentials: true,
});

๐Ÿ“ License

MIT

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ™ Acknowledgments

  • Built with NestJS and Nuxt 4
  • Styled with Tailwind CSS
  • Authenticated with Passport.js
  • Containerized with Docker