feat: Multi-user system with PostgreSQL - WIP temporary save
This commit is contained in:
@@ -261,7 +261,7 @@ QuantDinger provides a unified data interface across multiple markets:
|
||||
QuantDinger’s agents don’t start from scratch every time. The backend includes a **local memory store** and an optional **reflection/verification loop**:
|
||||
|
||||
- **What it is**: RAG-style experience retrieval injected into agent prompts (NOT model fine-tuning).
|
||||
- **Where it lives**: Local SQLite files under `backend_api_python/data/memory/` (privacy-first).
|
||||
- **Where it lives**: PostgreSQL database (shared with main data) or local files under `backend_api_python/data/memory/` (privacy-first).
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
@@ -301,7 +301,7 @@ flowchart TB
|
||||
end
|
||||
|
||||
%% ===== 🧠 Memory Layer =====
|
||||
subgraph Memory["🧠 Local SQLite Memory (data/memory/)"]
|
||||
subgraph Memory["🧠 PostgreSQL Memory Store"]
|
||||
M1[("market_analyst")]
|
||||
M2[("fundamental")]
|
||||
M3[("news_analyst")]
|
||||
@@ -356,9 +356,9 @@ Config lives in `.env` (see `backend_api_python/env.example`): `ENABLE_AGENT_MEM
|
||||
|
||||
### 7. Tech Stack
|
||||
|
||||
- **Backend**: Python (Flask) + SQLite + Redis (optional)
|
||||
- **Backend**: Python (Flask) + PostgreSQL + Redis (optional)
|
||||
- **Frontend**: Vue 2 + Ant Design Vue + KlineCharts/ECharts
|
||||
- **Deployment**: Docker Compose
|
||||
- **Deployment**: Docker Compose (with PostgreSQL)
|
||||
|
||||
---
|
||||
|
||||
@@ -441,7 +441,7 @@ All UI elements, error messages, and documentation are fully translated. Languag
|
||||
│ (Flask + strategy runtime) │
|
||||
└──────────────┬──────────────┘
|
||||
│
|
||||
├─ SQLite (quantdinger.db)
|
||||
├─ PostgreSQL (multi-user support)
|
||||
├─ Redis (optional cache)
|
||||
└─ Data providers / LLMs / Exchanges
|
||||
```
|
||||
@@ -466,9 +466,27 @@ All UI elements, error messages, and documentation are fully translated. Languag
|
||||
|
||||
### Option 1: Docker Deployment (Recommended)
|
||||
|
||||
The fastest way to get QuantDinger running.
|
||||
The fastest way to get QuantDinger running with PostgreSQL database and multi-user support.
|
||||
|
||||
#### 1. Start Services
|
||||
#### 1. Configure Environment
|
||||
|
||||
Create a `.env` file in project root:
|
||||
|
||||
```bash
|
||||
# Database Configuration
|
||||
POSTGRES_USER=quantdinger
|
||||
POSTGRES_PASSWORD=your_secure_password
|
||||
POSTGRES_DB=quantdinger
|
||||
|
||||
# Admin Account (created on first startup)
|
||||
ADMIN_USER=admin
|
||||
ADMIN_PASSWORD=your_admin_password
|
||||
|
||||
# Optional: AI Features
|
||||
OPENROUTER_API_KEY=your_api_key
|
||||
```
|
||||
|
||||
#### 2. Start Services
|
||||
|
||||
**Linux / macOS**
|
||||
```bash
|
||||
@@ -486,17 +504,20 @@ Copy-Item backend_api_python\env.example -Destination backend_api_python\.env
|
||||
docker-compose up -d --build
|
||||
```
|
||||
|
||||
#### 2. Configuration & Access
|
||||
|
||||
- **Frontend UI**: http://localhost:8888
|
||||
- **Default Account**: `quantdinger` / `123456`
|
||||
|
||||
> **Note**: For production or AI features, edit `backend_api_python/.env` (add `OPENROUTER_API_KEY`, change passwords) and restart with `docker-compose restart backend`.
|
||||
This will automatically:
|
||||
- Start PostgreSQL database (port 5432)
|
||||
- Initialize database schema
|
||||
- Start backend API (port 5000)
|
||||
- Start frontend (port 8888)
|
||||
- Create admin user from `ADMIN_USER`/`ADMIN_PASSWORD` in `.env`
|
||||
|
||||
#### 3. Access the Application
|
||||
|
||||
- **Frontend UI**: http://localhost
|
||||
- **Frontend UI**: http://localhost:8888
|
||||
- **Backend API**: http://localhost:5000
|
||||
- **Default Account**: Uses `ADMIN_USER` / `ADMIN_PASSWORD` from `.env` (default: `quantdinger` / `123456`)
|
||||
|
||||
> **Note**: For production, edit `backend_api_python/.env` to set strong passwords, add `OPENROUTER_API_KEY` for AI features, then restart with `docker-compose restart backend`.
|
||||
|
||||
#### Docker Commands Reference
|
||||
|
||||
@@ -535,29 +556,30 @@ docker exec -it quantdinger-frontend /bin/sh
|
||||
#### Docker Architecture
|
||||
|
||||
```
|
||||
┌─────────────────┐ ┌─────────────────┐
|
||||
│ Frontend │ │ Backend │
|
||||
│ (Nginx) │────▶│ (Python) │
|
||||
│ Port: 80 │ │ Port: 5000 │
|
||||
└─────────────────┘ └─────────────────┘
|
||||
│ │
|
||||
└───────────────────────┘
|
||||
Docker Network
|
||||
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
||||
│ Frontend │ │ Backend │ │ PostgreSQL │
|
||||
│ (Nginx) │────▶│ (Python) │────▶│ Database │
|
||||
│ Port: 8888 │ │ Port: 5000 │ │ Port: 5432 │
|
||||
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
||||
│ │ │
|
||||
└───────────────────────┴───────────────────────┘
|
||||
Docker Network
|
||||
```
|
||||
|
||||
- **Frontend**: Vue.js app served by Nginx, proxies API requests to backend
|
||||
- **Backend**: Python Flask API service
|
||||
- **Backend**: Python Flask API service with multi-user authentication
|
||||
- **PostgreSQL**: Database for user data, strategies, and trading records
|
||||
|
||||
#### Data Persistence
|
||||
|
||||
The following data is mounted to the host and persists across container restarts:
|
||||
The following data is persisted across container restarts:
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- ./backend_api_python/quantdinger.db:/app/quantdinger.db # Database
|
||||
- ./backend_api_python/logs:/app/logs # Logs
|
||||
- ./backend_api_python/data:/app/data # Data directory
|
||||
- ./backend_api_python/.env:/app/.env # Configuration
|
||||
postgres_data: # PostgreSQL database
|
||||
- ./backend_api_python/logs:/app/logs # Logs
|
||||
- ./backend_api_python/data:/app/data # Data directory
|
||||
- ./backend_api_python/.env:/app/.env # Configuration
|
||||
```
|
||||
|
||||
#### Customization
|
||||
@@ -630,10 +652,17 @@ docker-compose logs backend
|
||||
curl http://localhost:5000/api/health
|
||||
```
|
||||
|
||||
**Database permission issues:**
|
||||
**Database connection issues:**
|
||||
|
||||
```bash
|
||||
chmod 666 backend_api_python/quantdinger.db
|
||||
# Check PostgreSQL container status
|
||||
docker-compose logs postgres
|
||||
|
||||
# Verify PostgreSQL is ready
|
||||
docker exec quantdinger-db pg_isready -U quantdinger
|
||||
|
||||
# Connect to database manually
|
||||
docker exec -it quantdinger-db psql -U quantdinger -d quantdinger
|
||||
```
|
||||
|
||||
**Build failures:**
|
||||
@@ -669,11 +698,14 @@ docker-compose up -d --build
|
||||
#### Backup
|
||||
|
||||
```bash
|
||||
# Backup database
|
||||
cp backend_api_python/quantdinger.db backup/quantdinger_$(date +%Y%m%d).db
|
||||
# Backup PostgreSQL database
|
||||
docker exec quantdinger-db pg_dump -U quantdinger quantdinger > backup/quantdinger_$(date +%Y%m%d).sql
|
||||
|
||||
# Backup configuration
|
||||
cp backend_api_python/.env backup/.env_$(date +%Y%m%d)
|
||||
|
||||
# Restore database (if needed)
|
||||
cat backup/quantdinger_YYYYMMDD.sql | docker exec -i quantdinger-db psql -U quantdinger quantdinger
|
||||
```
|
||||
|
||||
---
|
||||
@@ -684,13 +716,40 @@ cp backend_api_python/.env backup/.env_$(date +%Y%m%d)
|
||||
|
||||
- Python 3.10+ recommended
|
||||
- Node.js 16+ recommended
|
||||
- PostgreSQL 14+ installed and running
|
||||
|
||||
#### 1. Start the backend (Flask API)
|
||||
#### 1. Setup PostgreSQL
|
||||
|
||||
```bash
|
||||
# Create database and user
|
||||
sudo -u postgres psql
|
||||
CREATE DATABASE quantdinger;
|
||||
CREATE USER quantdinger WITH ENCRYPTED PASSWORD 'your_password';
|
||||
GRANT ALL PRIVILEGES ON DATABASE quantdinger TO quantdinger;
|
||||
\q
|
||||
|
||||
# Initialize schema
|
||||
psql -U quantdinger -d quantdinger -f backend_api_python/migrations/init.sql
|
||||
```
|
||||
|
||||
#### 2. Start the backend (Flask API)
|
||||
|
||||
```bash
|
||||
cd backend_api_python
|
||||
pip install -r requirements.txt
|
||||
cp env.example .env # Windows: copy env.example .env
|
||||
```
|
||||
|
||||
Edit `.env` and set:
|
||||
```bash
|
||||
DATABASE_URL=postgresql://quantdinger:your_password@localhost:5432/quantdinger
|
||||
SECRET_KEY=your-secret-key
|
||||
ADMIN_USER=admin
|
||||
ADMIN_PASSWORD=your_admin_password
|
||||
```
|
||||
|
||||
Then start:
|
||||
```bash
|
||||
python run.py
|
||||
```
|
||||
|
||||
@@ -714,7 +773,7 @@ Use `backend_api_python/env.example` as a template. Common settings include:
|
||||
|
||||
- **Auth**: `SECRET_KEY`, `ADMIN_USER`, `ADMIN_PASSWORD`
|
||||
- **Server**: `PYTHON_API_HOST`, `PYTHON_API_PORT`, `PYTHON_API_DEBUG`
|
||||
- **Database**: `SQLITE_DATABASE_FILE` (optional; default is `backend_api_python/data/quantdinger.db`)
|
||||
- **Database**: `DATABASE_URL` (PostgreSQL connection string)
|
||||
- **AI / LLM**: `OPENROUTER_API_KEY`, `OPENROUTER_MODEL`, timeouts
|
||||
- **Web search**: `SEARCH_PROVIDER`, `SEARCH_GOOGLE_*`, `SEARCH_BING_API_KEY`
|
||||
- **Proxy (optional)**: `PROXY_PORT` or `PROXY_URL`
|
||||
|
||||
Reference in New Issue
Block a user