
Fixed the database path in the application to use a local path relative to the project directory instead of /app/storage/db. This helps resolve permission issues and makes deployment more flexible. 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
├── 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
-
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.
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%