# phamminhkha0710/doanweb architecture

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

- Interactive diagram: https://gitdiagram.com/phamminhkha0710/doanweb
- Repository: https://github.com/phamminhkha0710/doanweb

## Overview

##### Main Components

a. Frontend Client:
- Views – Represented by Views folder and associated ViewModels, where UI is rendered (HTML, Razor pages).
- Static Assets – Represented by the wwwroot directory (CSS, JavaScript, Images, etc.).
- Client-side Libraries – Integration of Bootstrap, jQuery, Marked.js, PrismJS, and SignalR-related scripts.

b. Backend Server:
- Controllers – In the Controllers directory (including API sub-controllers) that receive HTTP requests, manage user actions (authentication, Q&A actions, repository management, etc.).
- Services – Encapsulated business logic in Services (e.g., AnswerService, BadgeService, NotificationService) that handle application-specific functionality.
- Repositories – Interfaces and concrete implementations (in the Repositories folder) to encapsulate data access, following the repository pattern.
- Models – Data and domain models (in the Models folder) representing entities like User, Question, Answer, Repository, Vote, etc.
- Database – Represented by Entity Framework Core migrations (Migrations folder) and the SQL Server backend configured via the appsettings.json.
- Extensions and Middleware – Application startup configurations and middleware components (Extensions and Middleware folders) that extend ASP.NET Core’s dependency injection and request pipeline.

c. Real-time & Communication Layer:
- Hubs – SignalR hubs (in the Hubs folder) for real-time features such as live notifications, chat, and activity updates.

d. External Integration Components:
- GitIntegration – Subsystem responsible for integrating Gitea for managing code repositories. This module communicates with the external Gitea API and handles tasks like user sync and repository mapping.

##### Relationships and Data Flow

- Clients (web browsers) interact with the system by making HTTP requests to the Controllers.
- Controllers pass requests through middleware pipelines, leveraging Filters (e.g., for user information) and Extensions (for dependency injection, database migrations, etc.).
- Controllers call Services to execute business logic. For example, a QuestionsController will call QuestionService to process question submissions.
- Services communicate with the Database through Repository patterns. For example, UserService uses UserRepository to manage persistence.
- Real-time communication is managed by SignalR Hubs that push notifications, update views, or relay chat messages to connected clients.
- The GitIntegration module interacts with Gitea’s API to sync repository information and manage source code operations.
- All components consume shared Models (domain data) and use ViewModels to format data for presentation.

##### Architectural Patterns and Key Design Principles

- MVC (Model-View-Controller) – Clearly separates presentation, application logic, and data.
- Dependency Injection – Framework extensions and service configurations are used extensively (see Extensions folder).
- Repository Pattern – Data access logic is abstracted via repository interfaces and implementations.
- Real-Time Eventing – SignalR is used to deliver real-time notifications, chat, and updates.
- Integration Layer – GitIntegration abstracts external API interactions with Gitea.
- Layered Architecture – Clean separation between the presentation layer, service layer, repository/data layer, and external services.

a. Client Layer:
- Inside, note “Razor Views, HTML, CSS, JavaScript (Bootstrap, jQuery, SignalR)”

b. Backend API & Logic Layer:
- “Models” as a shared entity across Services and Repositories.

c. Real-Time Communication:

d. External Integration:

e. Infrastructure Components:

##### Final Details and Labeling

- That each component is clearly labeled with its function.
- From Client → Controllers (HTTP Requests)
- From Controllers → Services (Business Logic Invocations)
- From Services → Repositories (Data Access Requests)
- Bi-directional for SignalR Hubs (showing real-time push/pull)
- From GitIntegration → Gitea API (external call)
- Notes where necessary to call out key technologies (ASP.NET Core 9.0, Entity Framework Core, SignalR, etc.) and design choices (Repository Pattern, Dependency Injection).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    A["Web Browser/Client\n(Razor Views, HTML, CSS, JavaScript)"]:::client

    %% Frontend Components
    subgraph "Frontend"
        B["Views"]:::frontend
        C["Static Assets"]:::frontend
    end

    %% Backend API & Logic Layer
    subgraph "Backend"
        D["Controllers"]:::backend
        E["Services"]:::backend
        F["Repositories"]:::backend
        G["Models"]:::shared
        H["Database (SQL Server)"]:::database
    end

    %% Infrastructure Components
    I["Middleware & Extensions"]:::infrastructure

    %% Real-Time Communication
    J["SignalR Hubs"]:::realTime

    %% External Integration Components
    subgraph "External Integration"
        K["GitIntegration Module"]:::external
        L["Gitea API"]:::externalAPI
    end

    %% Connections and Data Flow
    A -->|"HTTPRequest"| D
    D -->|"BusinessLogicCall"| E
    E -->|"DataAccess"| F
    F -->|"CRUDOperations"| H
    E ---|"Uses"| G
    F ---|"Uses"| G
    I ---|"Wraps Pipeline"| D
    D ---|"RealTimeUsage"| J
    E ---|"PushNotifications"| J
    D -->|"RepoSync"| K
    K -->|"ExternalCall"| L

    %% Click Events
    click B "https://github.com/phamminhkha0710/doanweb/tree/main//Views folder"
    click C "https://github.com/phamminhkha0710/doanweb/tree/main//wwwroot folder"
    click D "https://github.com/phamminhkha0710/doanweb/tree/main//Controllers folder"
    click E "https://github.com/phamminhkha0710/doanweb/tree/main//Services folder"
    click F "https://github.com/phamminhkha0710/doanweb/tree/main//Repositories folder"
    click G "https://github.com/phamminhkha0710/doanweb/tree/main//Models folder"
    click H "https://github.com/phamminhkha0710/doanweb/tree/main//Migrations folder"
    click I "https://github.com/phamminhkha0710/doanweb/tree/main//Extensions folder"
    click J "https://github.com/phamminhkha0710/doanweb/tree/main//Hubs folder"
    click K "https://github.com/phamminhkha0710/doanweb/tree/main//GitIntegration folder"

    %% Styles
    classDef client fill:#ffd700,stroke:#000,stroke-width:2px;
    classDef frontend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef backend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef shared fill:#ffb6c1,stroke:#000,stroke-width:2px;
    classDef database fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef realTime fill:#40e0d0,stroke:#000,stroke-width:2px;
    classDef external fill:#ff6347,stroke:#000,stroke-width:2px;
    classDef externalAPI fill:#ff4500,stroke:#000,stroke-width:2px;
```
