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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__pycache__/
*.pyc
.coverage
.pytest_cache/
*.egg-info/
dist/
build/
.env
176 changes: 176 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Setup and Run Instructions

This document provides instructions for setting up and running the Task Management API.

## Prerequisites

- Python 3.9 or higher
- pip (Python package manager)

## Installation

1. **Clone the repository** (if not already done):
```bash
git clone https://github.com/automationExamples/spec-driven-development.git
cd spec-driven-development
```

2. **Create a virtual environment** (recommended):
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```

3. **Install dependencies**:
```bash
pip install -r requirements.txt
```

## Running the Application

### Start the API Server

```bash
uvicorn app.main:app --reload
```

The API will be available at:
- **API Base URL**: http://localhost:8000
- **Interactive API Docs (Swagger)**: http://localhost:8000/docs
- **Alternative Docs (ReDoc)**: http://localhost:8000/redoc

### Available Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/` | API information |
| GET | `/health` | Health check |
| POST | `/api/tasks` | Create a new task |
| GET | `/api/tasks` | List all tasks (with optional filters) |
| GET | `/api/tasks/search?q=` | Search tasks |
| GET | `/api/tasks/{id}` | Get a specific task |
| PUT | `/api/tasks/{id}` | Update a task |
| DELETE | `/api/tasks/{id}` | Delete a task |

### Query Parameters for Filtering

- `status`: Filter by status (`pending`, `in_progress`, `completed`)
- `priority`: Filter by priority (`low`, `medium`, `high`)

Example:
```bash
curl "http://localhost:8000/api/tasks?status=pending&priority=high"
```

## Running Tests

### Run All Tests

```bash
pytest
```

### Run Tests with Verbose Output

```bash
pytest -v
```

### Run Tests with Coverage Report

```bash
pytest --cov=app --cov-report=term-missing
```

### Run Specific Test File

```bash
pytest tests/test_tasks.py -v
```

### Run Specific Test Class

```bash
pytest tests/test_tasks.py::TestCreateTask -v
```

## Example API Usage

### Create a Task

```bash
curl -X POST "http://localhost:8000/api/tasks" \
-H "Content-Type: application/json" \
-d '{"title": "Buy groceries", "priority": "high"}'
```

### List All Tasks

```bash
curl "http://localhost:8000/api/tasks"
```

### Search Tasks

```bash
curl "http://localhost:8000/api/tasks/search?q=groceries"
```

### Update a Task

```bash
curl -X PUT "http://localhost:8000/api/tasks/{task_id}" \
-H "Content-Type: application/json" \
-d '{"status": "completed"}'
```

### Delete a Task

```bash
curl -X DELETE "http://localhost:8000/api/tasks/{task_id}"
```

## Project Structure

```
/
├── SPECS/ # Feature specifications
│ ├── feature-template.md
│ ├── task-management-api.md
│ ├── testing-framework.md
│ └── project-setup.md
├── app/ # Application source code
│ ├── __init__.py
│ ├── main.py # FastAPI application entry
│ ├── models.py # Pydantic models
│ ├── storage.py # Data persistence layer
│ └── routers/
│ └── tasks.py # Task endpoints
├── tests/ # Test suite
│ ├── __init__.py
│ ├── conftest.py # Test fixtures
│ ├── test_models.py # Model unit tests
│ └── test_tasks.py # API integration tests
├── requirements.txt # Python dependencies
├── README.md # Assessment instructions
├── RULES.md # Development rules
├── TODO.md # Task tracking
└── SETUP.md # This file
```

## Troubleshooting

### Port Already in Use

If port 8000 is in use, specify a different port:
```bash
uvicorn app.main:app --reload --port 8001
```

### Import Errors

Ensure you're in the project root directory and the virtual environment is activated.

### Test Failures

Tests are isolated and should pass independently. If tests fail, ensure no other process is using the same resources.
55 changes: 55 additions & 0 deletions SPECS/project-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Feature Spec: Project Setup and Documentation

## Goal
- Establish a clean, maintainable project structure
- Provide clear documentation for running the application and tests
- Enable easy local development and testing

## Scope
- In:
- Project directory structure
- Dependency management (requirements.txt)
- Configuration management
- Run instructions documentation
- Development setup guide
- Out:
- Docker containerization
- CI/CD pipeline configuration
- Production deployment guides

## Requirements
- Python 3.9+ compatibility
- Virtual environment support
- Clear separation of concerns (app, tests, specs)
- No hardcoded secrets or credentials

## Project Structure
```
/
├── SPECS/ # Feature specifications
├── app/ # Application source code
│ ├── __init__.py
│ ├── main.py # FastAPI application entry
│ ├── models.py # Pydantic models
│ ├── storage.py # Data persistence layer
│ └── routers/
│ └── tasks.py # Task endpoints
├── tests/ # Test suite
│ ├── __init__.py
│ ├── conftest.py # Test fixtures
│ ├── test_models.py
│ └── test_tasks.py
├── requirements.txt # Python dependencies
├── README.md # Project documentation
├── RULES.md # Development rules
├── TODO.md # Task tracking
└── SETUP.md # Setup and run instructions
```

