A robust, production-ready user authentication and profile management web application built with FastAPI, SQLAlchemy, and Jinja2. This project provides secure registration, login, profile editing, and session management, following best practices for modern Python web development.
- User Registration & Login: Secure authentication using hashed passwords and JWT cookies.
- Profile Management: Users can view and edit their profile, including personal details and profile image.
- Session Management: Cookie-based authentication with secure logout.
- Responsive UI: Modern, mobile-friendly interface using Bootstrap and custom CSS.
- Asynchronous Database Access: High performance with SQLAlchemy’s async ORM.
- Extensible Structure: Modular routers, models, and utilities for easy expansion.
- Backend: FastAPI, SQLAlchemy (async), FastAPI Users
- Frontend: Jinja2 templates, Bootstrap 5, custom CSS/JS
- Database: SQLite (default, easily swappable)
- Authentication: JWT + Cookie Transport
- Password Hashing: Passlib (bcrypt)
- Other: Alembic for migrations
webfa/
├── db.py # Database setup and session management
├── init_db.py # DB initialization script
├── main.py # FastAPI app entry point
├── models/
│ └── user.py # User and UserProfile SQLAlchemy models
├── routers/
│ └── auth.py # All authentication and profile routes
├── schemas/
│ └── user.py # (Optional) Pydantic schemas for user data
├── static/ # CSS, JS, images, assets
├── templates/ # Jinja2 HTML templates
│ ├── base.html
│ ├── index.html
│ ├── login.html
│ ├── register.html
│ ├── profile.html
│ └── edit_profile.html
└── utils.py # Utility functions for auth, profile, etc.
-
Clone the repository
git clone https://github.com/Legacy-G/gb-technologies-with-fastapi.git cd fastapiproject/fastapi -
Create a virtual environment
python -m venv .venv .venv\Scripts\activate # On Windows # Or source .venv/bin/activate # On Mac/Linux
-
Install dependencies
pip install -r webfa/requirements.txt
-
Run database migrations
alembic upgrade head
-
Start the development server
uvicorn webfa.main:app --reload
-
Access the app
- Visit http://127.0.0.1:8000 in your browser.
- Register: Create a new account via
/register. - Login: Authenticate via
/login. - Profile: View your profile at
/profile. - Edit Profile: Update your details at
/edit-profile. - Logout: End your session via
/logout.
- Secret Keys: Change
SUPER_SECRET_KEYand other secrets in production. Use environment variables. - HTTPS: Always deploy behind HTTPS in production.
- Password Hashing: Uses bcrypt for secure password storage.
- Database: Swap SQLite for PostgreSQL or MySQL by updating
db.pyand your connection string. - Templates: Modify Jinja2 templates in
templates/for branding. - Static Assets: Place your CSS/JS/images in
static/.
- Fork the repo
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
This project is licensed under the MIT License.