Skip to content

Commit 8193009

Browse files
authored
Merge pull request #5 from tldrwtf/fix
feat: Enhance documentation and synchronization features; update authentication methods and dependencies
2 parents 8b9aa25 + 7a60359 commit 8193009

18 files changed

+278
-141
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ __pycache__/
1515
*.class
1616
scratch.py
1717
venv/
18+
.ruff_cache/
19+
.pytest_cache/
20+
.venv/
1821

1922

2023
# Environment variables

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ A Pokemon-themed CLI task manager and wellbeing tracker. Complete tasks to catch
3232
- Catch Pokemon by completing tasks
3333
- **All 1025 Pokemon** from Gen 1 (Kanto) through Gen 9 (Paldea)
3434
- Pokemon rarity based on task difficulty
35-
- Pokemon **EVs (Effort Values) and IVs (Individual Values)** for stat training (in progress)
35+
- Pokemon **EVs (Effort Values) and IVs (Individual Values)** for stat training (partial implementation)
3636
- Shiny Pokemon (rare variants with boosted rates from streaks)
3737
- Legendary, Mythical, Pseudo-Legendary, and Ultra Beast encounters
3838
- Paradox Pokemon from Scarlet/Violet
@@ -102,7 +102,7 @@ pokedo
102102
### Initialize
103103

