Skip to content

DuckingGo/template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Template - Robust Environment Setup

A comprehensive, production-ready template for modern web applications with strong type safety, scalable configuration, and best practices.

πŸ“‹ Table of Contents

✨ Features

πŸ”’ Type Safety & Developer Experience

  • TypeScript with strict configuration
  • Zod for runtime environment validation
  • ESLint with comprehensive rules
  • Prettier for consistent formatting
  • Husky for git hooks

πŸ—οΈ Architecture & Scalability

  • Modular configuration for different environments
  • Path aliases for clean imports
  • Feature flags system
  • Error boundaries and proper error handling

πŸ§ͺ Testing

  • Jest for unit testing
  • React Testing Library for component testing
  • Playwright for E2E testing
  • Coverage reporting with thresholds

πŸš€ Deployment & DevOps

  • Docker support with multi-stage builds
  • GitHub Actions CI/CD pipeline
  • Environment-specific configurations
  • Security scanning and vulnerability checks

πŸ”§ Development Tools

  • Hot reload in development
  • Bundle analyzer for optimization
  • Pre-commit hooks for code quality
  • Comprehensive logging

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • pnpm 8+ (recommended) or npm 8+
  • Git

Installation

  1. Clone and setup

    git clone <repository-url>
    cd template
    pnpm install
  2. Environment configuration

    cp .env.example .env.local
    # Edit .env.local with your configuration
  3. Validate environment

    pnpm run env:validate
  4. Start development

    pnpm run dev

πŸ”§ Environment Setup

Environment Files

File Purpose When to use
.env.example Template with all variables Reference for required variables
.env.local Local development Development on your machine
.env.development Development environment Shared development settings
.env.production Production environment Production deployment
.env.test Testing environment Running tests

Environment Variables

Required Variables

NODE_ENV=development
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_API_URL=http://localhost:3000/api

Optional Variables

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/database

# Authentication
JWT_SECRET=your-super-secret-jwt-key-at-least-32-characters-long

# Analytics
NEXT_PUBLIC_ANALYTICS_ENABLED=false
NEXT_PUBLIC_GA_TRACKING_ID=G-XXXXXXXXXX

# Feature Flags
FEATURE_FLAG_NEW_UI=false
FEATURE_FLAG_BETA_FEATURES=false

Environment Validation

The project includes runtime environment validation using Zod:

# Validate current environment
pnpm run env:validate

# Environment will be validated automatically on:
# - Application start
# - Build process
# - CI/CD pipeline

πŸ’» Development

Available Scripts

Script Description
pnpm run dev Start development server
pnpm run build Build for production
pnpm run start Start production server
pnpm run lint Run ESLint
pnpm run lint:fix Fix ESLint issues
pnpm run format Format code with Prettier
pnpm run type-check Run TypeScript type checking
pnmp run test Run unit tests
pnpm run test:watch Run tests in watch mode
pnpm run test:coverage Run tests with coverage
pnpm run test:e2e Run E2E tests

Code Quality

The project enforces code quality through:

  • Pre-commit hooks that run linting and formatting
  • Pre-push hooks that run tests
  • CI pipeline that validates everything

Path Aliases

Use clean imports with configured path aliases:

// Instead of: import { Button } from '../../../components/ui/Button'
import { Button } from '@/components/ui/Button'
import { config } from '@/config'
import { User } from '@/types'

