# mohamed-samehh/financial-advisor architecture

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

- Interactive diagram: https://gitdiagram.com/mohamed-samehh/financial-advisor
- Repository: https://github.com/mohamed-samehh/financial-advisor

## Overview

##### Project type and purpose
- This is a multi‐platform financial advisor system.
- Two client UIs: an Angular SPA for web, a Flutter app for mobile/desktop/web.
- A primary backend in Laravel (REST API, business data, authentication, email).
- A separate Flask microservice for machine learning (model inference & data analysis).
- A relational database (MySQL/PostgreSQL) for user/finance data, plus email/queue services.

##### File structure
- Top-level “Angular” folder: an Angular 14+ web client (components for login, dashboard, expenses, chatbot, etc.).
- “Flutter”: cross-platform mobile & desktop client. Routes, screens mirror Angular features; calls the same REST API.
- “Laravel”: core API service (Controllers, Models, Migrations, Middleware, Mail, Routes). Implements authentication, budgeting, expenses, goals, categories, chatbot proxy.
- “Flask”: lightweight ML microservice (app.py, business_logic.py, ml_models.py). Exposes endpoints consumed by Laravel or directly by frontends for AI predictions.

##### README
- Confirms: personalized financial recommendations via AI/ML.
- Backends must orchestrate data flows between user data in DB and ML models.

a. Main components
- Clients: Angular Web App; Flutter Mobile/Desktop App
- API Gateway/Backend: Laravel
- ML Service: Flask microservice
- Persistence: Relational Database
- External services: SMTP/email provider; (optionally) third-party market/stock data APIs
- Infrastructure: Load balancer, Docker/K8s (if used), CI/CD pipeline

b. Relationships & interactions
1. User interacts with Angular or Flutter → sends HTTPS requests to Laravel API.
2. Laravel authenticates (Sanctum/JWT), reads/writes DB, queues emails.
3. For financial insights, Laravel forwards relevant data → Flask ML microservice → returns predictions/analysis.
4. Laravel aggregates ML response + database records → JSON → clients.
5. Laravel sends emails via SMTP service.

c. Architectural patterns & principles
- Microservices: separate ML logic (Flask) from business logic (Laravel).
- MVC in Laravel: Controllers → Models → Migrations.
- Modular frontends: Angular modules, Flutter screens and services.
- Service layer in clients: api_service.ts, auth_service.dart.
- Security: API Guard (Angular auth.guard), Laravel middleware for CORS/auth.

d. Key technologies & libraries
- Frontends: Angular, TypeScript, RxJS; Flutter, Dart.
- Backend: Laravel (PHP 8+, Sanctum, Eloquent ORM, Mail), Flask (Python 3, scikit-learn / TensorFlow).
- Database: MySQL or PostgreSQL.
- Dev & CI: Docker, Git, GitHub Actions, Composer, npm, pub.

##### Elements
- Blue for frontend clients
- Green for core backend (Laravel)
- Orange for ML microservice (Flask)
- Gray for infrastructure/external services
- Clouds for external services
- Rectangles for applications/microservices

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        AngularApp["Angular Web App"]:::frontend
        AppComponent["AppComponent"]:::frontend
        AppRoutes["AppRoutes"]:::frontend
        ApiService["ApiService"]:::frontend
        AuthService["AuthService"]:::frontend
        AuthGuard["AuthGuard"]:::frontend

        FlutterApp["Flutter Mobile/Desktop App"]:::frontend
        FlutterApiService["API Service"]:::frontend
        FlutterAuthService["Auth Service"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        LaravelApp["Laravel API Service"]:::backend
        Controllers["Controllers"]:::backend
        Models["Models"]:::backend
        Routes["API Routes"]:::backend
        Middleware["Middleware"]:::backend
        Mailables["Mailables"]:::backend
    end

    %% ML Service Layer
    subgraph "ML Service Layer"
        direction TB
        FlaskApp["Flask ML Microservice"]:::ml
        BusinessLogic["Business Logic"]:::ml
        MLModels["ML Models"]:::ml
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB["Relational Database"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        EmailProvider["SMTP / Email Provider"]:::external
        MarketAPI["Market/Stock Data API"]:::external
    end

    %% Connections
    AngularApp -->|"HTTPS REST"| LaravelApp
    FlutterApp -->|"HTTPS REST"| LaravelApp
    LaravelApp -->|"SQL queries"| DB
    LaravelApp -->|"HTTP /predict"| FlaskApp
    FlaskApp -->|"JSON predictions"| LaravelApp
    LaravelApp -->|"SMTP"| EmailProvider
    LaravelApp -->|"HTTP"| MarketAPI

    %% Click Events
    click AngularApp "https://github.com/mohamed-samehh/financial-advisor/tree/master/Angular/"
    click AppComponent "https://github.com/mohamed-samehh/financial-advisor/blob/master/Angular/src/app/app.component.ts"
    click AppRoutes "https://github.com/mohamed-samehh/financial-advisor/blob/master/Angular/src/app/app.routes.ts"
    click ApiService "https://github.com/mohamed-samehh/financial-advisor/blob/master/Angular/src/app/api.service.ts"
    click AuthService "https://github.com/mohamed-samehh/financial-advisor/blob/master/Angular/src/app/auth.service.ts"
    click AuthGuard "https://github.com/mohamed-samehh/financial-advisor/blob/master/Angular/src/app/auth.guard.ts"
    click FlutterApp "https://github.com/mohamed-samehh/financial-advisor/tree/master/Flutter/"
    click FlutterApiService "https://github.com/mohamed-samehh/financial-advisor/blob/master/Flutter/lib/services/api_service.dart"
    click FlutterAuthService "https://github.com/mohamed-samehh/financial-advisor/blob/master/Flutter/lib/services/auth_service.dart"
    click LaravelApp "https://github.com/mohamed-samehh/financial-advisor/tree/master/Laravel/"
    click FlaskApp "https://github.com/mohamed-samehh/financial-advisor/tree/master/Flask/"
    click BusinessLogic "https://github.com/mohamed-samehh/financial-advisor/blob/master/Flask/business_logic.py"
    click MLModels "https://github.com/mohamed-samehh/financial-advisor/blob/master/Flask/ml_models.py"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0062cc,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef ml fill:#fff3cd,stroke:#856404,color:#856404
    classDef database fill:#e2e3e5,stroke:#6c757d,color:#383d41
    classDef external fill:#f0f0f0,stroke:#adb5bd,color:#495057
```