104104
```bash
105-
# Full initialization (all 1025 Pokemon - takes a few minutes first time)
105+
# Full initialization (all 1025 Pokemon, takes a few minutes first time)
106106
pokedo init --name "Ash"
107107

108108
# Quick start with Gen 1 only (151 Pokemon)
@@ -202,7 +202,7 @@ pokedo stats history --days 14
202202

203203
### Server Usage (Optional)
204204

205-
PokeDo is developing a FastAPI server to enable cloud synchronization and multi-user features. You can run the development server and test its authentication endpoints.
205+
PokeDo is developing a FastAPI server to enable cloud synchronization and multi-user features. This system uses `requests` for client-side pushing and `bcrypt` for secure authentication.
206206

207207
1. **Run the Server:**
208208

docs/ARCHITECTURE.md

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ PokeDo is a gamified task manager that combines productivity tracking with Pokem
2121
- **Presentation Layer** (CLI) - User interface and command handling
2222
- **Business Logic Layer** (Core) - Domain models and game mechanics
2323
- **Data Access Layer** (Data) - Database operations and API clients
24+
- **Synchronization Layer** (Sync) - Client-side change queuing and server communication
2425

2526
**Technology Stack:**
2627
- Python 3.10+
2728
- Typer (CLI framework)
2829
- Rich (Terminal UI)
2930
- Pydantic (Data validation)
3031
- SQLite (Local storage)
31-
- FastAPI (Server & Sync)
32-
- JWT/Bcrypt (Authentication)
33-
- httpx (Async HTTP client)
32+
- FastAPI (Server)
33+
- Bcrypt (Direct password hashing)
34+
- httpx (Async HTTP client for PokeAPI)
35+
- requests (Sync HTTP client for Server Sync)
3436

3537
---
3638

@@ -44,16 +46,17 @@ pokedo/
4446
│ ├── app.py # Main Typer application
4547
│ └── ...
4648
├── core/ # Business Logic Layer
47-
│ ├── auth.py # NEW: Authentication logic
49+
│ ├── auth.py # Authentication logic (Bcrypt/JWT)
4850
│ ├── task.py # Task model and enums
4951
│ ├── trainer.py # Trainer model and progression
5052
│ ├── pokemon.py # Pokemon and Pokedex models
5153
│ ├── rewards.py # Encounter and reward system
5254
│ └── wellbeing.py # Wellbeing tracking models
5355
├── data/ # Data Access Layer
5456
│ ├── database.py # SQLite operations
55-
│ └── pokeapi.py # PokeAPI client
56-
├── server.py # NEW: FastAPI server entry point
57+
│ ├── pokeapi.py # PokeAPI client
58+
│ └── sync.py # NEW: Sync client and change queue
59+
├── server.py # FastAPI server entry point
5760
└── utils/ # Utilities
5861
├── config.py # Configuration management
5962
└── helpers.py # Helper functions
@@ -96,7 +99,7 @@ Handles centralized operations and synchronization.
9699
The core layer contains domain models and game logic.
97100

98101
**`auth.py`** - Authentication
99-
- Password hashing (Bcrypt)
102+
- Password hashing (Direct Bcrypt usage)
100103
- JWT Token generation and verification
101104

102105
**`task.py`** - Task Management
@@ -157,23 +160,42 @@ class DailyWellbeing:
157160
- Query builders
158161

159162
**`pokeapi.py`** - External API Client
160-
- Async HTTP client using httpx
163+
- Async HTTP client using `httpx`
161164
- Response caching (JSON files)
162165
- Sprite downloading
163166
- Evolution chain parsing
164167

165-
### Utilities (`utils/`)
168+
**`sync.py`** - Synchronization Client
169+
- Local change queue management (SQLModel `Change` entity)
170+
- Sync push operations using `requests`
166171

167-
**`config.py`** - Configuration
168-
- Data directory paths
169-
- Game constants (XP values, catch rates)
170-
- Generation ID ranges
171-
- Rarity thresholds
172+
---
173+
174+
## Synchronization Layer
175+
176+
This layer enables local-first data handling with cloud synchronization.
177+
178+
**Concept:**
179+
- **Local-First:** All user actions (Task Create, Pokemon Catch) are committed to the local SQLite database immediately.
180+
- **Change Queue:** Simultaneously, a record of the action is written to a `change` table in the local DB.
181+
- **Push Sync:** A background process (or manual command) reads unsynced changes from the `change` table and pushes them to the server via HTTP POST.
182+
183+
**Change Entity:**
184+
```python
185+
class Change(SQLModel):
186+
id: str (UUID)
187+
entity_id: str
188+
entity_type: str (e.g., "task", "pokemon")
189+
action: str (CREATE, UPDATE, DELETE)
190+
payload: JSON
191+
timestamp: datetime
192+
synced: bool
193+
```
172194

173-
**`helpers.py`** - Helper Functions
174-
- Date parsing and formatting
175-
- Input validation
176-
- Common utilities
195+
**Sync Process:**
196+
1. `queue_change()`: Called by CRUD functions in `database.py` whenever data modifies.
197+
2. `push_changes()`: Reads unsynced records, sends to `POST /sync`.
198+
3. On 200 OK, marks records as `synced=True`.
177199

178200
---
179201

@@ -182,7 +204,7 @@ class DailyWellbeing:
182204
### Task Completion Flow
183205

184206
```
185-
User Input -> CLI Command -> Validate Input -> Database Update
207+
User Input -> CLI Command -> Validate Input -> Database Update -> Queue Change
186208
|
187209
v
188210
Display Result <- UI Components <- Reward System <- Calculate Rewards
@@ -194,7 +216,7 @@ Display Result <- UI Components <- Reward System <- Calculate Rewards
194216
Catch Attempt
195217
|
196218
v
197-
Update Database
219+
Update Database -> Queue Change
198220
```
199221

200222
### Pokemon Encounter Flow

docs/CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222
### Installation
2323

24-
1. Clone the repository:
24+
1. Clone the repository:
2525

2626
```bash
2727
git clone https://github.com/tldrwtf/pokedo.git
2828
cd pokedo
2929
```
3030

31-
1. Create a virtual environment:
31+
2. Create a virtual environment:
3232

3333
```bash
3434
python -m venv venv
@@ -40,13 +40,13 @@
4040
source venv/bin/activate
4141
```
4242

43-
1. Install development dependencies (formatter, linter, tests):
43+
3. Install development dependencies (formatter, linter, tests):
4444

4545
```bash
4646
pip install -e ".[dev]"
4747
```
4848

49-
1. Initialize the application (for testing):
49+
4. Initialize the application (for testing):
5050

5151
```bash
5252
pokedo init --name "Developer" --quick

