Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!backend
!backend/**
backend/**/__pycache__
backend/**/*.sqlite3*
15 changes: 15 additions & 0 deletions .github/workflows/backend-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Backend checks
on:
push:
paths: ['backend/**', '.github/workflows/backend-check.yml']
pull_request:
paths: ['backend/**', '.github/workflows/backend-check.yml']
jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: python -m unittest discover -s backend/tests -v
22 changes: 22 additions & 0 deletions .github/workflows/deployment-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deployment checks
on:
push:
branches: [fix/backend-reliability, feature/web-app]
pull_request:
jobs:
containers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker build -t taskhub:test .
- run: TASKHUB_DOMAIN=example.com docker compose config --quiet
- run: docker run --rm -e TASKHUB_DOMAIN=example.com -v "$PWD/deploy/Caddyfile:/etc/caddy/Caddyfile:ro" caddy:2-alpine caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
- run: docker run --rm taskhub:test python -m unittest discover -s backend/tests -v
- run: TASKHUB_DOMAIN=example.com docker compose up -d --build --wait --wait-timeout 180 api backup
- run: docker compose --env-file /dev/null ps
env:
TASKHUB_DOMAIN: example.com
- if: always()
run: TASKHUB_DOMAIN=example.com docker compose logs --no-color
- if: always()
run: TASKHUB_DOMAIN=example.com docker compose down -v
4 changes: 3 additions & 1 deletion .github/workflows/flutter-check.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Flutter checks
on:
push:
branches: [feature/group-planners, feature/web-app]
branches: [feature/group-planners, feature/web-app, fix/backend-reliability]
pull_request:
workflow_dispatch:
jobs:
flutter:
Expand All @@ -11,6 +12,7 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: '3.47.8'
cache: true
- run: flutter pub get
- run: flutter analyze
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ app.*.map.json

# Widget Preview related
.widget_preview/

# Deployment secrets and local snapshots
.env
android/key.properties
*.jks
*.keystore
/backups/
/data/
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.12-slim
RUN useradd --uid 10001 --create-home taskhub && mkdir /data /backups && chown taskhub /data /backups
WORKDIR /app
COPY backend /app/backend
USER taskhub
ENV TASKHUB_HOST=0.0.0.0 TASKHUB_DB=/data/taskhub.sqlite3 PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=3)"
CMD ["python", "-m", "backend.app"]
26 changes: 23 additions & 3 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import java.util.Properties

plugins {
id("com.android.application")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}

val releaseProperties = Properties()
val releasePropertiesFile = rootProject.file("key.properties")
if (releasePropertiesFile.exists()) {
releasePropertiesFile.inputStream().use { releaseProperties.load(it) }
}

android {
namespace = "com.example.taskhub"
compileSdk = flutter.compileSdkVersion
Expand All @@ -30,11 +38,23 @@ android {
versionName = flutter.versionName
}

signingConfigs {
if (releasePropertiesFile.exists()) {
create("production") {
keyAlias = releaseProperties.getProperty("keyAlias")
keyPassword = releaseProperties.getProperty("keyPassword")
storeFile = file(releaseProperties.getProperty("storeFile"))
storePassword = releaseProperties.getProperty("storePassword")
}
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
if (releasePropertiesFile.exists()) {
signingConfig = signingConfigs.getByName("production")
}
// Without a production keystore the output is unsigned, never debug-signed.
}
}
}
Expand Down
31 changes: 27 additions & 4 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Keep it in device secure storage; don't put it in the source code or a URL.
A state GET returns `{"revision":0,"lessons":[],"deadlines":[]}` for a new
account. PUT the same shape with the user's lesson and deadline JSON arrays.
The server validates required fields and limits each array to 1000 objects and
the full request to 512 KiB. A successful PUT returns the incremented revision.
the full request to 512 KiB. Lessons require a valid weekday and 24-hour
`HH:MM` times with start before end; deadlines require a valid ISO date/time
containing `T`. Titles and subjects cannot be blank. A successful PUT returns the incremented revision.
If another device already wrote a new revision, PUT returns HTTP 409
`revision_conflict`; GET the new state and ask the user how to reconcile it.
A 401 means the token is absent, invalid or expired.
Expand All @@ -72,6 +74,27 @@ Group deadlines are shared, but completion is personal: PUT
completion value; another member's checkbox is unaffected. Group owners cannot
leave their own group. Removing a deadline clears its completion records.

