A starter admin panel project combining a .NET backend and a Svelte frontend.
This repository contains two main folders:
backend/
- ASP.NET Core Web API projectfrontend/
- Svelte + Vite frontendJWT authentication (Bearer tokens) — backend issues JWTs for authenticating API requests. Configure the secret via environment variables or backend/appsettings.Development.json
and keep it out of source control.
Svelte + Vite frontend with Tailwind CSS and shadcn-style UI components (in-repo UI primitives). Supports light and dark themes (black/white) with a UI toggle.
PostgreSQL persistence with EF Core on the backend.
backend/backend.csproj
). The backend exposes API endpoints and uses the configuration files under backend/
.frontend/
and uses pnpm
as the package manager.Both frameworks are designed for high performance: .NET delivers a fast, scalable server platform with mature JIT/AOT optimizations and robust I/O/concurrency support, while Svelte compiles away the framework at build time to produce minimal runtime code and highly efficient client updates.
Install pnpm globally (if you don't have it):
npm i -g pnpm
Create a .env
file in the frontend/
folder so the client can read the API base URL. Vite/Svelte exposes variables prefixed with PUBLIC_
to the browser.
PowerShell example (from repository root):
# create the file and write the variable
cd frontend
'PUBLIC_apiUrl=http://localhost:5000' | Out-File -Encoding utf8 .env
# verify the file
Get-Content .\frontend\.env
In the frontend code use the exposed variable via import.meta.env.PUBLIC_apiUrl
(or the framework's env helper) to build API requests.
If you want a fast way to run the full stack (backend, frontend and database) locally, use Docker Compose. From the repository root run the following in PowerShell to build and start the services:
# build and start in detached mode
docker compose up --build -d
# follow logs (optional)
docker compose logs -f
# stop and remove containers, networks and volumes created by compose
docker compose down -v
After the services start you can usually access:
Notes:
If you plan to run PostgreSQL with Docker on Windows, installing Docker Desktop is the recommended and simplest option. Docker Desktop provides the Docker Engine, CLI, and a GUI, and integrates with WSL2 for best performance.
Quick checks (PowerShell):
# verify Docker is available
docker --version
# verify WSL status (if using WSL2 backend)
wsl --status
If docker --version
reports an error, install Docker Desktop:
Notes:
Alternatives (if you can't or don't want to install Docker Desktop):
The backend expects a PostgreSQL database. You can either install PostgreSQL locally or run it in Docker.
Quick start with Docker (PowerShell):
# pull and run a PostgreSQL container
docker run --name dotnet-svelte-admin-db -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=dotnet_svelte_admin -p 5432:5432 -d postgres:15
Create database and user using psql
(if needed):
# connect as the default 'postgres' user (you may be prompted for the password set in the container)
psql -h localhost -U postgres -c "CREATE DATABASE dotnet_svelte_admin;"
psql -h localhost -U postgres -c "CREATE USER admin WITH PASSWORD 'secret';"
psql -h localhost -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE dotnet_svelte_admin TO admin;"
Example connection string to put in backend/appsettings.Development.json
or environment variables:
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=dotnet_svelte_admin;Username=admin;Password=secret"
}
Apply EF Core migrations (if the project uses migrations):
# from the backend folder
cd backend
# if dotnet-ef is not installed globally
dotnet tool install --global dotnet-ef
# run migrations
dotnet ef database update
If no migrations are present, either add them or ensure the backend can create the schema at startup (check project docs or Program.cs
).
Follow these steps to run both backend and frontend locally.
backend/
folder in your IDE (Visual Studio, VS Code, or Rider).backend/
folder you can use the .NET CLI:# from repository root
cd backend
dotnet restore
dotnet build
dotnet run
dotnet-svelte-admin.sln
).Configuration files of interest:
backend/appsettings.json
and backend/appsettings.Development.json
From the repository root or directly inside the frontend/
folder:
cd frontend
pnpm install
pnpm run dev
Open the dev server URL printed by Vite (usually http://localhost:5173
) in your browser.
Note: older notes in this repo refer to fronted
— the correct folder name is frontend
.
Backend:
cd backend
dotnet publish -c Release -o ./publish
Frontend:
cd frontend
pnpm install
pnpm run build
# the build output will be in frontend/dist (or as configured in Vite)
You can host the frontend static output with any static host or serve it from the backend project if configured.
Keep sensitive values (connection strings, JWT secrets) out of source control. Use environment variables or a secrets manager.
Check backend/appsettings.Development.json
for development-only defaults.
You can generate a 32-character secret using OpenSSL. Examples (git bash):
# 32 hexadecimal characters (16 bytes -> 32 hex chars)
openssl rand -hex 16
# 32 Base64 characters (24 bytes -> 32 base64 chars, no padding)
openssl rand -base64 24
.gitignore
so they are not committed. Example .gitignore
entries:# local development secrets
backend/appsettings.Development.json
.env
.env.local
# stop tracking the file and commit the removal
git rm --cached backend/appsettings.Development.json
git commit -m "Remove local config from repository"
git push
git rm --cached
removes the file from the current and future commits but does not erase it from the repository history. To fully remove sensitive data from the history, use a history-rewriting tool such as BFG Repo-Cleaner or git filter-repo
, and then force-push. Be careful: rewriting history affects collaborators.pnpm run dev
fails, ensure Node.js and pnpm
are installed and that you ran pnpm install
.dotnet build
to see compile errors, and verify the correct .NET SDK is installed (run dotnet --info
).appsettings
or environment variables and that PostgreSQL is running and accepting connections on port 5432.Contributions are welcome. Suggested workflow:
See the LICENSE
file in the repository root.
If you want, tell me which parts you'd like expanded (API docs, env variables, deployment steps, CI/CD), and I can add them to this README.