# ahmadmdabit/exchange architecture

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

- Interactive diagram: https://gitdiagram.com/ahmadmdabit/exchange
- Repository: https://github.com/ahmadmdabit/exchange

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with C# ASP.NET Core (3.1) on the server side and Vue.js (2) on the client side.
- It follows an N-Tier architecture with the following layers: API (presentation/API layer), BLL (business logic), DAL (data access), Entities (domain models) and Common (shared code).
- It uses MySQL as the primary data store, Redis for caching, and a separate console application (“RedisUpdate”) to refresh cache every 250 ms.

##### File Structure
- Top-level solution “Exchange.sln” orchestrates five C# projects: API, BLL, Common, DAL, Entities.
- API/ folder contains ASP.NET Core controllers under Controllers, middleware (JwtMiddleware), attributes, models (ApiResult, ErrorResult), Startup.cs and Program.cs.
- BLL/ implements business services (ExchangeInfoBusiness, UserBusiness) based on abstractions IBusiness and BaseBusiness.
- DAL/ implements repository pattern (IRepository, BaseRepository) and DatabaseContext under DataContext for EF Core or MySQL context.
- Entities/ holds domain models ExchangeInfo, User and base entity abstractions.
- Common/ holds shared attributes, helpers (AppSettings, RedisHelper), extensions.
- RedisUpdate/ is a console app that runs in the background to push updates into Redis.
- ui/ is a Vue.js SPA project with its own package.json, main.js, App.vue, components, public/index.html.
- exchange.sql provides initial MySQL schema.

##### README Insights
- Confirms N-Tier (separation of concerns), technology stack (MySQL, Redis, ASP.NET Core, Vue.js).
- Mentions a background console app for cache updates.

a. Main Components
- Client (Vue.js SPA)
- API Layer (ASP.NET Core Controllers + Middleware)
- Business Logic Layer (BLL services)
- Data Access Layer (DAL repositories + DbContext)
- Database (MySQL)
- Cache (Redis)
- Background Service (RedisUpdate console app)
- Shared/Common Utilities (Common project)
b. Relationships and Interactions
1. User’s browser ↔ Client (HTTP/HTTPS)
2. Client → API Controllers (REST calls)
3. Controllers → BLL services
4. BLL → DAL repositories
5. DAL → MySQL (CRUD)
6. BLL/DAL → Redis via RedisHelper for caching read/write
7. RedisUpdate → Redis (periodic updates)
8. Middleware/Attributes in API handle JWT authentication, authorization before controller execution
c. Architectural Patterns & Principles
- N-Tier layering: Presentation → Business → DataAccess
- Repository pattern in DAL
- Dependency Injection managed in Startup.cs
- JWT-based auth middleware
- Separation of cross-cutting concerns in Common (attributes, helpers)
- Background processing via standalone console app
d. Key Technologies/Frameworks
- ASP.NET Core 3.1 (API layer, Startup pipeline)
- Entity Framework Core or MySQL connector (in DAL/DataContext)
- Redis .NET client (in Common/Helpers)
- Vue.js 2 (UI)
- JSON Web Tokens for auth

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Side"
        Client["Vue.js SPA Client"]:::frontend
    end

    subgraph "Server Side"
        API["ASP.NET Core API"]:::api
        BLL["Business Logic Layer"]:::bll
        DAL["Data Access Layer"]:::dal
        Entities["Domain Entities"]:::entities
        Common["Common Utilities"]:::common
    end

    subgraph "Infrastructure"
        MySQL[(MySQL Database)]:::db
        Redis[(Redis Cache)]:::cache
        SQL["exchange.sql"]:::script
    end

    RedisUpdate["RedisUpdate Service"]:::service

    Client <-->|"HTTP/HTTPS"| API
    API -->|"Executes Services"| BLL
    BLL -->|"Uses Repositories"| DAL
    DAL -->|"CRUD Operations"| MySQL
    BLL -.->|"Cache Read/Write"| Redis
    DAL -.->|"Cache Read/Write"| Redis
    RedisUpdate -.->|"Refreshes Cache"| Redis
    API -->|"DI, Middleware, Helpers"| Common
    BLL -->|"Helpers, Settings"| Common
    DAL -->|"Helpers, Settings"| Common
    DAL -->|"Uses Models"| Entities
    BLL -->|"Uses Models"| Entities

    click Client "https://github.com/ahmadmdabit/exchange/tree/master/ui/"
    click API "https://github.com/ahmadmdabit/exchange/tree/master/API/"
    click BLL "https://github.com/ahmadmdabit/exchange/tree/master/BLL/"
    click DAL "https://github.com/ahmadmdabit/exchange/tree/master/DAL/"
    click Entities "https://github.com/ahmadmdabit/exchange/tree/master/Entities/"
    click Common "https://github.com/ahmadmdabit/exchange/tree/master/Common/"
    click RedisUpdate "https://github.com/ahmadmdabit/exchange/tree/master/RedisUpdate/"
    click SQL "https://github.com/ahmadmdabit/exchange/blob/master/exchange.sql"

    classDef frontend fill:#CEF,stroke:#036,stroke-width:1px
    classDef api fill:#FCF,stroke:#930,stroke-width:1px
    classDef bll fill:#CFC,stroke:#393,stroke-width:1px
    classDef dal fill:#CFF,stroke:#099,stroke-width:1px
    classDef entities fill:#FCC,stroke:#933,stroke-width:1px
    classDef common fill:#EEE,stroke:#666,stroke-width:1px
    classDef service fill:#FDC,stroke:#F90,stroke-width:1px
    classDef db fill:#CCF,stroke:#36F,stroke-width:1px
    classDef cache fill:#FFC,stroke:#F90,stroke-width:1px
    classDef script fill:#EEE,stroke:#333,stroke-width:1px
```
