Skip to content

Implement FastAPI backend with JWT authentication and activity management#71

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-6dfcf551-1032-496b-afec-53e9aaaae8d3
Draft

Implement FastAPI backend with JWT authentication and activity management#71
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-6dfcf551-1032-496b-afec-53e9aaaae8d3

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 19, 2025

This PR implements a complete FastAPI backend for the La Vida Luca application as specified in the requirements. The backend provides JWT-based authentication and activity management functionality.

🚀 Features Implemented

FastAPI Application Structure

  • Main application (apps/backend/src/main.py) with CORS middleware configured for frontend integration
  • Modular architecture with separate routers for authentication and activities
  • Automatic database table creation on startup
  • Health check endpoints and auto-generated API documentation

JWT Authentication System

  • User registration and login with secure password hashing using bcrypt
  • JWT token generation with configurable expiration times
  • Protected route middleware requiring valid authentication
  • Proper error handling for invalid credentials and duplicate registrations

Database Models & API Endpoints

# User model with activities relationship
class User(Base):
    id, email, hashed_password, full_name, created_at
    activities = relationship("Activity", back_populates="user")

# Activity model linked to users  
class Activity(Base):
    id, title, description, duration, category, user_id, created_at

API Endpoints:

  • POST /auth/register - User registration
  • POST /auth/login - Authentication (returns JWT token)
  • GET /activities/ - List user's activities (protected)
  • POST /activities/ - Create new activity (protected)
  • GET /activities/{id} - Get specific activity (protected)

Configuration & Environment

  • Environment-based configuration using Pydantic settings
  • SQLite database by default (easily configurable for other databases)
  • CORS configuration for frontend integration
  • Secure defaults with configurable JWT secrets and token expiration

🧪 Testing & Quality

Comprehensive Test Suite

  • 9 passing tests covering all authentication flows and API endpoints
  • Database isolation ensuring reliable test runs
  • Authentication tests: registration, login, invalid credentials, duplicate emails
  • API endpoint tests: protected routes, unauthorized access, activity CRUD operations

Modern Python Practices

  • Timezone-aware datetime handling (replacing deprecated utcnow())
  • Modern Pydantic schemas with ConfigDict instead of legacy Config class
  • SQLAlchemy 2.0 patterns with proper imports and session management
  • Type hints throughout the codebase

📁 Project Structure

apps/backend/
├── src/
│   ├── main.py           # FastAPI application entry point
│   ├── config.py         # Environment configuration
│   ├── database.py       # Database setup and session management
│   ├── models.py         # SQLAlchemy models (User, Activity)
│   ├── schemas.py        # Pydantic request/response schemas
│   ├── activities.py     # Activities router and endpoints
│   └── auth/
│       ├── router.py     # Authentication endpoints
│       └── utils.py      # JWT and password utilities
├── tests/
│   ├── conftest.py       # Test configuration and fixtures
│   ├── test_auth.py      # Authentication flow tests
│   └── test_api.py       # API endpoint tests
├── requirements.txt      # Python dependencies
├── start.sh             # Development server startup script
└── README.md            # Documentation and setup instructions

🔧 Development Setup

The backend includes a simple startup script for development:

cd apps/backend
./start.sh  # Automatically sets up venv, installs deps, starts server

Access points:

🔒 Security Features

  • Password hashing with bcrypt for secure credential storage
  • JWT tokens with configurable expiration and secret keys
  • Protected routes requiring valid authentication headers
  • Input validation using Pydantic schemas
  • CORS configuration to control frontend access

✅ Verification

All functionality has been thoroughly tested:

  • ✅ Server starts successfully
  • ✅ All 9 tests pass
  • ✅ Authentication flows work correctly
  • ✅ Protected routes require valid tokens
  • ✅ Database operations function properly
  • ✅ API documentation generates correctly

This implementation provides a solid foundation for the La Vida Luca application's backend needs, following modern FastAPI best practices and providing a secure, well-tested API.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
la-vida-luca-app Ready Ready Preview Comment Aug 19, 2025 6:26pm
la-vida-luca-app-zd4o Ready Ready Preview Comment Aug 19, 2025 6:26pm

Co-authored-by: vidaluca77-cloud <226796821+vidaluca77-cloud@users.noreply.github.com>
…ty management

Co-authored-by: vidaluca77-cloud <226796821+vidaluca77-cloud@users.noreply.github.com>
Co-authored-by: vidaluca77-cloud <226796821+vidaluca77-cloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Backend FastAPI Implementation Implement FastAPI backend with JWT authentication and activity management Aug 19, 2025
Copilot AI requested a review from vidaluca77-cloud August 19, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants