I recently built HabitTrackerApi, a clean full-stack habit tracking project to practice modern .NET 10 Minimal APIs alongside a React + TypeScript frontend, automated integration tests, and CI.
Tech Stack
Backend: ASP.NET Core (.NET 10) Minimal APIs + built-in AddValidation()
Database: Entity Framework Core 10 + SQLite
API Docs & Testing UI: Built-in OpenAPI + Scalar (Scalar.AspNetCore)
Automated Tests: xUnit + WebApplicationFactory (Unit & Integration tests)
Frontend: React + TypeScript + Vite
CI: GitHub Actions (.github/workflows/dotnet.yml)
Project Architecture
HabitTrackerApi/
├── HabitTracker.Api/
│ ├── Contracts/ # Request & Response DTOs with DataAnnotations
│ ├── Data/ # AppDbContext & Fluent API schema rules
│ ├── Domain/ # Habit & HabitCompletion entities
│ ├── Endpoints/ # Minimal API route group (/api/habits)
│ └── Migrations/ # EF Core SQLite migrations
├── HabitTracker.Tests/ # Domain unit tests & API integration tests
└── habit-tracker-ui/ # React + TypeScript frontend
Key Highlights
- Encapsulated Domain Models
Instead of exposing public setters everywhere, Habit and HabitCompletion expose factory methods (Create) and domain methods (Update) that keep data clean (trimming whitespace, converting blank descriptions/notes to null) and protect navigation collections with IReadOnlyCollection.
- Database-Level Guardrails with EF Core & SQLite
One core rule of the app is that a habit can only be completed once per day.
In AppDbContext, I enforced this both at the API layer (409 Conflict) and at the database schema level using a composite unique index:
entity.HasIndex(c => new { c.HabitId, c.CompletedAtUtc })
.IsUnique();
Deleting a habit also cascades cleanly to its completion history (DeleteBehavior.Cascade).
- Clean Minimal APIs with .NET 10 AddValidation()
In .NET 10, builder.Services.AddValidation() automatically validates request DTOs decorated with DataAnnotations ([Required], [StringLength], [Range]) and returns a standardized 400 Bad Request ValidationProblem before the endpoint handler even runs.
Here are the endpoints exposed under /api/habits:
GET /api/habits — List habits with totalCompletions and isCompletedToday
GET /api/habits/{id} — Get habit details and completion history
POST /api/habits — Create a new habit
PUT /api/habits/{id} — Update a habit
DELETE /api/habits/{id} — Delete a habit
POST /api/habits/{id}/completions — Mark a habit completed for a date (409 if duplicate)
- Interactive API Docs with Scalar
Instead of Swagger UI, the API uses .NET 10 OpenAPI + Scalar (/scalar/v1) for testing endpoints directly in the browser during development.
- Isolated Integration Tests with xUnit
In HabitTracker.Tests, HabitTests verifies domain logic while HabitEndpointsTests spins up the real Minimal API in memory using WebApplicationFactory.
To avoid touching the local development database, HabitApiFixture points ConnectionStrings:DefaultConnection to a temporary SQLite file in the OS temp folder, runs MigrateAsync(), executes the HTTP tests (400, 201, 200, 409), and deletes the temp database afterward.
- React + TypeScript Frontend & GitHub Actions CI
The habit-tracker-ui app connects to the API via CORS, lets users create/complete/delete habits, and uses the backend's isCompletedToday flag to turn completed buttons green and disabled for the day.
Every push to main triggers .github/workflows/dotnet.yml to restore, build in Release mode, and run all xUnit tests automatically.
Try It Locally
git clone https://github.com/beriltzcn/HabitTrackerApi.git
cd HabitTrackerApi
# Apply database migrations & run tests
dotnet ef database update --project HabitTracker.Api
dotnet test
# Start the API (http://localhost:5198)
cd HabitTracker.Api
dotnet run --launch-profile http
In a second terminal, start the React app (http://localhost:5173):
cd habit-tracker-ui
npm install
npm run dev
This mini project was a great hands-on way for me to learn and connect modern tools together—especially .NET 10 Minimal APIs, built-in AddValidation(), Scalar, xUnit integration testing, and a React + TypeScript frontend.
I would love for you to check out the repository, explore the code, and share any feedback, suggestions, or improvements in the comments!
🔗 GitHub Repository: https://github.com/beriltzcn/HabitTrackerApi

Top comments (0)