How codewithgradi/gradiapi works
Purpose and Entry Point
GradiApi is a .NET 10 ASP.NET Core REST API backing a personal portfolio/profile: one personal profile with associated experience and project records. Application composition, HTTP pipeline, environment loading, CORS, OpenAPI, DI, and exception handling begin in Program.cs; service registrations are centralized in Extentions/ServiceExtentions.cs.
HTTP API Boundary
Three controllers expose the resource-oriented API: personal profile creation/read/update, and list/create/update operations for experiences and projects. Controllers should remain the transport boundary, accepting request DTOs and returning response DTOs rather than persistence entities.
• Controllers/PersonalController.cs
• Controllers/ExperienceController.cs
• Controllers/ProjectController.cs
Application Services and Business Rules
Each resource has a service layer between controllers and persistence. This is the intended location for orchestration, profile-association checks when creating projects/experiences, update semantics, and translation of domain failures into custom exceptions.
• Services/PersonalService.cs
• Services/ExperienceService.cs
• Services/ProjectService.cs
• Exceptions/BusinessRuleException.cs
Persistence Boundary
Repository interfaces abstract data access from services; concrete repositories use the EF Core context. PostgreSQL is the sole documented durable external dependency. The context owns entity sets, relationships, and EF mapping; migrations capture the deployable schema history.
• Data/AppDbContext.cs
• Interface/IPersonalRepo.cs
• Repo/PersonalRepo.cs
• Migrations/20260717182018_init.cs
Domain Aggregate and Relationships
Personal is the aggregate-facing profile data returned to clients, containing structured social links and associations to projects and experiences. Project and Experience are individually updated records and include update timestamps. Array-like profile and project fields are persisted through EF/PostgreSQL mapping.
• Models/Personal.cs
• Models/Project.cs
• Models/Experience.cs
• Utils/Socials.cs
Contract Transformation Flow
The main request path is: client JSON → controller DTO → service → repository/entity → PostgreSQL; reads reverse this flow into response DTOs. Mapperly-based mappers isolate API contracts from entities and protect controller/service code from manual field conversion.
• DTO/PostPersonalDto.cs
• DTO/GetPersonalDto.cs
• Mappers/PersonalMappers.cs
• Mappers/ExperienceMappers.cs
Runtime, Configuration, and Operations
The runtime is net10.0 ASP.NET Core with EF Core, Npgsql PostgreSQL provider, snake_case naming conventions, DotNetEnv, and Mapperly. Configuration selects Dev or Prod connection strings via Env, while frontend URLs configure CORS. Development exposes OpenAPI. The container deployment boundary is defined by Dockerfile; PostgreSQL must be supplied externally.
• gradiapi.csproj
• appsettings.json
• appsettings.Development.json
• Dockerfile
Main entry points: PersonalController.cs Resource controllers · AppDbContext.cs EF Core context · Personal.cs Personal aggregate · IPersonalRepo.cs Repository abstraction
Components 19
Runtime & Operations
- ASP.NET Core host · Composes middleware, DI, CORS, OpenAPI, and exception handling.
Program.cs - Service registration
Extentions/ServiceExtentions.cs - Environment configuration · Selects Dev or Prod connection strings and frontend CORS origins.
appsettings.json - Container image
Dockerfile
HTTP API
- Resource controllers · Personal, experience, and project REST endpoints.
Controllers/PersonalController.cs - Request/response DTOs · Keep transport payloads separate from persistence entities.
DTO/PostPersonalDto.cs
Application
- Personal service
Services/PersonalService.cs - Experience service · Applies association checks and update semantics.
Services/ExperienceService.cs - Project service · Applies association checks and update semantics.
Services/ProjectService.cs - Business rule exception
Exceptions/BusinessRuleException.cs - Mapperly mappers · Converts DTOs and domain entities at the API boundary.
Mappers/PersonalMappers.cs
Domain & Persistence
- Repository abstraction
Interface/IPersonalRepo.cs - EF repositories · Concrete data access used by resource services.
Repo/PersonalRepo.cs - EF Core context · Owns entity sets, relationships, and PostgreSQL mappings.
Data/AppDbContext.cs - Personal aggregate · Profile root with social links, projects, and experiences.
Models/Personal.cs - Project · Associated record with update timestamp.
Models/Project.cs - Experience · Associated record with update timestamp.
Models/Experience.cs - Schema migrations · Deployable PostgreSQL schema history.
Migrations/20260717182018_init.cs
Other components
- PostgreSQL · Externally supplied durable datastore.
Connections 24
- Container image → ASP.NET Core host: runs
- Environment configuration → ASP.NET Core host: configures
- ASP.NET Core host → Service registration: loads DI
- Service registration → Resource controllers: hosts
- Resource controllers → Request/response DTOs: accepts and returns
- Resource controllers → Personal service: profile operations
- Resource controllers → Experience service: experience operations
- Resource controllers → Project service: project operations
- Resource controllers → Mapperly mappers: maps contracts
- Personal service → Repository abstraction: uses
- Experience service → Repository abstraction: uses
- Project service → Repository abstraction: uses
- Personal service → Business rule exception: raises
- Experience service → Business rule exception: raises
- Project service → Business rule exception: raises
- Mapperly mappers → Personal aggregate: transforms
- Repository abstraction → EF repositories: implemented by
- EF repositories → EF Core context: queries and saves
- EF Core context → Personal aggregate: maps
- Personal aggregate → Project: has projects
- Personal aggregate → Experience: has experiences
- Schema migrations → EF Core context: defines schema
- EF Core context → PostgreSQL: persists to
- Environment configuration → PostgreSQL: connection string