Critical fixes: - C-01: Pass user_id to _mark_sent/_already_sent (ntfy crash) - C-02: Align frontend HTTP methods with backend routes (PATCH->PUT, DELETE->POST, fix reset-password/enforce-mfa/disable-mfa paths) - C-03: Add X-Requested-With to CORS allow_headers - C-04: Replace scalar_one_or_none with func.count for auth/status Warning fixes: - W-01: Batch audit log into same transaction in create_user, setup, register - W-02: Extract users array from UserListResponse wrapper in useAdminUsers - W-03: Update password hint from "8 chars" to "12 chars" in CreateUserDialog - W-04: Remove password input from reset flow, show returned temp password - W-06: Remove unused actor_alias variable in admin_dashboard - W-07: Resolve usernames in dashboard audit entries via JOIN, remove ip_address column from recent_logins (not tracked on User model) Suggestions applied: - S-01/S-06: Add extra="forbid" to all admin mutation schemas - S-04: Add ondelete="SET NULL" to audit_log.actor_user_id FK - S-05: Improve registration error message for better UX Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
UMBRA Backend
A complete FastAPI backend for the UMBRA application with async SQLAlchemy, PostgreSQL, authentication, and comprehensive CRUD operations.
Features
- FastAPI with async/await support
- SQLAlchemy 2.0 with async engine
- PostgreSQL with asyncpg driver
- Alembic for database migrations
- bcrypt for password hashing
- itsdangerous for session management
- PIN-based authentication with secure session cookies
- Full CRUD operations for all entities
- Dashboard with aggregated data
- CORS enabled for frontend integration
Project Structure
backend/
├── alembic/ # Database migrations
│ ├── versions/ # Migration files
│ ├── env.py # Alembic environment
│ └── script.py.mako # Migration template
├── app/
│ ├── models/ # SQLAlchemy models
│ ├── schemas/ # Pydantic schemas
│ ├── routers/ # API route handlers
│ ├── config.py # Configuration
│ ├── database.py # Database setup
│ └── main.py # FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── alembic.ini # Alembic configuration
└── start.sh # Startup script
Setup
1. Install Dependencies
cd backend
pip install -r requirements.txt
2. Configure Environment
Create a .env file:
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/umbra
SECRET_KEY=your-secret-key-change-in-production
3. Create Database
createdb umbra
4. Run Migrations
alembic upgrade head
5. Start Server
# Using the start script
chmod +x start.sh
./start.sh
# Or directly with uvicorn
uvicorn app.main:app --reload
The API will be available at http://localhost:8000
API Documentation
Interactive API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Authentication
POST /api/auth/setup- Initial PIN setupPOST /api/auth/login- Login with PINPOST /api/auth/logout- LogoutGET /api/auth/status- Check auth status
Todos
GET /api/todos- List todos (with filters)POST /api/todos- Create todoGET /api/todos/{id}- Get todoPUT /api/todos/{id}- Update todoDELETE /api/todos/{id}- Delete todoPATCH /api/todos/{id}/toggle- Toggle completion
Calendar Events
GET /api/events- List events (with date range)POST /api/events- Create eventGET /api/events/{id}- Get eventPUT /api/events/{id}- Update eventDELETE /api/events/{id}- Delete event
Reminders
GET /api/reminders- List reminders (with filters)POST /api/reminders- Create reminderGET /api/reminders/{id}- Get reminderPUT /api/reminders/{id}- Update reminderDELETE /api/reminders/{id}- Delete reminderPATCH /api/reminders/{id}/dismiss- Dismiss reminder
Projects
GET /api/projects- List projectsPOST /api/projects- Create projectGET /api/projects/{id}- Get projectPUT /api/projects/{id}- Update projectDELETE /api/projects/{id}- Delete projectGET /api/projects/{id}/tasks- List project tasksPOST /api/projects/{id}/tasks- Create project taskPUT /api/projects/{id}/tasks/{task_id}- Update taskDELETE /api/projects/{id}/tasks/{task_id}- Delete task
People
GET /api/people- List people (with search)POST /api/people- Create personGET /api/people/{id}- Get personPUT /api/people/{id}- Update personDELETE /api/people/{id}- Delete person
Locations
GET /api/locations- List locations (with category filter)POST /api/locations- Create locationGET /api/locations/{id}- Get locationPUT /api/locations/{id}- Update locationDELETE /api/locations/{id}- Delete location
Settings
GET /api/settings- Get settingsPUT /api/settings- Update settingsPUT /api/settings/pin- Change PIN
Dashboard
GET /api/dashboard- Get dashboard dataGET /api/upcoming?days=7- Get upcoming items
Database Schema
The application uses the following tables:
settings- Application settings and PINtodos- Task itemscalendar_events- Calendar eventsreminders- Remindersprojects- Projectsproject_tasks- Tasks within projectspeople- Contacts/peoplelocations- Physical locations
Docker
Build and run with Docker:
docker build -t umbra-backend .
docker run -p 8000:8000 -e DATABASE_URL=... -e SECRET_KEY=... umbra-backend
Development
Create New Migration
alembic revision --autogenerate -m "Description of changes"
Apply Migrations
alembic upgrade head
Rollback Migration
alembic downgrade -1
Security Notes
- Change
SECRET_KEYin production - Use strong PINs (minimum 4 digits recommended)
- Session cookies are httpOnly and last 30 days
- All API endpoints (except auth) require authentication
- PINs are hashed with bcrypt before storage