Update devdocs: TinyDB→SQLite, project structure, deps, and commands
This commit is contained in:
parent
a5c5f5b077
commit
594bf65715
@ -6,11 +6,12 @@
|
|||||||
GoalsBreakDown/
|
GoalsBreakDown/
|
||||||
├── app.py # Flask application entry point
|
├── app.py # Flask application entry point
|
||||||
├── config.py # Configuration constants
|
├── config.py # Configuration constants
|
||||||
├── database.py # TinyDB initialization and operations
|
├── database.py # SQLite database operations
|
||||||
├── auth.py # Authentication helpers
|
├── auth.py # Authentication helpers
|
||||||
├── requirements.txt # Python dependencies
|
├── schema.py # SQLite table creation & migration
|
||||||
├── data/ # TinyDB data directory
|
├── pyproject.toml # Python dependencies (uv-managed)
|
||||||
│ └── db.json # TinyDB database file
|
├── data/ # SQLite data directory
|
||||||
|
│ └── db.sqlite # SQLite database file
|
||||||
├── static/
|
├── static/
|
||||||
│ ├── css/
|
│ ├── css/
|
||||||
│ │ ├── style.css # Global styles
|
│ │ ├── style.css # Global styles
|
||||||
@ -20,14 +21,14 @@ GoalsBreakDown/
|
|||||||
│ ├── api.js # API client utilities
|
│ ├── api.js # API client utilities
|
||||||
│ ├── auth.js # Authentication logic
|
│ ├── auth.js # Authentication logic
|
||||||
│ ├── goals.js # Goal page logic
|
│ ├── goals.js # Goal page logic
|
||||||
│ ├── tasks.js # Task page logic
|
│ └── tasks.js # Task page logic
|
||||||
│ └── sortable.min.js # Drag-and-drop library
|
|
||||||
└── templates/
|
└── templates/
|
||||||
├── base.html # Base template with navigation
|
├── base.html # Base template with navigation
|
||||||
├── login.html # Login page
|
├── login.html # Login page
|
||||||
├── register.html # Registration page
|
├── register.html # Registration page
|
||||||
├── goals.html # Goal CRUD page
|
├── goals.html # Goal CRUD page
|
||||||
└── tasks.html # Task CRUD page with scroll view
|
├── tasks.html # Task CRUD page with scroll view
|
||||||
|
└── admin.html # Admin user management page
|
||||||
```
|
```
|
||||||
|
|
||||||
## 2. Dependencies & Environment Management
|
## 2. Dependencies & Environment Management
|
||||||
@ -38,80 +39,69 @@ GoalsBreakDown/
|
|||||||
uv init --no-readme
|
uv init --no-readme
|
||||||
|
|
||||||
# Add dependencies
|
# Add dependencies
|
||||||
uv add flask tinydb bcrypt
|
uv add flask bcrypt
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
uv run python app.py
|
uv run flask run
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2.2 requirements.txt (managed by uv)
|
### 2.2 pyproject.toml (managed by uv)
|
||||||
```
|
|
||||||
flask==3.0.0
|
|
||||||
tinydb==4.8.0
|
|
||||||
bcrypt==4.1.2
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2.3 pyproject.toml (auto-generated by uv)
|
|
||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
name = "goalsbreakdown"
|
name = "goalsbreakdown"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.13"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flask>=3.0.0",
|
"flask>=3.1.3",
|
||||||
"tinydb>=4.8.0",
|
"bcrypt>=5.0.0",
|
||||||
"bcrypt>=4.1.2",
|
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
## 3. Database Schema (TinyDB)
|
## 3. Database Schema (SQLite)
|
||||||
|
|
||||||
### 3.1 Collections (TinyDB Tables)
|
### 3.1 Tables
|
||||||
|
|
||||||
**users** table:
|
**users** table:
|
||||||
```json
|
```sql
|
||||||
{
|
CREATE TABLE users (
|
||||||
"user_id": 1,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
"username": "admin",
|
username TEXT NOT NULL UNIQUE,
|
||||||
"password_hash": "$2b$12$...",
|
password_hash TEXT NOT NULL,
|
||||||
"role": "admin",
|
role TEXT NOT NULL DEFAULT 'user',
|
||||||
"max_goals": 10
|
max_goals INTEGER NOT NULL DEFAULT 5
|
||||||
}
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
**goals** table:
|
**goals** table:
|
||||||
```json
|
```sql
|
||||||
{
|
CREATE TABLE goals (
|
||||||
"goal_id": 1,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
"user_id": 1,
|
user_id INTEGER NOT NULL,
|
||||||
"title": "Learn Python",
|
title TEXT NOT NULL,
|
||||||
"activated": true
|
activated INTEGER NOT NULL DEFAULT 1,
|
||||||
}
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
**tasks** table:
|
**tasks** table:
|
||||||
```json
|
```sql
|
||||||
{
|
CREATE TABLE tasks (
|
||||||
"task_id": 1,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
"goal_id": 1,
|
goal_id INTEGER NOT NULL,
|
||||||
"title": "Complete basics",
|
title TEXT NOT NULL,
|
||||||
"desc": "Learn variables, loops, functions",
|
desc TEXT NOT NULL DEFAULT '',
|
||||||
"status": "doing",
|
status TEXT NOT NULL DEFAULT 'todo',
|
||||||
"start_time": "2026-05-08T10:00:00",
|
start_time TEXT,
|
||||||
"finished_time": null,
|
finished_time TEXT,
|
||||||
"order": 1.0
|
"order" REAL NOT NULL DEFAULT 0.0,
|
||||||
}
|
FOREIGN KEY (goal_id) REFERENCES goals(id)
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3.2 Database Initialization
|
### 3.2 Database Initialization (schema.py)
|
||||||
|
- `schema.py` defines SQL table creation and `get_connection()` helper
|
||||||
```python
|
- `init_db()` creates tables and seeds admin user on first run
|
||||||
# database.py responsibilities:
|
- Uses `sqlite3.Row` for dict-like row access
|
||||||
# - Initialize TinyDB with data/db.json
|
|
||||||
# - Create tables: users, goals, tasks
|
|
||||||
# - Seed admin user on first run (username: admin, password: admin123)
|
|
||||||
# - Provide CRUD helper functions for each table
|
|
||||||
```
|
|
||||||
|
|
||||||
## 4. API Endpoints
|
## 4. API Endpoints
|
||||||
|
|
||||||
@ -426,6 +416,7 @@ uv add flask tinydb bcrypt
|
|||||||
- `pyproject.toml` (auto-generated by uv)
|
- `pyproject.toml` (auto-generated by uv)
|
||||||
- `uv.lock` (auto-generated by uv)
|
- `uv.lock` (auto-generated by uv)
|
||||||
- `config.py`
|
- `config.py`
|
||||||
|
- `schema.py`
|
||||||
- `database.py`
|
- `database.py`
|
||||||
- `auth.py`
|
- `auth.py`
|
||||||
- `app.py` (basic setup)
|
- `app.py` (basic setup)
|
||||||
@ -517,7 +508,7 @@ uv add flask tinydb bcrypt
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
# Database
|
# Database
|
||||||
DB_PATH = "data/db.json"
|
DB_PATH = "data/db.sqlite"
|
||||||
|
|
||||||
# Default admin credentials
|
# Default admin credentials
|
||||||
DEFAULT_ADMIN_USERNAME = "admin"
|
DEFAULT_ADMIN_USERNAME = "admin"
|
||||||
@ -559,7 +550,7 @@ PORT = 5000
|
|||||||
- Session-based authentication with HTTP-only cookies
|
- Session-based authentication with HTTP-only cookies
|
||||||
- CSRF protection (Flask-WTF or manual token)
|
- CSRF protection (Flask-WTF or manual token)
|
||||||
- Input sanitization (prevent XSS)
|
- Input sanitization (prevent XSS)
|
||||||
- SQL injection not applicable (TinyDB), but validate all inputs
|
- Parameterized SQL queries (sqlite3 placeholders prevent injection)
|
||||||
- Rate limiting on auth endpoints (optional)
|
- Rate limiting on auth endpoints (optional)
|
||||||
- HTTPS in production
|
- HTTPS in production
|
||||||
|
|
||||||
|
|||||||
@ -84,7 +84,7 @@ Tech Stack:
|
|||||||
|
|
||||||
- Backend: Python + Flask (lightweight, good for small apps)
|
- Backend: Python + Flask (lightweight, good for small apps)
|
||||||
- Frontend: Vanilla JS + HTML/CSS (simple, no build step needed)
|
- Frontend: Vanilla JS + HTML/CSS (simple, no build step needed)
|
||||||
- Database: TinyDB (single JSON file, perfect for this scale)
|
- Database: SQLite (lightweight file-based relational database)
|
||||||
- Authentication: Session-based with password hashing (bcrypt)
|
- Authentication: Session-based with password hashing (bcrypt)
|
||||||
- Drag-and-drop: HTML5 Drag and Drop API or SortableJS
|
- Drag-and-drop: HTML5 Drag and Drop API or SortableJS
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user