Skip to content

Scalable & Secure FastAPI-based Ratings API πŸš€ REST API with JWT authentication, role-based access control (RBAC), PostgreSQL, and CI/CD. Includes monitoring (Prometheus, Grafana), security scanning, and optimized DB performance. Containerized with Docker and ready for scalable deployment.

License

Notifications You must be signed in to change notification settings

Alwil17/rating-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rating API - Comprehensive Rating & Review Platform

Rating API is a full-featured rating and review platform built with a modern tech stack. It allows users to rate and review items, discover new content through recommendations, and provides administrators with powerful analytics tools.

πŸš€ Features

User Features

  • User Authentication - Secure login/signup system
  • Item Rating & Reviews - Rate items on a 1-5 scale and leave detailed comments
  • Personal Recommendations - Get personalized recommendations based on rating history
  • Profile Management - Update personal information and view rating history

Admin Features

  • Complete User Management - Create, update, and manage user accounts
  • Item Management - Add, update, and categorize items
  • Category System - Organize items into customizable categories
  • Tag System - Add flexible tags to better describe items
  • Content Moderation - Remove inappropriate reviews/comments
  • Analytics Dashboard - Comprehensive analytics including:
    • Rating distributions
    • User growth metrics
    • Engagement statistics
    • Overall platform performance

πŸ› οΈ Technology Stack

Backend

  • FastAPI - High-performance API framework
  • SQLAlchemy - ORM for database interactions
  • PostgreSQL - Robust relational database
  • Pydantic - Data validation and settings management
  • JWT - Token-based authentication

Frontend

  • Next.js - React framework for web interface
  • React Query - Data fetching and state management
  • Tailwind CSS - Utility-first CSS framework
  • Chart.js - Data visualization

πŸ“‹ Project Structure

RatingApp/
β”‚
β”œβ”€β”€ app/                          # Backend application
β”‚   β”œβ”€β”€ api/                      # API routes and endpoints
β”‚   β”‚   β”œβ”€β”€ endpoints/            # Individual route modules
β”‚   β”‚   β”œβ”€β”€ auth.py               # Authentication handlers
β”‚   β”‚   └── security.py           # Security utilities
β”‚   β”‚
β”‚   β”œβ”€β”€ application/              # Application layer
β”‚   β”‚   β”œβ”€β”€ schemas/              # Pydantic schemas/DTOs
β”‚   β”‚   └── services/             # Business logic services
β”‚   β”‚
β”‚   β”œβ”€β”€ domain/                   # Domain models
β”‚   β”‚   β”œβ”€β”€ user.py
β”‚   β”‚   β”œβ”€β”€ item.py
β”‚   β”‚   β”œβ”€β”€ category.py
β”‚   β”‚   β”œβ”€β”€ tag.py
β”‚   β”‚   └── rating.py
β”‚   β”‚
β”‚   β”œβ”€β”€ infrastructure/           # Data access layer
β”‚   β”‚   β”œβ”€β”€ repositories/         # Repository pattern implementations
β”‚   β”‚   └── database.py           # Database connection
β”‚   β”‚
β”‚   β”œβ”€β”€ config.py                 # Application configuration
β”‚   └── main.py                   # Application entry point
β”‚
β”œβ”€β”€ migrations/                   # Database migration files
β”œβ”€β”€ tests/                        # Test suite
β”œβ”€β”€ docker/                       # Docker configuration
β”‚   β”œβ”€β”€ Dockerfile.api            # API service Dockerfile
β”‚   β”œβ”€β”€ Dockerfile.frontend       # Frontend Dockerfile
β”‚   └── docker-compose.yml        # Docker composition
β”‚
β”œβ”€β”€ requirements.txt              # Python dependencies
β”œβ”€β”€ .env.example                  # Example environment variables
└── README.md                     # Project documentation

πŸš€ Getting Started

Prerequisites

  • Python 3.9+
  • Node.js 16+
  • PostgreSQL
  • Docker (optional)

Backend Setup

  1. Clone the repository:
git clone https://github.com/Alwil17/rating-api.git
cd rating-api
  1. Set up a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment variables:
cp .env.example .env
# Edit .env with your database credentials and settings
  1. Initialize the database migrations:
# Make sure your database connection details are in .env file
# DATABASE_URL=postgresql://username:password@localhost:5432/ratingapp

# Create the versions directory if it doesn't exist
mkdir -p alembic/versions

# Create a new migration
alembic revision --autogenerate -m "Initial migration"

# Apply the migrations
alembic upgrade head
  1. Start the backend server:
uvicorn app.api.main:app --reload

🐳 Docker Setup

For a quick setup with Docker:

docker-compose up -d

This will start both the backend API and frontend services, along with a PostgreSQL database.

πŸ”’ API Authentication

The API uses JWT tokens for authentication:

  1. Get a token by calling POST /auth/token with email and password
  2. Include the token in subsequent requests as a Bearer token in the Authorization header

πŸ§ͺ Testing

Setting up a test database

Before running tests, you need to set up a test database:

# Create the test database
python setup_test_db.py

Running tests

# Run all tests
pytest

# Run specific test file
pytest tests/test_auth.py

# Run with verbose output
pytest -v

Tests use a separate database named rating_db_test by default to avoid affecting your development or production data.

πŸ“š API Documentation

API documentation is automatically generated and available at:

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Scalable & Secure FastAPI-based Ratings API πŸš€ REST API with JWT authentication, role-based access control (RBAC), PostgreSQL, and CI/CD. Includes monitoring (Prometheus, Grafana), security scanning, and optimized DB performance. Containerized with Docker and ready for scalable deployment.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages