
Added information about the storage directory and updated installation instructions with database setup steps. generated with BackendIM... (backend.im)
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 userGET /users/me
- Get current user informationGET /users/
- Get list of usersGET /users/{user_id}
- Get a specific user by ID
Health Check
GET /health
- Health check endpoint
Installation
-
Clone the repository
-
Install dependencies:
pip install -r requirements.txt
-
Make sure the storage directory exists:
mkdir -p storage/db
-
Run the database migrations:
alembic upgrade head
-
Run the application:
uvicorn main:app --reload
-
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
alembic revision --autogenerate -m "description"
Running Migrations
alembic upgrade head
Security
- Passwords are hashed using bcrypt
- Authentication is handled using JWT tokens
- Protected routes require a valid JWT token
Description
Languages
Python
97%
Mako
3%