11b020907d9ba3d2fcc21d6dd362f8d651ef5e8d
Non-root appuser can't write to the host-mounted SQLite data volume — chown in the image layer doesn't carry over to runtime volume mounts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
BTC Portfolio Tracker
A full-stack Bitcoin portfolio tracker with live EUR pricing, purchase history, and interactive charts.
Features
- Live BTC price — fetched from CoinGecko in EUR
- Purchase tracking — log BTC buys with amount (EUR) and price per BTC
- Portfolio stats — total invested, current value, profit/loss
- Interactive charts — portfolio value over time and 1-year BTC price history
- Edit & delete — manage purchases with inline editing
- JWT authentication — secure per-user portfolios
Tech Stack
| Layer | Technology |
|---|---|
| Frontend | React 18, Chart.js, dark theme |
| Backend | FastAPI, SQLAlchemy, SQLite |
| Auth | JWT (HS256, 24h expiry) + bcrypt |
| Pricing | CoinGecko API (EUR) |
| Deploy | Docker + Docker Compose |
Getting Started
Docker (recommended)
git clone <repo-url>
cd btc-portfolio
docker-compose up
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
Local Development
Backend
cd btc-portfolio/backend
pip install -r requirements.txt
uvicorn app.main:app --reload
Frontend
cd btc-portfolio/frontend
npm install
npm start
Project Structure
btc-portfolio/
├── backend/
│ └── app/
│ ├── main.py # FastAPI app + CORS
│ ├── models.py # User & Purchase ORM models
│ ├── auth.py # JWT + bcrypt
│ ├── dependencies.py # Auth dependency injection
│ ├── routes/
│ │ ├── users.py # POST /register, POST /login
│ │ ├── purchases.py # CRUD /purchases
│ │ ├── stats.py # GET /stats
│ │ └── history.py # GET /history (365-day BTC prices)
│ └── services/
│ └── btc.py # CoinGecko integration
└── frontend/
└── src/
├── App.js # Routing
├── pages/
│ └── Dashboard.js # Main view
└── components/
├── AddPurchase.js # Purchase form
├── PurchaseList.js # Purchase table (edit/delete)
├── PortfolioChart.js # Invested vs current value
└── BTCHistoryChart.js # 1-year BTC price history
API Endpoints
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /register |
Create account | No |
| POST | /login |
Get JWT token | No |
| GET | /purchases |
List user purchases | Yes |
| POST | /purchases |
Add a purchase | Yes |
| PUT | /purchases/{id} |
Edit a purchase | Yes |
| DELETE | /purchases/{id} |
Delete a purchase | Yes |
| GET | /stats |
Portfolio stats (P&L) | Yes |
| GET | /history |
365-day BTC price history | Yes |
Database
SQLite, stored at /app/data/btc_portfolio.db (persisted via Docker volume).
| Table | Columns |
|---|---|
users |
id, username (unique), password (bcrypt hash) |
purchases |
id, amount_eur, price_eur, created_at, user_id (FK) |
Notes
- The
SECRET_KEYinauth.pyis hardcoded — use an environment variable in production. - CoinGecko requests are unauthenticated; failures return
0.0gracefully. - CORS is restricted to
localhost:3000by default.
Description
Languages
JavaScript
65.4%
Python
33.4%
Dockerfile
0.7%
HTML
0.5%