Automated Action 1d54b4ec09 Implement user authentication service with FastAPI
- Set up project structure and dependencies
- Create SQLAlchemy database models
- Set up Alembic for database migrations
- Implement user registration and login endpoints
- Add JWT token authentication
- Create middleware for protected routes
- Add health check endpoint
- Update README with documentation

generated with BackendIM... (backend.im)
2025-05-13 16:59:17 +00:00

85 lines
2.1 KiB
Markdown

# User Authentication Service
A FastAPI-based service for user authentication and management.
## Features
- User registration and account management
- Secure password handling with bcrypt hashing
- JWT-based authentication
- Protected API endpoints
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
## Project Structure
```
├── alembic/ # Database migration files
│ └── versions/ # Migration version files
├── app/ # Application code
│ ├── middleware/ # Middleware components
│ ├── models/ # SQLAlchemy models
│ ├── routers/ # API routes
│ ├── utils/ # Utility functions
│ ├── database.py # Database connection setup
│ ├── models.py # SQLAlchemy models
│ └── schemas.py # Pydantic schemas
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
```
## API Endpoints
### Authentication
- `POST /auth/token` - OAuth2 token endpoint (form-based)
- `POST /auth/login` - Login endpoint (JSON-based)
### Users
- `POST /users/` - Register a new user
- `GET /users/me` - Get current user information
- `GET /users/` - Get list of users
- `GET /users/{user_id}` - Get a specific user by ID
### Health Check
- `GET /health` - Health check endpoint
## Installation
1. Clone the repository
2. Install dependencies:
```
pip install -r requirements.txt
```
3. Run the application:
```
uvicorn main:app --reload
```
4. Access the API documentation at `http://localhost:8000/docs`
## Database
The application uses SQLite as the database with SQLAlchemy ORM. Database migrations are managed with Alembic.
### Creating a Migration
```bash
alembic revision --autogenerate -m "description"
```
### Running Migrations
```bash
alembic upgrade head
```
## Security
- Passwords are hashed using bcrypt
- Authentication is handled using JWT tokens
- Protected routes require a valid JWT token