Available aliases:

  • @/* β†’ ./src/*
  • @/components/* β†’ ./src/components/*
  • @/lib/* β†’ ./src/lib/*
  • @/utils/* β†’ ./src/utils/*
  • @/hooks/* β†’ ./src/hooks/*
  • @/types/* β†’ ./types/*
  • @/config/* β†’ ./config/*

πŸ§ͺ Testing

Unit Testing

# Run all tests
pnpm run test

# Run tests in watch mode
pnpm run test:watch

# Run with coverage
pnpm run test:coverage

E2E Testing

# Run E2E tests
pnpm run test:e2e

# Run E2E tests with UI
pnpm run test:e2e:ui

# Install Playwright browsers (first time)
pnpm exec playwright install

Test Structure

tests/
β”œβ”€β”€ setup.ts           # Test configuration
β”œβ”€β”€ utils/             # Test utilities
└── e2e/              # E2E tests
src/
β”œβ”€β”€ __tests__/        # Unit tests
└── components/
    └── __tests__/    # Component tests

πŸš€ Deployment

Docker Deployment

  1. Build Docker image

    docker build -t template .
  2. Run container

    docker run -p 3000:3000 template
  3. Using Docker Compose

    # Production
    docker-compose up -d
    
    # Development
    docker-compose -f docker-compose.dev.yml up -d

Environment-Specific Builds

# Development build
NODE_ENV=development pnpm run build

# Production build
NODE_ENV=production pnpm run build

# Test build
NODE_ENV=test pnpm run build

CI/CD Pipeline

The GitHub Actions workflow automatically:

  1. Validates environment and code quality
  2. Tests unit and E2E tests
  3. Builds the application
  4. Scans for security vulnerabilities
  5. Deploys to staging/production

πŸ“ Project Structure

project-root/
β”œβ”€β”€ .github/              # GitHub workflows and templates
β”‚   └── workflows/        # CI/CD pipelines
β”œβ”€β”€ .husky/              # Git hooks
β”œβ”€β”€ config/              # Environment configurations
β”‚   β”œβ”€β”€ development/     # Development config
β”‚   β”œβ”€β”€ production/      # Production config
β”‚   β”œβ”€β”€ testing/         # Test config
β”‚   β”œβ”€β”€ env.ts          # Environment validation
β”‚   └── index.ts        # Main config
β”œβ”€β”€ scripts/             # Build and utility scripts
β”œβ”€β”€ src/                 # Source code
β”‚   β”œβ”€β”€ app/            # Next.js app directory
β”‚   β”œβ”€β”€ components/     # React components
β”‚   β”œβ”€β”€ lib/           # Utility libraries
β”‚   β”œβ”€β”€ hooks/         # Custom React hooks
β”‚   └── utils/         # Helper functions
β”œβ”€β”€ tests/              # Test files
β”‚   β”œβ”€β”€ utils/         # Test utilities
β”‚   └── e2e/          # E2E tests
β”œβ”€β”€ types/             # Global type definitions
β”œβ”€β”€ .env.example       # Environment template
β”œβ”€β”€ .eslintrc.js      # ESLint configuration
β”œβ”€β”€ .prettierrc       # Prettier configuration
β”œβ”€β”€ jest.config.ts    # Jest configuration
β”œβ”€β”€ playwright.config.ts # Playwright configuration
β”œβ”€β”€ tsconfig.json     # TypeScript configuration
β”œβ”€β”€ Dockerfile        # Production Docker image
β”œβ”€β”€ Dockerfile.dev    # Development Docker image
β”œβ”€β”€ docker-compose.yml # Production compose
└── docker-compose.dev.yml # Development compose

βš™οΈ Configuration

TypeScript Configuration

The project uses strict TypeScript settings:

  • Strict mode enabled
  • No implicit any
  • Unused locals/parameters detection
  • Exact optional properties
  • No unchecked indexed access

ESLint Rules

Comprehensive linting with:

  • TypeScript-specific rules
  • React hooks rules
  • Import ordering
  • Accessibility checks
  • Code complexity limits

Environment-Specific Configs

Each environment has its own configuration:

  • Development: Debug mode, hot reload, verbose logging
  • Production: Optimized, analytics enabled, security headers
  • Testing: Mock data, no analytics, fast timeouts

🀝 Contributing

  1. Fork the repository

  2. Create a feature branch

    git checkout -b feature/amazing-feature
  3. Make your changes

  4. Run tests and linting

    pnpm run test:ci
  5. Commit your changes

    git commit -m "feat: add amazing feature"
  6. Push to the branch

    git push origin feature/amazing-feature
  7. Open a Pull Request

Commit Convention

We use Conventional Commits:

  • feat: New features
  • fix: Bug fixes
  • docs: Documentation changes
  • style: Code style changes
  • refactor: Code refactoring
  • test: Adding or updating tests
  • chore: Maintenance tasks

πŸ“š Additional Resources

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made by DuckingGo with ❀️ for robust, scalable, and maintainable applications.

Releases

No releases published

Packages

No packages published