How emanuelmath/xchange works
1. This is a layered ASP.NET Core MVC solution with three main projects: XChange.Core, XChange.Infrastructure, and XChange.Web. The architecture cleanly separates domain contracts, data/access implementations, and the presentation layer.
2. XChange.Core is the application contract layer. It contains:
- domain entities like User and User2fa
- shared result/error handling via Common/Result.cs
- enums for user/auth/transaction state
- custom exceptions
- interfaces for repositories and services such as password hashing, MFA, email, and database connection creation
3. XChange.Infrastructure is the implementation layer. It provides concrete infrastructure for the interfaces defined in Core:
- SQL connection creation in Data/SqlConnectionFactory.cs
- repositories for User and User2fa
- BcryptPasswordHasher for credential hashing
- GoogleMfaService for MFA/TOTP-based verification
4. XChange.Web is the user-facing MVC application. It hosts the HTTP entry point (Program.cs), controllers, MVC views, view models, filters, and static assets. This project depends on Core abstractions and Infrastructure implementations through dependency injection.
5. The main user flows are authentication-centric. The presence of AuthController, login/register/forgot-password/reset-password/verify-email/verify-mfa views, and related view models indicates a full identity lifecycle:
registration → email verification → login → optional MFA verification → password recovery/reset.
6. There is also a private authenticated user area. UserController plus views like Dashboard, Wallet, Transactions, and Settings suggest the app exposes a post-login account section focused on user state and financial/account activity.
7. Access control is enforced at the MVC boundary using filters:
- RedirectIfAuthenticatedAttribute prevents logged-in users from returning to auth pages
- RedirectIfNotLoginForMfaAttribute gates MFA verification so it only works in the correct login flow
These filters shape request routing before controller actions run.
8. Data access is repository-based, not directly embedded in controllers. Controllers should talk to Core interfaces, which Infrastructure implements with SQL-backed repositories. This gives a clear separation between HTTP handling and persistence concerns.
9. The architecture also includes service abstractions for cross-cutting concerns:
- password hashing
- MFA generation/validation
- email delivery
These are kept out of the web layer so they can be swapped or mocked independently.
10. The UI layer is Razor-based and split by layout:
- public pages
- auth pages
- private authenticated pages
Static assets live under wwwroot, including Bootstrap, Font Awesome, custom CSS/JS, and a spanish.json file that likely supports localized client-side text.
11. From an architecture-diagram perspective, the primary data flow is:
browser → MVC controller → Core abstractions / view models → Infrastructure repositories & services → SQL database and MFA/email-related services → back to MVC views.
12. The repo appears focused on account and transaction management rather than a generic content site. The combination of user, 2FA, wallet, and transaction concepts implies a fintech or exchange-style application domain, with the core business boundary centered on identity, access, and account state.
Main entry points: Interfaces Contracts · AuthController.cs Auth Controller · Program.cs Program · UserController.cs User Controller
Components 18
XChange.Core
Domain contracts, shared types, and application abstractions
- Contracts · Repository and service abstractions for database, email, MFA, and hashing
src/XChange/XChange.Core/Interfaces - Domain · User entities plus status and provider constants
src/XChange/XChange.Core/Entities - Result · Common success/error result handling
src/XChange/XChange.Core/Common/Result.cs - Errors · Core exception hierarchy for user and MFA flows
src/XChange/XChange.Core/Exceptions
XChange.Infrastructure
Concrete SQL and service implementations
- SQL Factory · Creates SQL connections for persistence operations
src/XChange/XChange.Infrastructure/Data/SqlConnectionFactory.cs - User Repos · SQL-backed user and 2FA repositories
src/XChange/XChange.Infrastructure/Repositories - Security Services · Password hashing and TOTP/MFA implementation services
src/XChange/XChange.Infrastructure/Services
XChange.Web
MVC presentation layer and user flows
- Program · ASP.NET Core entry point and dependency wiring
src/XChange/XChange.Web/Program.cs - Auth Controller · Registration, login, password recovery, email verification, and MFA flows
src/XChange/XChange.Web/Controllers/AuthController.cs - User Controller · Private account area for dashboard, wallet, transactions, and settings
src/XChange/XChange.Web/Controllers/UserController.cs - Home Controller · Public landing and informational pages
src/XChange/XChange.Web/Controllers/HomeController.cs - MVC Filters · Redirect rules for authenticated users and MFA login flow
src/XChange/XChange.Web/Filters - Auth ViewModels · Login, register, reset, email verify, and MFA form models
src/XChange/XChange.Web/ViewModels - Auth Views · UI pages for the identity lifecycle
src/XChange/XChange.Web/Views/Auth - Private Views · Authenticated dashboard, wallet, transactions, and settings pages
src/XChange/XChange.Web/Views/User - Public Views · Landing and informational site pages
src/XChange/XChange.Web/Views/Home - Layouts · Shared public, auth, private, and base layouts
src/XChange/XChange.Web/Views/Shared - Static Assets · Bootstrap, Font Awesome, custom CSS/JS, and localized client-side data
src/XChange/XChange.Web/wwwroot
Connections 28
- Program → Contracts: registers · Wires abstractions into dependency injection
- Program → SQL Factory: configures · Sets up database connectivity and hosting services
- Program → User Repos: registers · Adds repository implementations to the container
- Program → Security Services: registers · Adds hashing and MFA services to the container
- Auth Controller → Contracts: uses · Depends on repository and service interfaces
- Auth Controller → Auth ViewModels: binds · Consumes dedicated authentication form models
- Auth Controller → MVC Filters: governed by · Protected by redirect and login-state filters
- User Controller → Contracts: uses · Reads and writes user/account state through abstractions
- User Controller → MVC Filters: governed by · Protected by request gating rules
- Home Controller → Layouts: renders · Served through shared public layouts
- Auth Controller → Auth Views: renders · Returns identity workflow views
- User Controller → Private Views: renders · Returns authenticated account views
- Home Controller → Public Views: renders · Returns public-facing pages
- Auth Views → Layouts: uses · Shares auth-specific and base layouts
- Private Views → Layouts: uses · Shares private authenticated layouts
- Public Views → Layouts: uses · Shares public and base layouts
- Auth Views → Static Assets: loads · Uses CSS, JS, and localized assets
- Private Views → Static Assets: loads · Uses shared static UI assets
- Contracts → Domain: defines · Interfaces operate on core entities and enums
- Contracts → Result: returns · Service and repository operations use result objects
- Errors → Result: maps to · Exceptions support structured failure handling
- User Repos → Contracts: implements · Concrete repositories satisfy core interfaces
- Security Services → Contracts: implements · Concrete security services satisfy core interfaces
- SQL Factory → Contracts: implements · SQL connection factory fulfills database contract
- User Repos → SQL Factory: opens · Repositories acquire connections through the factory
- Security Services → Domain: works with · Hashing and MFA services operate on user-related domain data
- Auth Controller → Errors: handles · Controller flow can surface domain exceptions
- User Controller → Domain: uses · Displays and updates account state concepts