Rewrite README with comprehensive documentation and modern formatting
This commit is contained in:
parent
497f7d14d5
commit
d5daca29f8
213
README.md
213
README.md
@ -1,96 +1,177 @@
|
||||
# Todo API
|
||||
# FastAPI Todo Application
|
||||
|
||||
A simple Todo application API built with FastAPI and SQLite.
|
||||
A modern, high-performance todo management API built with FastAPI, featuring a clean architecture and comprehensive functionality for task management.
|
||||
|
||||
## Features
|
||||
## 🚀 Quick Start
|
||||
|
||||
- Create, read, update, and delete todos
|
||||
- RESTful API endpoints
|
||||
- SQLite database with SQLAlchemy ORM
|
||||
- Database migrations with Alembic
|
||||
- Health check endpoint
|
||||
- CORS enabled for all origins
|
||||
- Interactive API documentation
|
||||
Get up and running in minutes:
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.7+
|
||||
- FastAPI
|
||||
- SQLAlchemy
|
||||
- Alembic
|
||||
- Uvicorn
|
||||
|
||||
## Installation
|
||||
|
||||
1. Install dependencies:
|
||||
```bash
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
2. Run database migrations:
|
||||
```bash
|
||||
# Initialize database
|
||||
alembic upgrade head
|
||||
```
|
||||
|
||||
3. Start the application:
|
||||
```bash
|
||||
# Launch the application
|
||||
uvicorn main:app --reload
|
||||
```
|
||||
|
||||
The API will be available at `http://localhost:8000`
|
||||
Access your API at `http://localhost:8000`
|
||||
|
||||
## API Endpoints
|
||||
## 📋 Features
|
||||
|
||||
### Base
|
||||
- `GET /` - API information and links to documentation
|
||||
### Core Functionality
|
||||
- ✅ Complete CRUD operations for todos
|
||||
- 🔍 Pagination support for large datasets
|
||||
- 📝 Rich todo metadata (title, description, completion status, timestamps)
|
||||
- 🏥 Health monitoring endpoint
|
||||
|
||||
### Health Check
|
||||
- `GET /health` - Health check endpoint
|
||||
### Technical Features
|
||||
- 🌐 CORS-enabled for cross-origin requests
|
||||
- 📚 Auto-generated interactive documentation
|
||||
- 🗄️ SQLite database with SQLAlchemy ORM
|
||||
- 🔄 Database migrations with Alembic
|
||||
- 🧹 Code quality with Ruff linting
|
||||
|
||||
### Todos
|
||||
- `GET /api/v1/todos` - Get all todos (with pagination)
|
||||
- `POST /api/v1/todos` - Create a new todo
|
||||
- `GET /api/v1/todos/{id}` - Get a specific todo
|
||||
- `PUT /api/v1/todos/{id}` - Update a todo
|
||||
- `DELETE /api/v1/todos/{id}` - Delete a todo
|
||||
## 🛠️ Technology Stack
|
||||
|
||||
## Documentation
|
||||
- **Framework**: FastAPI 0.104.1
|
||||
- **Database**: SQLite with SQLAlchemy 2.0.23
|
||||
- **Migrations**: Alembic 1.13.0
|
||||
- **Server**: Uvicorn 0.24.0
|
||||
- **Code Quality**: Ruff 0.1.6
|
||||
|
||||
- Interactive API docs: `http://localhost:8000/docs`
|
||||
- ReDoc documentation: `http://localhost:8000/redoc`
|
||||
- OpenAPI JSON: `http://localhost:8000/openapi.json`
|
||||
## 📖 API Reference
|
||||
|
||||
## Project Structure
|
||||
### Base Endpoints
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| GET | `/` | Application information and links |
|
||||
| GET | `/health` | Service health status |
|
||||
|
||||
### Todo Management
|
||||
| Method | Endpoint | Description | Parameters |
|
||||
|--------|----------|-------------|-----------|
|
||||
| GET | `/api/v1/todos` | List todos | `skip`, `limit` |
|
||||
| POST | `/api/v1/todos` | Create todo | `title`, `description?` |
|
||||
| GET | `/api/v1/todos/{id}` | Get specific todo | `id` |
|
||||
| PUT | `/api/v1/todos/{id}` | Update todo | `id`, fields |
|
||||
| DELETE | `/api/v1/todos/{id}` | Delete todo | `id` |
|
||||
|
||||
### Example Requests
|
||||
|
||||
**Create a Todo:**
|
||||
```bash
|
||||
curl -X POST "http://localhost:8000/api/v1/todos" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"title": "Learn FastAPI", "description": "Build awesome APIs"}'
|
||||
```
|
||||
|
||||
**List Todos:**
|
||||
```bash
|
||||
curl "http://localhost:8000/api/v1/todos?skip=0&limit=10"
|
||||
```
|
||||
|
||||
## 📚 Documentation
|
||||
|
||||
- **Interactive Docs**: [http://localhost:8000/docs](http://localhost:8000/docs)
|
||||
- **ReDoc**: [http://localhost:8000/redoc](http://localhost:8000/redoc)
|
||||
- **OpenAPI Schema**: [http://localhost:8000/openapi.json](http://localhost:8000/openapi.json)
|
||||
|
||||
## 🏗️ Architecture
|
||||
|
||||
```
|
||||
.
|
||||
├── main.py # FastAPI application entry point
|
||||
├── requirements.txt # Python dependencies
|
||||
├── alembic.ini # Alembic configuration
|
||||
├── alembic/ # Database migrations
|
||||
│ ├── env.py
|
||||
│ ├── script.py.mako
|
||||
│ └── versions/
|
||||
todoapp/
|
||||
├── main.py # Application entry point
|
||||
├── requirements.txt # Python dependencies
|
||||
├── alembic.ini # Migration configuration
|
||||
├── alembic/ # Database migrations
|
||||
│ ├── env.py # Migration environment
|
||||
│ ├── script.py.mako # Migration template
|
||||
│ └── versions/ # Migration files
|
||||
│ └── 0001_create_todos_table.py
|
||||
└── app/
|
||||
├── __init__.py
|
||||
└── app/ # Application package
|
||||
├── db/
|
||||
│ ├── __init__.py
|
||||
│ ├── base.py # SQLAlchemy declarative base
|
||||
│ └── session.py # Database session configuration
|
||||
│ ├── base.py # SQLAlchemy declarative base
|
||||
│ └── session.py # Database session management
|
||||
├── models/
|
||||
│ ├── __init__.py
|
||||
│ └── todo.py # Todo model
|
||||
│ └── todo.py # Todo data model
|
||||
└── routes/
|
||||
├── __init__.py
|
||||
├── todos.py # Todo CRUD endpoints
|
||||
└── health.py # Health check endpoint
|
||||
├── todos.py # Todo API endpoints
|
||||
└── health.py # Health check endpoint
|
||||
```
|
||||
|
||||
## Database
|
||||
## 💾 Database
|
||||
|
||||
The application uses SQLite database stored at `/app/storage/db/db.sqlite`. The database is automatically created when the application starts.
|
||||
**Storage Location**: `/app/storage/db/db.sqlite`
|
||||
|
||||
## Author
|
||||
The application uses SQLite for simplicity and portability. The database is automatically created on first run, with tables managed through Alembic migrations.
|
||||
|
||||
BackendIM
|
||||
**Todo Schema:**
|
||||
- `id`: Primary key (auto-increment)
|
||||
- `title`: Todo title (required)
|
||||
- `description`: Optional description
|
||||
- `completed`: Completion status (default: false)
|
||||
- `created_at`: Creation timestamp
|
||||
- `updated_at`: Last modification timestamp
|
||||
|
||||
## 🔧 Development
|
||||
|
||||
### Running Tests
|
||||
```bash
|
||||
# Add your test command here when tests are implemented
|
||||
pytest
|
||||
```
|
||||
|
||||
### Code Quality
|
||||
```bash
|
||||
# Lint and format code
|
||||
ruff check --fix .
|
||||
```
|
||||
|
||||
### Database Management
|
||||
```bash
|
||||
# Create new migration
|
||||
alembic revision --autogenerate -m "description"
|
||||
|
||||
# Apply migrations
|
||||
alembic upgrade head
|
||||
|
||||
# Rollback migration
|
||||
alembic downgrade -1
|
||||
```
|
||||
|
||||
## 📦 Deployment
|
||||
|
||||
For production deployment, consider:
|
||||
|
||||
1. **Environment Variables**: Configure database URL and secrets
|
||||
2. **Process Manager**: Use Gunicorn with Uvicorn workers
|
||||
3. **Reverse Proxy**: Place behind Nginx or similar
|
||||
4. **Database**: Migrate to PostgreSQL for production workloads
|
||||
|
||||
Example production command:
|
||||
```bash
|
||||
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
|
||||
```
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
3. Make your changes
|
||||
4. Run tests and linting
|
||||
5. Submit a pull request
|
||||
|
||||
## 📄 License
|
||||
|
||||
This project is open source and available under the MIT License.
|
||||
|
||||
## 👨💻 Author
|
||||
|
||||
**BackendIM** - AI Backend Code Generation Agent
|
||||
|
||||
---
|
||||
|
||||
*Built with ❤️ using FastAPI and modern Python practices*
|
Loading…
x
Reference in New Issue
Block a user