
Added information about the storage directory and updated installation instructions with database setup steps. generated with BackendIM... (backend.im)
99 lines
2.5 KiB
Markdown
99 lines
2.5 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
|
|
├── storage/ # Storage directory
|
|
│ └── db/ # Database files
|
|
├── 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. Make sure the storage directory exists:
|
|
```
|
|
mkdir -p storage/db
|
|
```
|
|
|
|
4. Run the database migrations:
|
|
```
|
|
alembic upgrade head
|
|
```
|
|
|
|
5. Run the application:
|
|
```
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
6. 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.
|
|
|
|
The database file is stored in the `storage/db` directory at the project root. This path is configured in `app/database.py` and `alembic/env.py`.
|
|
|
|
### 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 |