## Acceptance Criteria
- [x] Application runs with `uvicorn app.main:app`
- [x] Tests run with `pytest`
- [x] Dependencies install with `pip install -r requirements.txt`
- [x] SETUP.md contains complete run instructions
- [x] No secrets or credentials in repository
- [x] Project structure is clean and logical
62 changes: 62 additions & 0 deletions SPECS/task-management-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Feature Spec: Task Management API

## Goal
- Provide a RESTful API for managing tasks with full CRUD operations
- Enable users to organize, track, and filter tasks by status and priority
- Persist data in-memory with optional JSON file storage

## Scope
- In:
- Create, read, update, delete tasks
- List all tasks with filtering by status and priority
- Search tasks by title or description
- Data persistence (in-memory with file backup)
- Input validation and error handling
- Out:
- User authentication/authorization
- Real-time notifications
- Task assignments to multiple users
- File attachments

## Requirements
- FastAPI framework for API implementation
- Pydantic models for request/response validation
- In-memory storage with JSON file persistence option
- RESTful endpoints following standard conventions
- Proper HTTP status codes and error responses

## Data Model
```
Task:
- id: string (UUID)
- title: string (required, 1-200 chars)
- description: string (optional, max 2000 chars)
- status: enum ["pending", "in_progress", "completed"]
- priority: enum ["low", "medium", "high"]
- created_at: datetime
- updated_at: datetime
```

## API Endpoints
- POST /api/tasks - Create a new task
- GET /api/tasks - List all tasks (with optional filters)
- GET /api/tasks/{id} - Get a specific task
- PUT /api/tasks/{id} - Update a task
- DELETE /api/tasks/{id} - Delete a task
- GET /api/tasks/search - Search tasks by keyword

## Acceptance Criteria
- [x] POST /api/tasks creates a task and returns 201 with the created task
- [x] POST /api/tasks returns 422 for invalid input (missing title, invalid status)
- [x] GET /api/tasks returns all tasks with 200 status
- [x] GET /api/tasks?status=pending filters tasks by status
- [x] GET /api/tasks?priority=high filters tasks by priority
- [x] GET /api/tasks/{id} returns 200 with task details
- [x] GET /api/tasks/{id} returns 404 for non-existent task
- [x] PUT /api/tasks/{id} updates task and returns 200
- [x] PUT /api/tasks/{id} returns 404 for non-existent task
- [x] DELETE /api/tasks/{id} removes task and returns 204
- [x] DELETE /api/tasks/{id} returns 404 for non-existent task
- [x] GET /api/tasks/search?q=keyword returns matching tasks
- [x] All timestamps are automatically managed
- [x] API returns proper JSON error responses
41 changes: 41 additions & 0 deletions SPECS/testing-framework.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Feature Spec: Testing Framework

## Goal
- Comprehensive test suite for the Task Management API
- Validate all endpoints, edge cases, and error scenarios
- Ensure tests can run locally with simple commands

## Scope
- In:
- Unit tests for data models and validation
- Integration tests for API endpoints
- Edge case coverage (empty inputs, boundary values)
- Error scenario testing (404, 422 responses)
- Test fixtures and factories
- Out:
- Performance/load testing
- Security penetration testing
- UI/E2E browser testing

## Requirements
- pytest as the testing framework
- pytest-asyncio for async test support
- httpx for API testing (TestClient alternative)
- Test isolation (clean state between tests)
- Clear test naming conventions
- Coverage reporting

## Test Categories
1. **Model Tests**: Validate Pydantic models and data validation
2. **CRUD Tests**: Test create, read, update, delete operations
3. **Filter Tests**: Test query parameter filtering
4. **Search Tests**: Test search functionality
5. **Error Tests**: Test error responses and edge cases

## Acceptance Criteria
- [x] All tests pass with `pytest` command
- [x] Test coverage includes all API endpoints
- [x] Tests cover happy path and error scenarios
- [x] Tests are isolated and can run in any order
- [x] Test output is clear and informative
- [x] Coverage report is generated (92% coverage achieved)
17 changes: 15 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# TODO

## Completed
- [x] Project setup and structure
- [x] Task Management API implementation
- [x] CRUD operations (Create, Read, Update, Delete)
- [x] Task filtering by status and priority
- [x] Task search functionality
- [x] Comprehensive test suite
- [x] Documentation

## Refactor Proposals
-
- Consider adding database persistence (PostgreSQL/SQLite) for production use
- Add pagination for large task lists

## New Feature Proposals
-
- Task due dates and reminders
- Task categories/tags
- Bulk operations (delete multiple, update multiple)
- Task history/audit log
1 change: 1 addition & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Task Management API - Application Package"""
Loading