Skip to content

Latest commit

ย 

History

42 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Next.js Railway Template

Production-ready Next.js starter with Screaming Architecture, Server Actions, and zero-config Railway deployment.

Deploy on Railway

Next.js React TypeScript Railway License

๐ŸŽ‰ October 2025 Update: All Railway deployment issues resolved! Now fully compatible with Railway's Railpack builder. See CHANGELOG.md for details.


๐ŸŽฏ What Makes This Different?

Most templates give you a framework. This gives you a foundation.

This isn't another bloated starter with every possible feature. It's a battle-tested architecture that:

  • โœ… Screams what it does - Business logic organized by domain, not technical layers
  • โœ… Uses modern patterns - Server Actions instead of API routes
  • โœ… Deploys perfectly - Railway-native with health checks and graceful shutdown
  • โœ… Validates everything - Runtime type safety with Zod
  • โœ… Looks professional - Amber Minimal theme with shadcn/ui
  • โœ… Ready for better-auth - Architecture designed for easy migration

๐Ÿš€ Quick Start

One-Click Deploy

Deploy on Railway

Local Development

# Clone the repository
git clone https://github.com/contourkde/railway_nextjs_with_shadcn
cd nextjs_best_practices

# Install dependencies
npm install

# Run development server
npm run dev

Visit http://localhost:3000 to see your app.

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ app/                          # Next.js App Router
โ”‚   โ”œโ”€โ”€ (auth)/                   # Auth pages (signup, login, etc.)
โ”‚   โ”œโ”€โ”€ dashboard/                # Protected dashboard
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”œโ”€โ”€ health/              # Railway health checks
โ”‚   โ”‚   โ””โ”€โ”€ system/              # System monitoring
โ”‚   โ””โ”€โ”€ layout.tsx               # Root layout with theme
โ”‚
โ”œโ”€โ”€ features/                     # Business logic by domain
โ”‚   โ”œโ”€โ”€ auth/                    # Authentication feature
โ”‚   โ”‚   โ”œโ”€โ”€ actions/             # Server actions (NO API routes!)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ signup.action.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ login.action.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ forgot-password.action.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ reset-password.action.ts
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ validate-email.action.ts
โ”‚   โ”‚   โ”œโ”€โ”€ components/          # Auth UI components
โ”‚   โ”‚   โ”œโ”€โ”€ lib/                 # Auth utilities (password hashing)
โ”‚   โ”‚   โ””โ”€โ”€ types/               # Zod schemas & TypeScript types
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ dashboard/               # Dashboard feature
โ”‚   โ”œโ”€โ”€ home/                    # Homepage feature
โ”‚   โ””โ”€โ”€ health/                  # Health check feature
โ”‚
โ”œโ”€โ”€ components/
โ”‚   โ””โ”€โ”€ ui/                      # shadcn/ui components (Amber theme)
โ”‚
โ”œโ”€โ”€ core/                        # Shared business rules
โ”‚   โ”œโ”€โ”€ config/                  # Environment validation
โ”‚   โ””โ”€โ”€ types/                   # Shared types
โ”‚
โ””โ”€โ”€ infrastructure/              # External services
    โ””โ”€โ”€ logging/                 # Logging utilities

โœจ Key Features

๐Ÿ—๏ธ Screaming Architecture

Your folder structure tells you what the app does, not what framework it uses:

  • features/auth/ - "This app has authentication"
  • features/dashboard/ - "This app has a dashboard"
  • features/home/ - "This app has a homepage"

No more hunting through components/, utils/, or lib/ folders.

โšก Modern Server Actions

Zero API routes for authentication. Everything uses Next.js 15 server actions:

// โŒ OLD WAY: API Routes
const response = await fetch('/api/auth/signup', {
  method: 'POST',
  body: JSON.stringify(data),
});

// โœ… NEW WAY: Server Actions
import { signupAction } from '@/features/auth/actions';

const [state, formAction] = useFormState(signupAction, null);

Benefits:

  • Type-safe by default
  • No network overhead
  • Better performance
  • Simpler code
  • Progressive enhancement

๐ŸŽจ Beautiful Amber Theme

Pre-configured with the Amber Minimal theme from tweakcn:

  • Warm amber/orange primary color
  • Professional light & dark modes
  • All shadcn/ui components themed
  • Consistent design system

๐Ÿ”’ Complete Authentication

All auth flows included with server actions:

  • โœ… Signup - Email/password registration
  • โœ… Login - Secure authentication (demo: demo@example.com / password123)
  • โœ… Forgot Password - Password reset flow
  • โœ… Reset Password - Token-based password reset
  • โœ… Email Verification - Email validation (demo code: 123456)

Features:

  • Client + server validation with Zod
  • Password hashing with bcrypt
  • Toast notifications
  • Loading states
  • Error handling
  • Auto-redirects

๐Ÿš‚ Railway-Native Deployment

Deploys perfectly on Railway with:

  • โœ… Health check endpoint (/api/health)
  • โœ… System monitoring (/api/system)
  • โœ… Environment validation at startup
  • โœ… Graceful shutdown (SIGTERM handling)
  • โœ… Production logging
  • โœ… Zero configuration needed

๐Ÿ›ก๏ธ Type Safety Everywhere

// Environment variables validated at startup
const config = loadAppConfig(); // Throws if invalid

