brian a1a914ee4d
Build and Push Docker Image / build-and-push (push) Successful in 26s
Python Code Quality / python-code-quality (push) Successful in 10s
Python Test / python-test (push) Successful in 18s
Merge pull request 'added showcase data, users and CI workflow to refresh data daily' (#33) from add-showcase-data-and-users into main
Reviewed-on: #33
2025-11-12 18:20:06 +01:00
2025-11-12 18:18:17 +01:00
2025-11-06 21:33:51 +01:00
2025-11-12 18:18:17 +01:00
2025-11-12 17:32:02 +01:00
2025-11-06 21:40:12 +01:00
2025-11-04 21:03:16 +01:00
2025-11-04 21:03:16 +01:00
2025-11-11 21:18:20 +01:00
2025-11-11 15:16:24 +01:00
2025-11-04 21:03:16 +01:00
2025-11-12 18:18:17 +01:00
2025-11-11 20:43:47 +01:00

👶 Baby Monitor

A self-hosted FastAPI web application for tracking baby activities including feeding, sleeping, and diaper changes. Built with modern Python tools and designed for easy deployment with Docker.

Docker FastAPI Python

Features

  • 🔐 Secure Authentication - Token-based authentication with environment-configured credentials
  • 💾 Flexible Storage - SQLite by default with PostgreSQL support
  • 🚀 Scalable Sessions - In-memory tokens with optional Redis for distributed deployments
  • 📦 Self-Contained - Docker image includes all optional dependencies
  • 🔌 Repository Pattern - Clean architecture with swappable backends
  • 🏥 Health Checks - Built-in health and readiness endpoints
  • 🌐 SPA Frontend - Modern single-page application interface
  • 🐳 Docker Ready - Production-ready Dockerfile with multi-architecture support

🚀 Quick Start

# Pull and run the latest image
docker run -d \
  --name baby-monitor \
  -p 8000:8000 \
  -e ADMIN_PASSWORD=your-secure-password \
  -v baby_monitor_data:/data \
  gitea.gt-proj.com/brian/baby-monitor:latest

# Access the application
open http://localhost:8000

Using Docker Compose

services:
  baby-monitor:
    image: gitea.gt-proj.com/brian/baby-monitor:latest
    container_name: baby-monitor
    ports:
      - "8000:8000"
    environment:
      - ENVIRONMENT=production
      - ADMIN_PASSWORD=${ADMIN_PASSWORD}
      # Optional: Use Redis for distributed token storage
      # - REDIS_URI=redis://redis:6379
    volumes:
      - ./data:/data
    restart: unless-stopped

  # Optional: Redis for token storage
  # redis:
  #   image: redis:7-alpine
  #   restart: unless-stopped

Local Development

# Clone the repository
git clone https://gitea.gt-proj.com/brian/baby-monitor.git
cd baby-monitor

# Install dependencies with uv
uv sync --all-extras

# Set environment variables
export ENVIRONMENT=development
export ADMIN_PASSWORD=password
export DATA_DIR=./data

# Run the application
uv run uvicorn src.baby_monitor.main:app --reload --host 0.0.0.0 --port 8000

🔧 Configuration

Environment Variables

Variable Default Description
ENVIRONMENT production Set to development to enable API docs
ADMIN_PASSWORD (required) Admin user password
ADMIN_USERNAME admin Admin username
DATA_DIR /data Directory for SQLite database (SQLite only)
REDIS_URI (optional) Redis connection URI for distributed tokens
POSTGRES_URI (optional) PostgreSQL connection URI for database storage

Storage Options

SQLite (Default)

  • Automatic setup, no configuration needed
  • Data stored in /data/baby_monitor.db
  • Perfect for single-server deployments
  • Timezone-aware datetimes stored as naive UTC

Redis (Optional - Token Storage)

# Enable Redis token storage for distributed deployments
export REDIS_URI=redis://localhost:6379

PostgreSQL (Optional - Database)

# Enable PostgreSQL for production database
export POSTGRES_URI=postgresql://user:password@localhost:5432/baby_monitor
  • Supports timezone-aware datetimes natively
  • Recommended for production deployments
  • Better performance for concurrent access
  • Supports database migrations and backups

📁 Project Structure

baby-monitor/
├── src/baby_monitor/
│   ├── main.py                     # FastAPI application
│   ├── models/                     # Pydantic models
│   ├── routers/                    # API endpoints
│   │   ├── auth.py                # Authentication routes
│   │   └── health.py              # Health check routes
│   ├── repositories/               # Data access layer
│   │   ├── interfaces.py          # Abstract interfaces
│   │   ├── user/                  # User repositories
│   │   ├── token/                 # Token storage
│   │   └── credentials/           # Credentials management
│   └── static/                    # Frontend files
├── tests/                         # Test suite
│   ├── integration/               # Integration tests
│   └── unit/                      # Unit tests
├── Dockerfile                     # Production container
├── docker-compose.yml             # Local development
└── pyproject.toml                 # Project dependencies

🏗️ Architecture

Repository Pattern

The application uses the Repository Pattern for data access, allowing easy swapping of backends:

# Switch from SQLite to PostgreSQL
from baby_monitor.repositories.user.postgresql_user import PostgreSQLUserRepository
return PostgreSQLUserRepository(db)

# Switch from in-memory to Redis tokens
# Just set REDIS_URI environment variable

Technology Stack

  • Backend: FastAPI + SQLAlchemy 2.0
  • Database: SQLite (default) / PostgreSQL (ready)
  • Cache: In-memory (default) / Redis (optional)
  • Package Manager: uv
  • Container: Docker with multi-stage builds

🧪 Testing

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov-report=term-missing --cov=src/baby_monitor

# Run specific test types
uv run pytest tests/unit/
uv run pytest tests/integration/

🔒 Security

  • Token-based authentication
  • Environment-based secrets (no hardcoded credentials)
  • API docs disabled in production
  • CORS configuration ready
  • ⚠️ TODO: Add password hashing (currently plain text comparison)
  • ⚠️ TODO: Implement rate limiting

🚀 Deployment

Unraid

  1. Add the repository to Community Applications
  2. Configure environment variables
  3. Map /data volume for persistence
  4. Set admin password

Docker Swarm / Kubernetes

The application is stateless when using Redis for tokens, making it suitable for:

  • Multi-replica deployments
  • Load balancing
  • Rolling updates

CI/CD

Gitea Actions workflow included:

  • Builds multi-architecture images (amd64, arm64)
  • Automatic semantic versioning
  • Pushes to container registry
  • Health checks and metadata

📊 API Documentation

When running in development mode (ENVIRONMENT=development):

Key Endpoints

Endpoint Method Description
/ GET Serve home page
/api/ GET Authenticated API root
/api/login POST User authentication
/api/logout POST Invalidate token
/health GET Health check
/ready GET Readiness probe
/info GET Feature detection

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Write tests for new features
  • Follow PEP 8 style guide
  • Add type hints to all functions
  • Keep line length ≤ 79 characters
  • Run mypy and ruff before committing

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📧 Contact

Brian Bjarke Jensen - @brian

Project Link: https://gitea.gt-proj.com/brian/baby-monitor


Made with ❤️ for new parents everywhere

S
Description
Baby monitor app that helps track feeding, sleeping and diaper changes for a child.
Readme MIT
1.3 MiB
2026-05-21 15:36:45 +02:00
Languages
HTML 59.1%
Python 35.4%
JavaScript 2.9%
CSS 2.3%
Dockerfile 0.3%