|
| 1 | + |
| 2 | +# 💼 Financial Data API – Local Setup Guide |
| 3 | + |
| 4 | +This guide walks you through running the full-stack project (FastAPI + PostgreSQL + Redis + HTML/CSS/JS frontend) either via **Docker** or **manual setup**. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## 🚀 Quick Start (Docker) |
| 9 | + |
| 10 | +### 1. Clone the Repository |
| 11 | + |
| 12 | +```bash |
| 13 | +git clone https://github.com/your-username/financial-data-api.git |
| 14 | +cd financial-data-api |
| 15 | +``` |
| 16 | + |
| 17 | +### 2. Start Backend Services (FastAPI + PostgreSQL + Redis) |
| 18 | + |
| 19 | +```bash |
| 20 | +docker-compose -f backend/docker-compose.yml up -d |
| 21 | +``` |
| 22 | + |
| 23 | +### 3. Access the Services |
| 24 | + |
| 25 | +* API: [http://localhost:8000](http://localhost:8000) |
| 26 | +* PGAdmin: [http://localhost:5050](http://localhost:5050) |
| 27 | + *Credentials: `admin@admin.com` / `admin`* |
| 28 | +* Frontend: Open `frontend/index.html` in your browser or use `live-server` (see below) |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## 🛠 Manual Setup (Detailed) |
| 33 | + |
| 34 | +### 1. Backend Setup |
| 35 | + |
| 36 | +```bash |
| 37 | +cd backend |
| 38 | + |
| 39 | +# Create virtual environment |
| 40 | +python -m venv venv |
| 41 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 42 | + |
| 43 | +# Install dependencies |
| 44 | +pip install -r requirements.txt |
| 45 | +``` |
| 46 | + |
| 47 | +**Environment Variables (.env)** |
| 48 | + |
| 49 | +```bash |
| 50 | +echo "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/financial_data" > .env |
| 51 | +echo "REDIS_URL=redis://localhost:6379" >> .env |
| 52 | +echo "ALPHA_VANTAGE_API_KEY=your_api_key_here" >> .env |
| 53 | +``` |
| 54 | + |
| 55 | +**Initialize Database** |
| 56 | + |
| 57 | +```bash |
| 58 | +alembic upgrade head |
| 59 | +``` |
| 60 | + |
| 61 | +**Run the API** |
| 62 | + |
| 63 | +```bash |
| 64 | +uvicorn app.main:app --reload |
| 65 | +``` |
| 66 | + |
| 67 | +> API will be available at [http://localhost:8000](http://localhost:8000) |
| 68 | +
|
| 69 | +--- |
| 70 | + |
| 71 | +### 2. Database (PostgreSQL) Setup |
| 72 | + |
| 73 | +Install PostgreSQL (Ubuntu example): |
| 74 | + |
| 75 | +```bash |
| 76 | +sudo apt install postgresql postgresql-contrib |
| 77 | +``` |
| 78 | + |
| 79 | +Start PostgreSQL: |
| 80 | + |
| 81 | +```bash |
| 82 | +sudo service postgresql start |
| 83 | +``` |
| 84 | + |
| 85 | +Create the database: |
| 86 | + |
| 87 | +```bash |
| 88 | +sudo -u postgres psql |
| 89 | +CREATE DATABASE financial_data; |
| 90 | +\q |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +### 3. Redis Setup |
| 96 | + |
| 97 | +Install Redis: |
| 98 | + |
| 99 | +```bash |
| 100 | +sudo apt install redis-server |
| 101 | +``` |
| 102 | + |
| 103 | +Start Redis: |
| 104 | + |
| 105 | +```bash |
| 106 | +sudo service redis-server start |
| 107 | +``` |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +### 4. Frontend Setup |
| 112 | + |
| 113 | +```bash |
| 114 | +cd ../frontend |
| 115 | + |
| 116 | +# Optional: Install live-server for dev preview |
| 117 | +npm install -g live-server |
| 118 | + |
| 119 | +# Run the frontend |
| 120 | +live-server --port=3000 |
| 121 | +``` |
| 122 | + |
| 123 | +> Access the frontend at [http://localhost:3000](http://localhost:3000) |
| 124 | +
|
| 125 | +--- |
| 126 | + |
| 127 | +## 🔌 Connect Frontend to Backend |
| 128 | + |
| 129 | +In `frontend/scripts/main.js`, update the backend API base URL: |
| 130 | + |
| 131 | +```javascript |
| 132 | +const API_BASE_URL = 'http://localhost:8000'; |
| 133 | +``` |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## 🧪 Running Backend Tests |
| 138 | + |
| 139 | +```bash |
| 140 | +cd backend |
| 141 | +source venv/bin/activate |
| 142 | + |
| 143 | +# Run tests |
| 144 | +pytest -v |
| 145 | + |
| 146 | +# Run with coverage |
| 147 | +pytest --cov=app --cov-report=html |
| 148 | +``` |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## 🌐 Access Points Summary |
| 153 | + |
| 154 | +| Service | URL | |
| 155 | +| ---------- | -------------------------------------------------------- | |
| 156 | +| API Docs | [http://localhost:8000/docs](http://localhost:8000/docs) | |
| 157 | +| Frontend | [http://localhost:3000](http://localhost:3000) | |
| 158 | +| PostgreSQL | postgresql://localhost:5432 | |
| 159 | +| Redis | redis\://localhost:6379 | |
| 160 | +| PGAdmin | [http://localhost:5050](http://localhost:5050) | |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +## 🚨 Troubleshooting |
| 165 | + |
| 166 | +**Port Conflicts** |
| 167 | +Check for processes using ports: |
| 168 | + |
| 169 | +```bash |
| 170 | +sudo lsof -i :8000 |
| 171 | +``` |
| 172 | + |
| 173 | +**Database Connection Issues** |
| 174 | + |
| 175 | +```bash |
| 176 | +psql -h localhost -U postgres -d financial_data |
| 177 | +``` |
| 178 | + |
| 179 | +**Missing Data from Alpha Vantage** |
| 180 | +Ensure you have a valid [Alpha Vantage API Key](https://www.alphavantage.co/support/#api-key) |
| 181 | + |
| 182 | +**Frontend Not Connecting?** |
| 183 | + |
| 184 | +* Check browser console (F12) for CORS errors. |
| 185 | +* Verify `API_BASE_URL` in `main.js`. |
| 186 | + |
| 187 | +--- |
| 188 | + |
| 189 | +## 🐳 Docker Cleanup |
| 190 | + |
| 191 | +```bash |
| 192 | +# Stop all services |
| 193 | +docker-compose -f backend/docker-compose.yml down |
| 194 | + |
| 195 | +# Optionally remove volumes |
| 196 | +docker volume prune |
| 197 | +``` |
| 198 | + |
| 199 | +--- |
| 200 | + |
| 201 | +Choose **Docker** for quick setup or **manual mode** for customization. Once running, your full stack is accessible at: |
| 202 | + |
| 203 | +* **API**: [http://localhost:8000](http://localhost:8000) |
| 204 | +* **Frontend**: [http://localhost:3000](http://localhost:3000) |
0 commit comments