A full-featured backend for an ecommerce platform built with FastAPI, PostgreSQL, SQLAlchemy ORM, and Google OAuth 2.0 for authentication. Product images are stored in a S3 Bucket.
- Build a modern, secure, and scalable ecommerce backend using FastAPI.
- Implement Google OAuth 2.0 for user authentication and onboarding.
- Use JWT-based access/refresh tokens for secure session management.
- Support full CRUD operations for products and categories.
- Store and retrieve product images via S3-compatible storage.
- Manage relational data with PostgreSQL using SQLAlchemy ORM.
- Provide a modular and maintainable code structure.
- Enable seamless integration with frontend or mobile applications via RESTful APIs.
- FastAPI backend with modular architecture
- User authentication via Google OAuth 2.0
- PostgreSQL database using SQLAlchemy ORM
- JWT-based access/refresh token authentication
- Product CRUD with image upload to S3
- Role-based access (user/admin)
- Alembic for database migrations
- Pydantic for request validation
.
├── app/
│ ├── api/
│ │ └── v1/
│ │ ├── auth
| | | ├── endpoints.py
| | | ├── model.py
| | | ├── repository.py
| | | ├── schema.py
| | | └── service.py
│ │ ├── category
| | | ├── endpoints.py
| | | ├── model.py
| | | ├── repository.py
| | | └── schema.py
| | ├── product
| | | ├── endpoints.py
| | | ├── model.py
| | | ├── repository.py
| | | └── schema.py
| | └── user
| | ├── endpoints.py
| | ├── model.py
| | ├── repository.py
| | ├── schema.py
| | └── service.py
│ ├── core/
│ │ ├── config.py
│ │ └── security.py
│ ├── services/
│ │ ├── s3_service.py
| | ├── email_service.py
| | └── mock_email_service.py
│ ├── utils/
│ │ └── utils.py
│ ├── db/
│
AC11
│ ├── base.py
│ │ └── session.py
│ └── main.py
├── migrations/
│ └── env.py
├── requirements.txt
├── .env
├── README.md
└── docker-compose.yml
- Google OAuth 2.0: Sign in users and generate JWT tokens.
- JWT tokens: Used for protected routes.
- User roles: Supports admin and customer access control.
- Upload product images to a mock S3 bucket hosted in LocalStack.
- Uses
boto3
SDK to interact with the S3 service. - LocalStack provides a local cloud stack for development.
docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
S3_BUCKET_NAME=product-images
S3_ENDPOINT=http://localhost:4566
- Python 3.9 or later
- PostgreSQL database for storing user, category and product details
- A virtual environment is recommended.
- LocalStack for S3-compatible object storage
git clone https://github.com/your-username/authora.git
cd authora
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Make sure PostgreSQL is running and .env
contains:
DATABASE_URL=postgresql+asyncpg://postgres:password@localhost:5432/database
alembic upgrade head
LocalStack simulates AWS services (S3) locally. Install it using pip:
pip install localstack
Start LocalStack using docker:
docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack
Verify LocalStack is running:
localstack status services
uvicorn app.main:app --reload
Register an app in Google Cloud Console:
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
REDIRECT_URI=http://localhost:8000/api/v1/auth/google/callback
POST /auth/register
— Register UserPOST /auth/verify-email
— User verify emailPOST /auth/login
— User loginPOST /auth/verify-resend-otp
— User Send OTP again for verificationPOST /auth/forgot-password
— User Forget email PasswordPUT /auth/reset-password
— User set new passwordPOST /auth/logout
— User LogoutGET /api/v1/auth/google/login
— Google Login RedirectGET /api/v1/auth/google/callback
— Google Auth Callback
GET /user/info
— User detailPATCH /product/{id}
— Update user detailDELETE /product/{id}
— Delete user by ID
GET /categories
— List categoriesGET /categories/{id}
— Get category by unique ID.POST /categories
— Create new categoryPUT /categories/{id}
— Update specific category by its unique ID.DELETE /categories/{id}
— Delete specific category by its unique ID.
GET /products/
— List productsGET /product/{id}
— Get product by idPOST /product
— Create new productPUT /product/{id}
— Update product detailDELETE /product/{id}
— Delete product by ID
curl -X POST http://localhost:8000/api/v1/product/upload-image \
-H "Authorization: Bearer <your-jwt-token>" \
-F "file=@image.png"