A production-ready Blazor Server + PostgreSQL template optimized for Railway deployment.
Build full-stack web applications with C# and .NET 9. This template includes Entity Framework Core, automatic database migrations, and a complete CRUD demo ready to extend.
- 🚀 One-Click Deploy - Blazor app + PostgreSQL database
- ⚡ Blazor Server - Build interactive UIs with C#
- 🗄️ PostgreSQL - Production database included
- 🔄 Auto Migrations - Database schema updates automatically
- 🎯 Entity Framework Core - Modern ORM for .NET
- 📝 CRUD Demo - Working example with create, read, update, delete
- 🔧 Production Ready - Health checks, error handling, Docker optimized
- 🌐 .NET 9 - Latest .NET features and performance
Click the "Deploy on Railway" button above. Railway will automatically:
- Deploy the Blazor application
- Provision a PostgreSQL database
- Connect them together
- Run database migrations
- Generate a public URL
Visit /database page to see the CRUD demo in action!
# Clone the repository
git clone https://github.com/YOUR_USERNAME/blazor-postgres-starter.git
cd blazor-postgres-starter/BlazorPostgresStarter
# Install PostgreSQL locally or use Docker
docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres
# Update connection string in appsettings.json if needed
# Run the application
dotnet run
# Open browser to https://localhost:5001
# Visit /database to test the database connectionblazor-postgres-starter/
├── BlazorPostgresStarter/ # Main application
│ ├── Components/ # Blazor components
│ │ ├── Layout/ # Layout components
│ │ ├── Pages/ # Page components
│ │ │ └── Database.razor # CRUD demo page ⭐
│ │ └── App.razor # Root component
│ ├── Data/ # Database context and models
│ │ └── AppDbContext.cs # EF Core DbContext
│ ├── Services/ # Business logic
│ │ └── SampleItemService.cs # Database operations
│ ├── Migrations/ # Database migrations
│ ├── wwwroot/ # Static files
│ ├── Program.cs # App configuration
│ └── appsettings.json # Configuration
├── Dockerfile # Multi-stage Docker build
├── railway.toml # Railway configuration
└── README.md # Documentation
The template includes a working CRUD example at /database:
Features:
- ✅ View all items from database
- ✅ Add new items
- ✅ Delete items
- ✅ Real-time UI updates
- ✅ Type-safe LINQ queries
Sample Model:
public class SampleItem
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime CreatedAt { get; set; }
}Create a new class in the Data folder:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int Stock { get; set; }
}Update AppDbContext.cs:
public DbSet<Product> Products { get; set; }dotnet ef migrations add AddProductsgit add .
git commit -m "Add Products model"
git pushRailway automatically runs the migration on deploy! 🎉
Railway automatically sets:
DATABASE_URL- PostgreSQL connection string (auto-configured)PORT- Application portASPNETCORE_ENVIRONMENT- Set to Production
No manual configuration needed!
📊 Data-Driven Dashboards - Real-time analytics with live database updates
🛒 E-Commerce Apps - Product catalogs, inventory, orders
👥 CRM Systems - Customer and contact management
📝 Content Management - Blogs, wikis, documentation sites
🎫 Ticketing Systems - Support tickets, issue tracking
💼 Business Apps - Inventory, invoicing, HR management
cd BlazorPostgresStarter
dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCoreUpdate AppDbContext to inherit from IdentityDbContext:
public class AppDbContext : IdentityDbContext
{
// ... your DbSets
}Mix Blazor UI with REST APIs:
app.MapGet("/api/items", async (AppDbContext db) =>
await db.SampleItems.ToListAsync());
app.MapPost("/api/items", async (SampleItem item, AppDbContext db) =>
{
db.SampleItems.Add(item);
await db.SaveChangesAsync();
return Results.Created($"/api/items/{item.Id}", item);
});# Add Railway volume or cloud storage
# Store uploaded files alongside your data- Go to your Railway project
- Click on PostgreSQL service
- Click "Data" tab to browse tables
Get the DATABASE_URL from Railway dashboard and use your favorite PostgreSQL client.
Contributions welcome! Please submit a Pull Request.
MIT License - see LICENSE file
Built for the Railway community 🚂
⭐ Pro Tip: Visit /database after deployment to see the PostgreSQL integration in action!