# hodaifa-ech/smartmarketplace architecture

> Architecture diagram of the GitHub repository hodaifa-ech/smartmarketplace, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hodaifa-ech/smartmarketplace
- Repository: https://github.com/hodaifa-ech/smartmarketplace

## Overview

##### Project type and purpose
- This is a full-stack ASP.NET Core MVC web application (“Smart Marketplace – AI Mission Generator”).
- Purpose: take a natural-language prompt, call the Groq API (Llama 3) to generate a structured mission brief, persist it in MySQL via Entity Framework Core, and display results/history in a Bootstrap UI.

##### File structure
- Top-level solution file (`SmartMarketplace.sln`) and a single web project folder (`SmartMarketplace.Web`).
- Under `SmartMarketplace.Web`:
- Controllers (HomeController) – handles HTTP requests & responses
- Services (IGroqService/GroqService) – encapsulates AI API calls
- Data (ApplicationDbContext + Migrations) – EF Core context & database migrations
- Models (Mission, ErrorViewModel) – domain entities & view models
- Views / wwwroot – Razor pages + static assets (Bootstrap, jQuery, custom CSS/JS)
- `Program.cs` & `appsettings.json` – application startup, configuration, DI, middleware

##### Extract architecture insights from README
- MVC pattern on the backend
- Layered design: Presentation (views/controllers) → Application logic (services) → Data access (EF Core)
- External dependency: Groq API (HTTP REST)
- Persistence: MySQL via EF Core
- Frontend: responsive UI built with Bootstrap 5 + JavaScript

a. Components:
- Client (Browser) – UI built with Razor + Bootstrap, JS for modals/history
- Web Server – ASP.NET Core MVC application
– Controllers (HTTP endpoints)
– Services (AI integration)
– Data Access Layer (EF Core, DbContext + Migrations)
- External AI Service – Groq API / Llama 3 model
- Database – MySQL instance

b. Relationships & data flows:
1. Client → Web Server: HTTP GET/POST for generator, history, detail
2. Web Server → Groq API: HTTPS POST with PromptRequest JSON → returns structured mission JSON
3. Web Server → Database: EF Core performs SQL CRUD on Missions table
4. Web Server → Client: returns rendered Razor views or JSON for modals

c. Architectural patterns & principles:
- MVC separation of concerns
- Service abstraction (IGroqService injected into controllers)
- Repository/UnitOfWork implicit via DbContext
- Single responsibility per layer
- Configuration via `appsettings.json` + environment overrides

d. Key technologies & libraries:
- ASP.NET Core 8.0, MVC
- Entity Framework Core 8.0, MySQL provider
- Groq API client (`GroqService`)
- Bootstrap 5, jQuery, Font Awesome
- Dependency Injection (built into ASP.NET Core)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Browser<br/>(Razor + Bootstrap + JS)"]:::client

    %% Backend Server
    subgraph "ASP.NET Core MVC (Server)"
        direction TB

        subgraph "Presentation Layer"
            direction TB
            HomeController["HomeController"]:::controller
            Views["Razor Views + wwwroot"]:::views
        end

        subgraph "Application Layer"
            direction TB
            IGroqService["IGroqService"]:::service
            GroqService["GroqService"]:::service
        end

        subgraph "Data Layer"
            direction TB
            ApplicationDbContext["ApplicationDbContext"]:::dbctx
            Migrations["EF Core Migrations"]:::migrations
        end

        subgraph "Models"
            direction TB
            Mission["Mission<br/>(Domain Entity)"]:::model
            ErrorViewModel["ErrorViewModel"]:::model
        end

        subgraph "ViewModels"
            direction TB
            MissionViewModel["MissionViewModel"]:::vm
            PromptRequest["PromptRequest"]:::vm
        end
    end

    %% External Services & DB
    GroqAPI["Groq API<br/>(Llama 3)"]:::api
    MySQL[(MySQL Database)]:::db

    %% Flows
    Client -->|"HTTP GET/POST"| HomeController
    HomeController -->|"calls GenerateMissionAsync(prompt)"| GroqService
    GroqService -->|"POST PromptRequest JSON"| GroqAPI
    GroqAPI -->|"returns mission JSON"| GroqService
    GroqService -->|"returns structured data"| HomeController
    HomeController -->|"SaveAsync(mission)"| ApplicationDbContext
    Migrations -->|"define schema"| MySQL
    ApplicationDbContext -->|"SQL CRUD"| MySQL
    HomeController -->|"renders views"| Views
    Views -->|"HTML/JSON responses"| Client

    %% Click Events
    click HomeController "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/Controllers/HomeController.cs"
    click IGroqService "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/Services/IGroqService.cs"
    click GroqService "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/Services/GroqService.cs"
    click ApplicationDbContext "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/Data/ApplicationDbContext.cs"
    click Migrations "https://github.com/hodaifa-ech/smartmarketplace/tree/main/SmartMarketplace.Web/Migrations/"
    click Mission "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/Models/Mission.cs"
    click ErrorViewModel "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/Models/ErrorViewModel.cs"
    click MissionViewModel "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/ViewModels/MissionViewModel.cs"
    click PromptRequest "https://github.com/hodaifa-ech/smartmarketplace/blob/main/SmartMarketplace.Web/ViewModels/PromptRequest.cs"
    click Views "https://github.com/hodaifa-ech/smartmarketplace/tree/main/SmartMarketplace.Web/Views/"
    click Client "https://github.com/hodaifa-ech/smartmarketplace/tree/main/SmartMarketplace.Web/wwwroot/"
    click MySQL "https://github.com/hodaifa-ech/smartmarketplace/blob/main/appsettings.json"

    %% Styles
    classDef client fill:#cccccc,stroke:#333,stroke-width:1px
    classDef controller fill:#cce5ff,stroke:#004085,stroke-width:1px
    classDef views fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef service fill:#d1ecf1,stroke:#0c5460,stroke-width:1px
    classDef dbctx fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef migrations fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef model fill:#f8d7da,stroke:#721c24,stroke-width:1px
    classDef vm fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef api fill:#ffe5b4,stroke:#cc8400,stroke-width:1px
    classDef db fill:#c3e6cb,stroke:#155724,stroke-width:1px,stroke-dasharray: 5 5
```