docs/EV_IV_SPEC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# EV / IV Spec (Pokedo Expansion) Minimal Reference
1+
# EV / IV Spec (Pokedo Expansion) - Minimal Reference
22

33
**Status:** Partially Implemented (Core Models & Helpers done; DB persistence pending)
44

docs/GETTING_STARTED.md

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,83 @@
11
# Getting Started (Developer)
22

3-
Prereqs:
3+
## Prerequisites
44

5-
- Python 3.11+, pip
6-
- Docker (for postgres) — optional for server dev
5+
- Python 3.10+
6+
- pip (Python package manager)
7+
- Docker (Optional, for future PostgreSQL support)
78

8-
Install:
9-
Windows cmd.exe:
9+
## Installation
1010

11-
```
11+
**Windows (cmd.exe):**
12+
13+
```cmd
1214
python -m venv .venv
13-
.venv\\Scripts\\activate
15+
.venv\Scripts\activate
1416
pip install -e ".[dev]"
1517
```
1618

17-
Run CLI examples:
19+
**Linux/macOS:**
1820

19-
```
20-
python -m pokedo.cli.app init-db
21-
python -m pokedo.cli.app add-task "Finish report" --category work --difficulty medium
22-
python -m pokedo.cli.app add-pokemon "Starter"
21+
```bash
22+
python3 -m venv .venv
23+
source .venv/bin/activate
24+
pip install -e ".[dev]"
2325
```
2426

25-
Run server (dev):
27+
## Running the CLI
2628

27-
```
28-
# Starts FastAPI server on port 8000 with hot reload
29+
1. **Initialize the Database:**
30+
This downloads the initial Pokemon data cache.
31+
32+
```bash
33+
pokedo init --name "Dev" --quick
34+
```
35+
36+
2. **Basic Commands:**
37+
38+
```bash
39+
pokedo task add "Finish report" --category work --difficulty medium
40+
pokedo task list
41+
pokedo pokemon box
42+
```
43+
44+
## Running the Server
45+
46+
To test the synchronization features, you can run the local FastAPI development server.
47+
48+
```bash
2949
uvicorn pokedo.server:app --reload --port 8000
3050
```
3151

32-
Test Auth:
52+
## Testing Authentication
3353

34-
```bash
35-
# 1. Register
36-
curl -X POST http://localhost:8000/register -H "Content-Type: application/json" -d "{\"username\": \"me\", \"password\": \"secret\"}"
54+
You can use `curl` to test the registration and login flow.
3755

38-
# 2. Login
39-
curl -X POST http://localhost:8000/token -F "username=me" -F "password=secret"
56+
**1. Register a user:**
57+
58+
```bash
59+
curl -X POST http://localhost:8000/register \
60+
-H "Content-Type: application/json" \
61+
-d "{\"username\": \"me\", \"password\": \"secret\"}"
4062
```
4163

42-
Run tests:
64+
**2. Login to get a token:**
4365

66+
```bash
67+
curl -X POST http://localhost:8000/token \
68+
-F "username=me" \
69+
-F "password=secret"
4470
```
45-
pytest -q
71+
72+
## Running Tests
73+
74+
Run the full test suite to ensure everything is working correctly.
75+
76+
```bash
77+
pytest
4678
```
4779

48-
Notes:
80+
## Notes
4981

50-
- The repo uses a local-first SQLite DB for the CLI; if you start Postgres (via docker-compose), set `DATABASE_URL` accordingly.
82+
- The application uses a local-first SQLite database by default (`~/.pokedo/pokedo.db`).
83+
- If you are working on the Sync client, remember to initialize the sync table: `python -m pokedo.data.sync init`.

0 commit comments

Comments
 (0)