How nightmoon1996/catfacttodotracker works
Project type and purpose
• This is a backend‐only RESTful API built with .NET 9 Minimal APIs.
• It exposes authentication endpoints (register/login) and ToDo endpoints that enrich new ToDos with a cat fact and current Bangkok weather.
• Uses an in‐memory EF Core database, JWT for security, external HTTP calls, and Swagger for docs.
File structure
• Program.cs: bootstraps the web host, configures services & endpoint routing.
• Data/ApplicationDbContext.cs: EF Core DbContext with DbSets for Users and TodoItems.
• Models/*.cs: DTOs and domain entities (User, TodoItem) plus response models (CatFactResponse, WeatherResponse).
• Services/AuthService.cs & TodoService.cs: business logic for authentication and ToDo operations (incl. external HTTP calls).
• appsettings.json / appsettings.Development.json: configuration (JWT keys, external API URLs).
• Properties/launchSettings.json & Swagger: dev tooling and API documentation.
Key README insights
• JWT Bearer Authentication with BCrypt password hashing.
• External services: “cat fact” API and weather API (hard‐coded to Bangkok).
• In‐memory EF Core – no external database server, but still a distinct data layer.
• Minimal API style – no MVC controllers, just endpoints in Program.cs wired to services.
Main components
a. Client (e.g. Postman or Browser)
b. ASP.NET Core Minimal API Layer (Program.cs hosting endpoints)
c. Authentication Module
• JWT Bearer middleware
• AuthService (register/login + token gen)
d. ToDo Module
• TodoService
• External HTTP Client A: Cat Fact API
• External HTTP Client B: Weather API
e. Data Layer
• ApplicationDbContext (EF Core In‐Memory DB)
• Entities: User, TodoItem
f. API Documentation
• Swagger / OpenAPI UI
g. Configuration Store
• appsettings.json / Environment Variables
Relationships & data‐flow
1. Client → HTTP POST /api/auth/register or /api/auth/login → Minimal API endpoint
→ AuthService → ApplicationDbContext → (User table) → returns JWT
2. Client → HTTP GET/POST /api/todos with Bearer token → JWT Middleware validates →
Minimal API endpoint → TodoService
a. If POST:
i. Create TodoItem entity in DbContext
ii. Call Cat Fact API over HTTP → map to CatFactResponse
iii. Call Weather API over HTTP → map to WeatherResponse
iv. Save enriched TodoItem in DbContext → return to client
b. If GET:
i. Query DB for user’s TodoItems → include cat fact and weather fields
ii. Return list to client
3. Swagger UI → served by Swashbuckle middleware
Architectural patterns & principles
• Layered architecture: Presentation (endpoints) → Business (Services) → Data (EF Core)
• Dependency Injection for services & DbContext
• External integration via HTTP Client in TodoService
• Secure perimeter enforced by JWT middleware
• Configuration abstraction via IConfiguration and environment overrides
Final advice
• Be exhaustive: represent each service class, middleware, and external integration.
• Configuration sources (appsettings.json vs env vars).
• Swagger as a sidecar of the API layer.