// Forms validated on client AND server
const schema = signupSchema; // Single source of truth

// API responses are type-safe
const health: HealthCheckResponse = await HealthService.check();

๐Ÿงช Testing

# Run all tests
npm test

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage

๐Ÿ“š Documentation

Getting Started

Architecture & Patterns

Migration & Cleanup

๐Ÿ”ง Built With

Technology Purpose Version
Next.js React framework with App Router 15.5.4
React UI library 19.2.0
TypeScript Type safety 5.9.3
Tailwind CSS Utility-first styling 4.1.14
shadcn/ui Component library Latest
Zod Runtime validation 4.1.11
React Hook Form Form validation 7.64.0
Server Actions Data mutations Built-in
bcryptjs Password hashing 3.0.2
Sonner Toast notifications 2.0.7
next-themes Theme management 0.4.6

๐ŸŽ“ Learn the Patterns

Server Actions Pattern

All auth forms follow this pattern:

  1. Shared Schema - Single Zod schema for validation
  2. Server Action - Server-side logic with 'use server'
  3. Client Form - React Hook Form + useFormState
  4. Toast Feedback - Success/error notifications

Example:

// 1. Schema (src/features/auth/types/auth.types.ts)
export const signupSchema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
  confirmPassword: z.string(),
}).refine((data) => data.password === data.confirmPassword);

// 2. Server Action (src/features/auth/actions/signup.action.ts)
'use server';

export async function signupAction(
  _prevState: SignupActionState | null,
  formData: FormData
): Promise<SignupActionState> {
  const result = signupSchema.safeParse({
    email: formData.get('email'),
    password: formData.get('password'),
    confirmPassword: formData.get('confirmPassword'),
  });

  if (!result.success) {
    return { success: false, message: 'Validation failed', errors: result.error };
  }

  // Hash password, create user, etc.
  return { success: true, message: 'Account created!' };
}

// 3. Client Form (src/features/auth/components/SignupForm.tsx)
'use client';

export function SignupForm() {
  const [state, formAction] = useFormState(signupAction, null);
  const [isPending, startTransition] = useTransition();

  const onSubmit = (data) => {
    const formData = new FormData();
    formData.append('email', data.email);
    formData.append('password', data.password);
    formData.append('confirmPassword', data.confirmPassword);

    startTransition(() => formAction(formData));
  };

  return <form onSubmit={handleSubmit(onSubmit)}>...</form>;
}

๐Ÿ”ฎ Better-Auth Ready

This architecture is designed for easy migration to better-auth:

Why This Helps

  1. Pattern Alignment - Better-auth uses server-side logic (like our server actions)
  2. Reusable Schemas - Your Zod schemas work with better-auth
  3. Same Client Patterns - Form components stay mostly the same
  4. Easy Migration - Just swap server actions for better-auth actions

Migration Path

// Current (our server actions)
import { signupAction } from '@/features/auth/actions';

// Future (better-auth) - same pattern!
import { signUp } from '@/lib/auth-client';

Estimated migration time: 2-4 hours

What you get:

  • OAuth providers (Google, GitHub, etc.)
  • Session management
  • 2FA support
  • Email verification (built-in)
  • Password reset (built-in)

๐Ÿš€ Deployment

Railway (Recommended)

โœ… Fully Optimized for Railway Railpack Builder

This template is production-ready with all Railway deployment issues resolved:

  1. Click the deploy button above
  2. Set environment variables (if needed)
  3. Deploy!

Railway automatically:

  • โœ… Uses Railpack builder (modern, optimized)
  • โœ… Detects Next.js and installs dependencies
  • โœ… Builds the app with static asset copying
  • โœ… Runs health checks on /api/health
  • โœ… Binds to 0.0.0.0 for container networking
  • โœ… Handles zero-downtime deployments

Recent Fixes (October 2025):

  • Fixed server path for Railpack builder
  • Fixed health check failures with HOSTNAME=0.0.0.0
  • Fixed static files not being served (README showing instead of app)

See CHANGELOG.md for detailed fix information.

Other Platforms

This template works on any platform that supports Next.js:

  • Vercel - Native Next.js support
  • Netlify - Next.js runtime
  • AWS - Amplify or EC2
  • Google Cloud - Cloud Run
  • Azure - App Service

๐Ÿค Contributing

Contributions are welcome! Please read our Contributing Guide first.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (npm test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

๐Ÿ“ License

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

TL;DR: You can use this for anything (including commercial projects), but please give credit to the original project.

๐Ÿ™ Acknowledgments

  • Next.js Team - For the amazing framework
  • shadcn - For the beautiful UI components
  • Railway - For the best deployment platform
  • tweakcn - For the Amber Minimal theme
  • Community - For all the feedback and contributions

๐Ÿ“ž Support

๐Ÿ—บ๏ธ Roadmap

  • Add database integration examples (Prisma, Drizzle)
  • Better-auth integration guide
  • OAuth provider examples
  • 2FA implementation
  • Email service integration
  • Stripe payment integration example
  • Admin dashboard example
  • Multi-tenancy example

โญ Star History

If this template helped you, please consider giving it a star! It helps others discover the project.


Built with โค๏ธ by the community

Deploy Now | View Docs | Report Bug | Request Feature

About

No description, website, or topics provided.

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages