Skip to content

A serverless backend for managing user tasks, built with AWS Lambda, Python 3.12, and the Serverless Framework. This service provides user registration, authentication, and full CRUD operations on tasks.

Notifications You must be signed in to change notification settings

savg92/task-manager-backend

Repository files navigation

Task Manager Backend

A serverless backend for managing user tasks, built with AWS Lambda, Python 3.12, and the Serverless Framework. This service provides user registration, authentication, and full CRUD operations on tasks.

Table of Contents

Features

  • User registration and login (JWT-based authentication)
  • Create, read, update, and delete tasks
  • Serverless deployment on AWS Lambda with HTTP API Gateway
  • Environment-based configuration with dotenv

Prerequisites

  • Node.js >= 16

  • Python 3.12

  • Docker (for building Python dependencies)

  • AWS CLI configured with appropriate IAM permissions

  • Serverless Framework CLI installed globally:

    npm install -g serverless

Installation

  1. Clone the repo:
    git clone https://github.com/savg92/task-manager-backend
    cd task-manager-backend
  2. Install NPM dev dependencies:
    npm install
  3. Install Python runtime dependencies (you can use a virtual environment):
    python3 -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt

Configuration

  • Copy the .env.example file in the project root to .env and fill in your values:
# MongoDB Atlas connection details
MONGO_USER="<db_username>"
MONGO_PASS="<db_password>"
MONGO_HOST="<cluster_host>"

# JWT secret for token signing
JWT_SECRET="<your_jwt_secret>"

The Serverless Framework will automatically load these values.

Usage

Local Testing

You can test individual functions locally:

# Test database connection
python test_db_connection.py

# Invoke a Lambda handler locally (example: getTasks)
serverless invoke local -f getTasks --path sample_event.json

Deployment

Deploy to AWS:

serverless deploy -v

After deployment, you'll receive HTTP endpoints for all functions.

API Endpoints

Method Path Description
POST /register Register a new user
POST /login Authenticate and receive a JWT
POST /tasks Create a new task (authenticated)
GET /tasks Fetch all tasks for the user
GET /tasks/{taskId} Fetch a single task by ID
PUT /tasks/{taskId}/status Update task status (authenticated)
DELETE /tasks/{taskId} Delete a task (authenticated)
GET /docs Serve static HTML API documentation
GET /openapi.yaml Serve the raw OpenAPI specification

All routes requiring authentication (/tasks and sub-routes) need an Authorization: Bearer <token> header obtained from the /login endpoint.

Testing

  • Database Connection: Verify access to MongoDB:
    python test_db_connection.py
  • Unit Tests: Run the unit test suite using pytest:
    pytest -v tests/

Documentation

Project Structure

.
├── auth_handlers.py        # User registration & login logic
├── db.py                   # MongoDB client setup
├── docs_handlers.py        # Handlers for serving API docs
├── handler.py              # Task CRUD handlers
├── open_docs.py            # Script to serve docs locally
├── package.json            # NPM dev dependencies (Serverless plugins)
├── readme.md               # This file
├── requirements.txt        # Python runtime dependencies
├── serverless.yml          # Serverless service configuration
├── test_db_connection.py   # DB connection test script
├── docs/
│   ├── index.html          # Static HTML documentation page
│   └── openapi.yaml        # OpenAPI 3.x specification
└── tests/
    ├── __init__.py
    ├── conftest.py         # Pytest fixtures and configuration
    ├── test_auth_handlers.py # Tests for auth_handlers.py
    ├── test_docs_handlers.py # Tests for docs_handlers.py
    └── test_handler.py       # Tests for handler.py

About

A serverless backend for managing user tasks, built with AWS Lambda, Python 3.12, and the Serverless Framework. This service provides user registration, authentication, and full CRUD operations on tasks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published