# datpham0412/swe30003-assignment3-yourlocalshop architecture

> Architecture diagram of the GitHub repository datpham0412/swe30003-assignment3-yourlocalshop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/datpham0412/swe30003-assignment3-yourlocalshop
- Repository: https://github.com/datpham0412/swe30003-assignment3-yourlocalshop

## Overview

##### Project type and purpose
- This is a full-stack e-commerce/order-management system.
- Frontend: Next.js (React) app under /frontend, delivering catalog, cart, checkout, admin dashboard, reports, etc.
- Backend: ASP.NET Core Web API (Controllers + Managers + EF Core DbContext) exposing REST endpoints for auth, products, inventory, cart, orders, invoices, payments, shipments, sales reports.
- Data persistence: Relational database via Entity Framework Core and migrations.
- External integrations: Email sender/notifier (SMTP or service), payment processing (likely external gateway).

##### File structure
- Top-level:
- Controllers: HTTP API endpoints (AuthController, CatalogueController, InventoryController, …)
- Managers: business-logic services (AccountManager)
- Data: AppDbContext (EF Core)
- Migrations: EF Core schema versioning
- Models: domain entities (Account, Product, ShoppingCart, Order, Invoice, Payment, Shipment, SalesReport, etc.)
- Program.cs + appsettings.json: ASP.NET Core startup & configuration
- frontend/: Next.js application (app directory with page.tsx routes, shared components, utils, CSS, config)

##### README
- Confirms the split into two distinct runtime processes communicating over HTTP.

##### Main components & relationships
a. Components
- User’s browser (React/Next.js)
- Next.js frontend (UI Layer + API client)
- ASP.NET Core Web API
– Controllers (Auth, Catalogue, Inventory, Cart, Order, Invoice, Payment, Shipment, SalesReport)
– Managers (business logic)
– AppDbContext (EF Core ORM)
- Database (SQL Server / PostgreSQL / etc.)
- External services:
– Email service (SMTP or email-API) via EmailSender/EmailNotifier
– Payment gateway (credit-card processor or similar)
b. Relationships & interactions
- Browser ↔ Next.js pages/components (React hydration, SSR)
- Next.js → Web API endpoints (HTTP REST calls)
- Web API Controllers → Managers → AppDbContext → Database (CRUD)
- Web API → Payment gateway (HTTP) for /payments/process
- Web API → Email service for order confirmation, shipment notices
c. Architectural patterns & design principles
- Layered architecture: Presentation (Next.js), API (Controllers), Business (Managers), Data (EF Core)
- Use of DTOs to decouple API contract from domain models
- EF Core code-first with migrations for schema evolution
- Single API surface for web and mobile clients
d. Key technologies
- Frontend: Next.js 13 (app router), React, TypeScript
- Backend: .NET 7+, ASP.NET Core Web API, EF Core, C#
- Database: Relational (configured via AppDbContext + migrations)
- Infra: appsettings.json, launchSettings.json for env config

##### Detailed focus points
- Major API controller group as its own component or combine related ones under a single “Feature API” cluster.
- How DTOs flow between frontend API client and Controllers, then map to Models and persist via EF Core.
- Email notification flow triggered by order/invoice shipment events.
- Payment processing call chain inside the API layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User layer
    Browser["User Browser"]:::frontend

    %% Frontend Layer
    subgraph "Next.js Frontend" 
        direction TB
        SSR["Server-Rendered Pages"]:::frontend
        CSR["Client-Side Components"]:::frontend
        APIClient["API Client"]:::frontend
    end

    %% Backend Layer
    subgraph "ASP.NET Core Web API"
        direction TB
        %% Controllers
        subgraph "Controllers"
            direction TB
            AuthCtrl["AuthController"]:::backend
            CatalogueCtrl["CatalogueController"]:::backend
            InventoryCtrl["InventoryController"]:::backend
            CartCtrl["ShoppingCartController"]:::backend
            OrderCtrl["OrderController"]:::backend
            InvoiceCtrl["InvoiceController"]:::backend
            ShipmentCtrl["ShipmentController"]:::backend
            SalesReportCtrl["SalesReportController"]:::backend
            BaseCtrl["BaseController"]:::backend
        end
        %% Business Logic
        AccountMgr["AccountManager"]:::backend

        %% Data Access
        DbContext["AppDbContext (EF Core)"]:::backend
    end

    %% Database
    SQLDatabase["Relational Database"]:::database

    %% External Services
    PaymentGateway["Payment Gateway"]:::external
    EmailService["Email Service"]:::external

    %% Flows
    Browser -->|page requests| SSR
    Browser -->|interactive calls| CSR
    SSR --> APIClient
    CSR --> APIClient
    APIClient -->|REST API calls| AuthCtrl
    APIClient --> CatalogueCtrl
    APIClient --> InventoryCtrl
    APIClient --> CartCtrl
    APIClient --> OrderCtrl
    APIClient --> InvoiceCtrl
    APIClient --> ShipmentCtrl
    APIClient --> SalesReportCtrl

    %% Internal API flow
    AuthCtrl -->|"calls"| AccountMgr
    CatalogueCtrl --> AccountMgr
    InventoryCtrl --> AccountMgr
    CartCtrl --> AccountMgr
    OrderCtrl --> AccountMgr
    InvoiceCtrl --> AccountMgr
    ShipmentCtrl --> AccountMgr
    SalesReportCtrl --> AccountMgr

    AccountMgr --> DbContext
    DbContext --> SQLDatabase

    %% External integrations
    InvoiceCtrl -->|process payment| PaymentGateway
    InvoiceCtrl -->|send invoice notification| EmailService
    ShipmentCtrl -->|send shipment notice| EmailService

    %% Click events
    click Browser "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/tree/main/frontend/"
    click AuthCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/AuthController.cs"
    click CatalogueCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/CatalogueController.cs"
    click InventoryCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/InventoryController.cs"
    click CartCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/ShoppingCartController.cs"
    click OrderCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/OrderController.cs"
    click InvoiceCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/InvoiceController.cs"
    click ShipmentCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/ShipmentController.cs"
    click SalesReportCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/SalesReportController.cs"
    click BaseCtrl "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Controllers/BaseController.cs"
    click APIClient "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/tree/main/frontend/"
    click AccountMgr "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Managers/AccountManager.cs"
    click DbContext "https://github.com/datpham0412/swe30003-assignment3-yourlocalshop/blob/main/Data/AppDbContext.cs"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0066CC,color:#000;
    classDef backend fill:#DFF2D8,stroke:#2C662D,color:#000;
    classDef database fill:#FFE5CC,stroke:#CC6600,color:#000;
    classDef external fill:#FFD6D6,stroke:#CC0000,color:#000;
```