The Flutter Groups tab uses these endpoints. The original personal Schedule and
Deadlines tabs still keep their data in SharedPreferences; personal cloud sync
is not wired up yet.
Flutter uses these endpoints for groups and personal cloud planners. Guest data
is separate; use Import guest planner after signing in to copy it explicitly.
Pending edits are stored per account. Revision conflicts require an explicit
choice and retain the discarded version locally for recovery.


## Reliability and hosting boundaries

API responses are sent after the SQLite transaction commits. A database failure
returns an error instead of acknowledging an uncommitted change. Backend checks
run on pull requests and pushes affecting backend code.

Keep `TASKHUB_DB` outside `TASKHUB_WEB_DIR`. The static server rejects hidden
paths, traversal outside the web root and extensions outside its asset allowlist,
including SQLite and Python files. The web directory must contain only public
build assets; JSON files there are public too.

Deploy the bounded API behind Caddy using compose.yaml. See deploy/README.md
and deploy/RELEASE_CHECKLIST.md for infrastructure setup and release acceptance.
Schema version 2 adds hashed one-use recovery codes. POST account/password,
account/recovery-code and account/delete under /api/v1 require the current
password. POST /api/v1/auth/recover accepts email, recoveryCode and newPassword;
it consumes the code and revokes all sessions. Account deletion removes owned
groups as well as the personal planner.
56 changes: 56 additions & 0 deletions backend/accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Account lifecycle endpoints; callers provide an authenticated transaction."""
import hashlib
import hmac
import secrets


def password_hash(password, salt):
return hashlib.scrypt(password.encode(), salt=salt, n=2**14, r=8, p=1, dklen=32)


def valid_password(password):
return isinstance(password, str) and 12 <= len(password) <= 1024


def manage(db, user_id, action, data):
password = data.get('password')
if not valid_password(password):
return 400, {'error': 'invalid_password'}
db.execute('BEGIN IMMEDIATE')
row = db.execute('SELECT * FROM users WHERE id=?', (user_id,)).fetchone()
if not hmac.compare_digest(password_hash(password, row['salt']), row['password_hash']):
return 401, {'error': 'invalid_credentials'}
if action == 'recovery-code':
code = secrets.token_hex(24)
db.execute('INSERT INTO recovery_codes(user_id,code_hash) VALUES(?,?) ON CONFLICT(user_id) DO UPDATE SET code_hash=excluded.code_hash',
(user_id, hashlib.sha256(code.encode()).digest()))
return 200, {'recoveryCode': code}
if action == 'password':
new = data.get('newPassword')
if not valid_password(new):
return 400, {'error': 'password_length_must_be_12_to_1024'}
salt = secrets.token_bytes(16)
db.execute('UPDATE users SET salt=?,password_hash=? WHERE id=?', (salt, password_hash(new, salt), user_id))
db.execute('DELETE FROM sessions WHERE user_id=?', (user_id,))
db.execute('DELETE FROM recovery_codes WHERE user_id=?', (user_id,))
return 200, {'ok': True}
if action == 'delete':
db.execute('DELETE FROM groups WHERE owner_id=?', (user_id,))
db.execute('DELETE FROM users WHERE id=?', (user_id,))
return 200, {'ok': True}
return 404, {'error': 'not_found'}


def recover(db, data):
email, code, password = data.get('email'), data.get('recoveryCode'), data.get('newPassword')
if not isinstance(email, str) or not isinstance(code, str) or len(code) != 48 or not valid_password(password):
return 400, {'error': 'invalid_recovery_request'}
db.execute('BEGIN IMMEDIATE')
row = db.execute('SELECT u.id,r.code_hash FROM users u JOIN recovery_codes r ON r.user_id=u.id WHERE u.email=?', (email.casefold(),)).fetchone()
if row is None or not hmac.compare_digest(hashlib.sha256(code.encode()).digest(), row['code_hash']):
return 400, {'error': 'invalid_recovery_code'}
salt = secrets.token_bytes(16)
db.execute('UPDATE users SET salt=?,password_hash=? WHERE id=?', (salt, password_hash(password, salt), row['id']))
db.execute('DELETE FROM sessions WHERE user_id=?', (row['id'],))
db.execute('DELETE FROM recovery_codes WHERE user_id=?', (row['id'],))
return 200, {'ok': True}
Loading
Loading