Skip to content

Latest commit

 

History

History
182 lines (168 loc) · 10.9 KB

File metadata and controls

182 lines (168 loc) · 10.9 KB

Architecture Overview

System Design

┌─────────────────────────────────────────────────────────────────┐
│                         CLIENT BROWSER                          │
│                    (Next.js Frontend)                           │
│         ┌──────────────────────────────────────────┐            │
│         │  Dashboard | Portfolio | Markets | Auth  │            │
│         │     Charts | Holdings | Transactions     │            │
│         └──────────────────────────────────────────┘            │
└────────────────────────────┬────────────────────────────────────┘
                             │ HTTPS/TLS
                             │ REST API
┌────────────────────────────────────────────────────────────────┐
│                    API GATEWAY / NGINX                         │
│           (Reverse Proxy, SSL, Rate Limiting)                  │
└────────────────────┬─────────────────────────────────────────┘
                     │
┌────────────────────────────────────────────────────────────────┐
│              NODE.JS/EXPRESS BACKEND (Cluster)                 │
│         ┌─────────────────────────────────────┐                │
│         │  Authentication Routes              │                │
│         │  ├─ /api/auth/register              │                │
│         │  ├─ /api/auth/login                 │                │
│         │  └─ /api/auth/profile               │                │
│         ├─────────────────────────────────────┤                │
│         │  Portfolio Routes                   │                │
│         │  ├─ /api/portfolio                  │                │
│         │  ├─ /api/portfolio/buy              │                │
│         │  └─ /api/portfolio/transactions     │                │
│         ├─────────────────────────────────────┤                │
│         │  Market Routes                      │                │
│         │  ├─ /api/market/prices              │                │
│         │  └─ /api/market/trending            │                │
│         └─────────────────────────────────────┘                │
│                                                                │
│  Middleware Layer                                              │
│  ├─ Authentication (JWT)                                       │
│  ├─ Validation (express-validator)                             │
│  ├─ Error Handling                                             │
│  ├─ Rate Limiting                                              │
│  └─ Security (Helmet, CORS)                                    │
└──────────────────────┬─────────────────────────────────────────┘
                       │
        ┌──────────────┼──────────────────┐
        │              │                  │
┌───────▼──────┐  ┌────▼────────┐  ┌────▼──────────┐
│              │  │             │  │               │
│  MongoDB     │  │  PostgreSQL │  │    Redis      │
│              │  │             │  │  (Cache)      │
│ Collections: │  │  Tables:    │  │               │
│ ├─ users     │  │ ├─ users    │  │ ├─ sessions  │
│ ├─ portfolio │  │ ├─ portfolio│  │ ├─ prices    │
│ └─ transactions  │ └─ transactions  │ └─ quotes (soon)
└──────────────┘  └────────────┘  └────────────────┘

Data Flow

Authentication Flow

Client                Backend               Database
  │                     │                      │
  ├─ register/login ──→ │                      │
  │                     ├─ validate input      │
  │                     │                      │
  │                     ├─ hash password       │
  │                     │                      │
  │                     ├─ create/find user ──→│
  │                     │                      │
  │  ← JWT token ───── │←─ user data ────────┤
  │                     │                      │

Portfolio Update Flow

Client              Backend           Database          External API
  │                   │                  │                   │
  ├─ buy asset ──→    │                  │                   │
  │                   ├─ validate token  │                   │
  │                   │                  │                   │
  │                   ├─ verify balance  │                   │
  │                   │                  │                   │
  │                   ├─ fetch prices ─────────────────→    │
  │                   │                  │     ←─ prices ───┤
  │                   │                  │                   │
  │                   ├─ create holding ─→                   │
  │                   │                  │                   │
  │  ← success ───── │←─ portfolio data ─────────────────────┤
  │                   │                  │                   │

Security Layers

┌─ HTTPS/TLS ────────────────────────────────────┐
│                                                 │
│  ┌─ CORS Policy ────────────────────────────┐  │
│  │                                           │  │
│  │  ┌─ Authentication (JWT) ──────────────┐ │  │
│  │  │                                      │ │  │
│  │  │  ┌─ Input Validation ──────────────┐│ │  │
│  │  │  │                                  ││ │  │
│  │  │  │  ┌─ Database Queries ──────────┐││ │  │
│  │  │  │  │ (Parameterized)             │││ │  │
│  │  │  │  └──────────────────────────────┘││ │  │
│  │  │  │                                  ││ │  │
│  │  │  └──────────────────────────────────┘│ │  │
│  │  │                                      │ │  │
│  │  └──────────────────────────────────────┘ │  │
│  │                                           │  │
│  └───────────────────────────────────────────┘  │
│                                                 │
└─────────────────────────────────────────────────┘

Deployment Architecture

                    ┌─────────────────┐
                    │  DNS Provider   │
                    └────────┬────────┘
                             │
                    ┌────────▼────────┐
                    │ CDN (Cloudflare)│
                    └────────┬────────┘
                             │
        ┌────────────────────┼────────────────────┐
        │                    │                    │
   ┌────▼──────┐       ┌────▼───────┐     ┌─────▼──────┐
   │ Vercel    │       │ Heroku     │     │ AWS EC2    │
   │(Frontend) │       │(Backend)   │     │(Backup)    │
   └───────────┘       └────────────┘     └────────────┘
           │                  │                   │
           └──────────────────┼───────────────────┘
                              │
                    ┌─────────▼─────────┐
                    │   AWS S3 Backup   │
                    │   Database Backup │
                    └───────────────────┘

Component Communication

Frontend Components

App (Root)
├── Layout
│   ├── Sidebar (Navigation)
│   └── Navbar (User Info)
├── Dashboard (Main Page)
│   ├── PortfolioOverview
│   ├── PortfolioChart
│   ├── HoldingsTable
│   └── RecentTransactions
├── Portfolio Page
├── Markets Page
└── Auth Pages
    ├── Login
    └── Register

Backend Modules

Server (Express)
├── Database Connection
├── Middleware Stack
│   ├── Authentication
│   ├── CORS
│   ├── Helmet
│   └── Error Handler
└── Routes
    ├── /auth
    ├── /portfolio
    └── /market

This architecture is scalable, secure, and production-ready.