How cpsu25/mamafit-server works
1. MamaFit Server is a .NET 8 ASP.NET Core Web API backend for a maternity fashion platform. It is organized as a layered monolith, with the API host, business/services layer, repository layer, and shared business objects split into separate projects.
2. MamaFit.API is the HTTP entrypoint. It hosts REST controllers, middleware, Swagger/OpenAPI, CORS, JWT auth, and startup wiring. The controllers are feature-oriented rather than generic: auth, users, catalog, measurements, appointments, carts, orders, payments, shipping, warranties, chat, notifications, analytics, and AI test endpoints.
3. MamaFit.Services contains the main business logic boundary. Service classes implement orchestration for each domain area, while validators enforce request rules with FluentValidation. This is where workflows such as order processing, design requests, measurement generation, appointment handling, and notification dispatch are coordinated.
4. MamaFit.Repositories is the persistence layer. It uses a generic repository and unit-of-work pattern over Entity Framework Core, with one repository interface/implementation per aggregate. This layer isolates query and data-access logic from service rules and is the only place that should directly depend on the EF context.
5. MamaFit.BusinessObjects holds the shared domain model: EF Core ApplicationDBContext, entities, DTOs, enums, seed data, and the design-time context factory. DTOs are heavily used at service/controller boundaries, so the public API contract is defined separately from the persistence entities.
6. The core domain spans several subsystems: catalog management (Category, Style, Component, MaternityDress, Preset, AddOn), customer operations (Measurement, MeasurementDiary, Appointment), commerce (CartItem, Order, OrderItem, Transaction, Voucher*), and post-purchase flows (WarrantyRequest, WarrantyHistory, Feedback, Ticket). These are distinct business areas but share the same data store and service host.
7. Authentication and authorization are central cross-cutting concerns. The repo includes JWT token helpers, refresh tokens, OTP flows, Google login DTOs, role/user entities, and a permission middleware. This indicates the API enforces access control at the HTTP pipeline layer as well as in service logic.
8. Real-time features are handled with SignalR hubs in MamaFit.Services/Hubs. Chat and notifications are pushed through dedicated hubs, with connection management utilities to map users to active connections. The API exposes hub endpoints separately from REST controllers, but they share the same auth and user model.
9. External integrations are modeled as first-class services under MamaFit.Services/ExternalService. The backend talks to Cloudinary for images, Redis for caching, GHTK for shipping and tracking, Sepay for QR payments and webhooks, Mailgun for email, Contentful for CMS sync, and AI providers via Groq or optional Ollama. These integrations are wrapped behind service interfaces so the domain layer does not depend on provider-specific APIs directly.
10. Background processing is done with Hangfire backed by PostgreSQL storage. Recurring jobs are registered at startup and include appointment reminders and measurement generation. The architecture therefore has both request/response paths and asynchronous scheduled workflows operating on the same database state.
11. The API host also owns cross-cutting infrastructure: exception middleware, permission middleware, logging via NLog, CORS policy constants, endpoint constants, and startup service registration in ApplicationServiceExtension. These concerns shape how requests enter the system and how failures, permissions, and diagnostics are handled.
12. Deployment is container-focused. The repo includes a Dockerfile, Compose files, and a GitHub Actions pipeline that restores, builds, tests, creates the Docker image, ships compose files, and deploys to a VPS. There is also filebeat configuration for log shipping, which suggests production logs are collected outside the application container.
13. For diagramming, the main boundaries to show are: external clients calling REST or SignalR endpoints; the API host applying auth/middleware; services orchestrating validation, domain rules, caches, and integrations; repositories persisting through EF Core/PostgreSQL; and external systems such as Redis, Cloudinary, GHTK, Sepay, Mailgun, Contentful, Groq/Ollama, and Hangfire as separate dependencies.
Main entry points: ApplicationServiceExtension.cs Startup DI · Program.cs Program · OrderRepository.cs Repositories · ValidatorAssemblyReference.cs Validation
Components 24
API Host
HTTP entrypoint, middleware, controllers, and startup wiring.
- Program · Bootstraps the Web API, middleware, auth, Swagger, CORS, and DI.
MamaFit.API/Program.cs - Startup DI · Registers application services and cross-cutting API configuration.
MamaFit.API/DependencyInjection/ApplicationServiceExtension.cs - Middleware · Exception handling and permission enforcement at the HTTP layer.
MamaFit.API/Middlewares/ExceptionMiddleware.cs - Auth API · Login, token, OTP, roles, and user-facing identity endpoints.
MamaFit.API/Controllers/AuthController.cs - Catalog API · Category, style, component, dress, add-on, branch, and size endpoints.
MamaFit.API/Controllers/CategoryController.cs - Commerce API · Cart, order, payment, shipping, voucher, and transaction endpoints.
MamaFit.API/Controllers/OrderController.cs - Customer API · Measurements, appointments, design requests, feedback, and support endpoints.
MamaFit.API/Controllers/MeasurementController.cs - Realtime API · Chat and notification hub endpoints for push-style interaction.
MamaFit.Services/Hubs/ChatHub.cs
Business Services
Orchestration, validation, hubs, and external adapters.
- Identity · JWT, refresh token, OTP, roles, permissions, and user workflows.
MamaFit.Services/Service/AuthService.cs - Catalog · Manages product taxonomy, styles, components, presets, and dress data.
MamaFit.Services/Service/CategoryService.cs - Commerce · Coordinates cart, order, payment, shipment, voucher, and transaction flows.
MamaFit.Services/Service/OrderService.cs - Customer Ops · Handles measurements, appointments, design requests, feedback, and support.
MamaFit.Services/Service/MeasurementService.cs - Realtime · Chat and notification delivery plus connection management.
MamaFit.Services/Hubs/NotificationHub.cs - Integrations · Cloudinary, Redis cache, GHTK shipping, Sepay payments, Mailgun email, Contentful CMS, and AI providers.
MamaFit.Services/ExternalService/Ghtk/GhtkService.cs - Jobs · Recurring jobs for reminders and measurement generation via Hangfire scheduling.
MamaFit.Services/ExternalService/CronJob/RecurringJobScheduler.cs - Validation · Request validation rules for API and service boundary DTOs.
MamaFit.Services/Validator/ValidatorAssemblyReference.cs
Domain Model
Shared entities, DTOs, enums, and EF Core context.
- DB Context · ApplicationDbContext and design-time factory defining the database model.
MamaFit.BusinessObjects/DBContext/ApplicationDBContext.cs - Entities · Core persistence model for users, catalog, commerce, and post-purchase workflows.
MamaFit.BusinessObjects/Entity/Order.cs - DTOs · Boundary models used by controllers and services for requests and responses.
MamaFit.BusinessObjects/DTO/OrderDto/OrderRequestDto.cs
Persistence
Repositories and unit-of-work over EF Core.
- Unit of Work · Generic repository and transaction boundary for persistence coordination.
MamaFit.Repositories/Implement/UnitOfWork.cs - Repositories · Aggregate-specific repositories encapsulating queries and persistence details.
MamaFit.Repositories/Repository/OrderRepository.cs - Repo Helpers · Persistence-related helpers such as JWT, hashing, ordering, paging, and response models.
MamaFit.Repositories/Helper/JwtTokenHelper.cs
Delivery & Ops
Container and CI/CD artifacts.
- CI Pipeline · Build, test, image, compose packaging, and deployment workflow.
.github/workflows/main.yml - Deployment · Docker, compose, and log shipping configuration for containerized release.
Dockerfile
Connections 42
- Program → Startup DI: registers · Program wires the application services and infrastructure setup.
- Program → Middleware: uses · HTTP requests flow through exception and permission middleware.
- Program → Auth API: hosts · API exposes authentication controllers.
- Program → Catalog API: hosts · API exposes catalog and product controllers.
- Program → Commerce API: hosts · API exposes commerce controllers.
- Program → Customer API: hosts · API exposes customer-operation controllers.
- Program → Realtime API: maps · Program maps SignalR hub endpoints.
- Startup DI → Identity: injects · Registers identity and auth services.
- Startup DI → Catalog: injects · Registers catalog services.
- Startup DI → Commerce: injects · Registers commerce services.
- Startup DI → Customer Ops: injects · Registers customer workflow services.
- Startup DI → Realtime: injects · Registers hubs and connection services.
- Startup DI → Integrations: injects · Registers external adapters and caching/payment/email services.
- Startup DI → Jobs: schedules · Registers recurring background jobs.
- Startup DI → Validation: adds · Registers validator assembly and request validation.
- Auth API → Identity: calls · Auth controllers delegate identity workflows to services.
- Catalog API → Catalog: calls · Catalog controllers delegate to domain services.
- Commerce API → Commerce: calls · Commerce controllers delegate to order/payment workflows.
- Customer API → Customer Ops: calls · Customer controllers delegate to measurement and appointment workflows.
- Realtime API → Realtime: pushes · Hubs use realtime services to manage messaging and notifications.
- Identity → Validation: validates · Identity requests are validated before execution.
- Catalog → Validation: validates · Catalog requests are validated before mutations.
- Commerce → Validation: validates · Commerce workflows validate incoming commands.
- Customer Ops → Validation: validates · Customer workflows validate measurement and appointment input.
- Identity → Repositories: persists · Identity services read and write through repositories.
- Catalog → Repositories: persists · Catalog services persist through repositories.
- Commerce → Repositories: persists · Commerce services persist through repositories.
- Customer Ops → Repositories: persists · Customer services persist through repositories.
- Realtime → Repositories: reads · Realtime features resolve users and chat state from persistence.
- Integrations → Repositories: supports · Adapters support shipping, payment, cache, and storage workflows.
- Jobs → Repositories: operates on · Scheduled jobs act on persisted appointments and measurements.
- Repositories → Unit of Work: coordinates · Repositories operate under a unit-of-work boundary.
- Unit of Work → DB Context: uses · Unit of work depends on the EF Core context.
- Repositories → DB Context: queries · Repositories query the application database context.
- DB Context → Entities: maps · The DbContext maps entities to the database schema.
- Validation → DTOs: checks · Validators target DTOs exchanged across boundaries.
- Auth API → DTOs: accepts · Controllers bind request/response DTOs.
- Catalog API → DTOs: accepts · Controllers bind request/response DTOs.
- Commerce API → DTOs: accepts · Controllers bind request/response DTOs.
- Customer API → DTOs: accepts · Controllers bind request/response DTOs.
- CI Pipeline → Deployment: packages · Pipeline builds container and deployment artifacts.
- Deployment → Program: runs · Containerized deployment hosts the API entrypoint.