buildout full stack functionality #1
53
README.md
53
README.md
@@ -1,2 +1,55 @@
|
||||
# react-dotnet
|
||||
|
||||
### A minimal monorepo skeleton project jumpstarter.
|
||||
### NET backend
|
||||
### React/Vite frontend.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- [.NET SDK](https://dotnet.microsoft.com/download) (project targets `net10.0`)
|
||||
- [Node.js](https://nodejs.org/) (LTS recommended)
|
||||
|
||||
## Backend
|
||||
|
||||
From the repository root:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
dotnet run
|
||||
```
|
||||
|
||||
The API runs at `http://localhost:5231`. Swagger UI is available in Development at `http://localhost:5231/swagger`.
|
||||
|
||||
Skeleton endpoints:
|
||||
|
||||
- `GET /health` — liveness check
|
||||
- `GET /v1/info` — app name, version, environment, and server timestamp
|
||||
|
||||
## Frontend
|
||||
|
||||
From the repository root:
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
The app runs at `http://localhost:3000`.
|
||||
|
||||
Copy `.env.example` to `.env.development` (or `.env.local`) if you need to customize the API URL:
|
||||
|
||||
```
|
||||
VITE_API_BASE_URL=http://localhost:5231
|
||||
```
|
||||
|
||||
## Running both
|
||||
|
||||
Start the backend and frontend in separate terminals. The backend CORS policy allows requests from `http://localhost:3000`.
|
||||
|
||||
## Project structure
|
||||
|
||||
```
|
||||
backend/ ASP.NET Core Web API
|
||||
frontend/ React + Vite + TypeScript SPA
|
||||
```
|
||||
|
||||
29
backend/Controllers/InfoController.cs
Normal file
29
backend/Controllers/InfoController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Backend.Controllers;
|
||||
|
||||
[Route("v1/[controller]")]
|
||||
[ApiController]
|
||||
public class InfoController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public InfoController(IWebHostEnvironment environment)
|
||||
{
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Get()
|
||||
{
|
||||
var assembly = typeof(InfoController).Assembly.GetName();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
name = assembly.Name ?? "backend",
|
||||
version = assembly.Version?.ToString(3) ?? "0.0.0",
|
||||
environment = _environment.EnvironmentName,
|
||||
timestamp = DateTime.UtcNow,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
// using Backend.Data
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
builder.Services.AddCors();
|
||||
|
||||
@@ -32,6 +36,19 @@ app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapHealthChecks("/health", new HealthCheckOptions
|
||||
{
|
||||
ResponseWriter = async (context, report) =>
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
status = report.Status == HealthStatus.Healthy ? "healthy" : "unhealthy",
|
||||
});
|
||||
await context.Response.WriteAsync(payload);
|
||||
},
|
||||
});
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@@ -1,6 +1,11 @@
|
||||
@Backend_HostAddress = http://localhost:3000
|
||||
@Backend_HostAddress = http://localhost:5231
|
||||
|
||||
GET {{Backend_HostAddress}}/weatherforecast/
|
||||
GET {{Backend_HostAddress}}/health
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{Backend_HostAddress}}/v1/info
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
1
frontend/.env.development
Normal file
1
frontend/.env.development
Normal file
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=http://localhost:5231
|
||||
1
frontend/.env.example
Normal file
1
frontend/.env.example
Normal file
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=http://localhost:5231
|
||||
24
frontend/.gitignore
vendored
Normal file
24
frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
28
frontend/eslint.config.js
Normal file
28
frontend/eslint.config.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ['dist'] },
|
||||
{
|
||||
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2022,
|
||||
globals: globals.browser,
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
13
frontend/index.html
Normal file
13
frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>React + .NET Starter</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
3258
frontend/package-lock.json
generated
Normal file
3258
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
frontend/package.json
Normal file
29
frontend/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.30.1",
|
||||
"@types/react": "^19.1.8",
|
||||
"@types/react-dom": "^19.1.6",
|
||||
"@vitejs/plugin-react": "^4.6.0",
|
||||
"eslint": "^9.30.1",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.20",
|
||||
"globals": "^16.3.0",
|
||||
"typescript": "~5.8.3",
|
||||
"typescript-eslint": "^8.35.1",
|
||||
"vite": "^7.0.4"
|
||||
}
|
||||
}
|
||||
1
frontend/public/vite.svg
Normal file
1
frontend/public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFBD4F"></stop><stop offset="100%" stop-color="#FF980E"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
89
frontend/src/App.css
Normal file
89
frontend/src/App.css
Normal file
@@ -0,0 +1,89 @@
|
||||
.app {
|
||||
max-width: 720px;
|
||||
margin: 0 auto;
|
||||
padding: 3rem 1.5rem;
|
||||
}
|
||||
|
||||
.app__header {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.app__header h1 {
|
||||
margin: 0 0 0.5rem;
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.app__header p {
|
||||
margin: 0;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.app__section {
|
||||
padding: 1.25rem 1.5rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
background-color: #f8fafc;
|
||||
}
|
||||
|
||||
.app__section h2 {
|
||||
margin: 0 0 0.75rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.app__section p {
|
||||
margin: 0;
|
||||
color: #475569;
|
||||
}
|
||||
|
||||
.app__section code {
|
||||
font-size: 0.875em;
|
||||
background-color: #e2e8f0;
|
||||
padding: 0.125rem 0.375rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.app__section--api {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.app__status {
|
||||
margin: 0.75rem 0 0;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.app__status--loading {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.app__status--ok {
|
||||
color: #15803d;
|
||||
}
|
||||
|
||||
.app__status--error {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.app__info {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
margin: 1rem 0 0;
|
||||
}
|
||||
|
||||
.app__info div {
|
||||
display: grid;
|
||||
grid-template-columns: 8rem 1fr;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.app__info dt {
|
||||
margin: 0;
|
||||
color: #64748b;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.app__info dd {
|
||||
margin: 0;
|
||||
color: #334155;
|
||||
}
|
||||
83
frontend/src/App.tsx
Normal file
83
frontend/src/App.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { apiBaseUrl, apiFetch } from './api/client'
|
||||
import './App.css'
|
||||
|
||||
type InfoResponse = {
|
||||
name: string
|
||||
version: string
|
||||
environment: string
|
||||
timestamp: string
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [info, setInfo] = useState<InfoResponse | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<InfoResponse>('/v1/info')
|
||||
.then(setInfo)
|
||||
.catch((err: unknown) =>
|
||||
setError(err instanceof Error ? err.message : 'Unknown error'),
|
||||
)
|
||||
.finally(() => setLoading(false))
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<header className="app__header">
|
||||
<h1>React + .NET Starter</h1>
|
||||
<p>A minimal monorepo skeleton for new projects.</p>
|
||||
</header>
|
||||
|
||||
<section className="app__section">
|
||||
<h2>Frontend</h2>
|
||||
<p>
|
||||
Vite + React + TypeScript running on port 3000. Extend{' '}
|
||||
<code>src/App.tsx</code> to begin building your application.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="app__section app__section--api">
|
||||
<h2>Backend API</h2>
|
||||
<p>
|
||||
Requests go to <code>{apiBaseUrl}</code> via{' '}
|
||||
<code>VITE_API_BASE_URL</code>.
|
||||
</p>
|
||||
|
||||
{loading && <p className="app__status app__status--loading">Checking API…</p>}
|
||||
{error && (
|
||||
<p className="app__status app__status--error">
|
||||
Unable to reach API: {error}
|
||||
</p>
|
||||
)}
|
||||
{info && (
|
||||
<dl className="app__info">
|
||||
<div>
|
||||
<dt>Status</dt>
|
||||
<dd className="app__status app__status--ok">Connected</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Name</dt>
|
||||
<dd>{info.name}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Version</dt>
|
||||
<dd>{info.version}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Environment</dt>
|
||||
<dd>{info.environment}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Server time (UTC)</dt>
|
||||
<dd>{new Date(info.timestamp).toISOString()}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
17
frontend/src/api/client.ts
Normal file
17
frontend/src/api/client.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL
|
||||
|
||||
export async function apiFetch<T>(
|
||||
path: string,
|
||||
init?: RequestInit,
|
||||
): Promise<T> {
|
||||
const url = `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`
|
||||
const response = await fetch(url, init)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API request failed: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>
|
||||
}
|
||||
|
||||
export { baseUrl as apiBaseUrl }
|
||||
28
frontend/src/index.css
Normal file
28
frontend/src/index.css
Normal file
@@ -0,0 +1,28 @@
|
||||
:root {
|
||||
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
||||
sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
10
frontend/src/main.tsx
Normal file
10
frontend/src/main.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
9
frontend/src/vite-env.d.ts
vendored
Normal file
9
frontend/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_API_BASE_URL: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
||||
23
frontend/tsconfig.app.json
Normal file
23
frontend/tsconfig.app.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
frontend/tsconfig.json
Normal file
7
frontend/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
21
frontend/tsconfig.node.json
Normal file
21
frontend/tsconfig.node.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
10
frontend/vite.config.ts
Normal file
10
frontend/vite.config.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 3000,
|
||||
host: 'localhost',
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user