A modern FastAPI backend application with GraphQL support, SQLAlchemy, and PostgreSQL.
- FastAPI - Modern, fast web framework for building APIs
- GraphQL - Query language with Strawberry GraphQL
- SQLAlchemy - SQL toolkit and ORM with async support
- PostgreSQL - Advanced open source relational database
- Docker - Containerization for development and deployment
- Alembic - Database migration tool
- Pytest - Testing framework with async support
- π High Performance: FastAPI with async/await support
- π GraphQL API: Flexible query language with Strawberry
- ποΈ Database: PostgreSQL with SQLAlchemy ORM
- π³ Docker Ready: Full containerization setup
- π§ͺ Testing: Comprehensive test suite with pytest
- π Auto Documentation: Interactive API docs with Swagger/ReDoc
- π§ Developer Tools: Code formatting, linting, and type checking
- Python 3.11+
- Docker and Docker Compose
- Git
-
Clone the repository:
git clone <repository-url> cd Revo-Backend
-
Run the setup script:
make setup
-
Start the database:
make docker-up
-
Create and run migrations:
make migration name="initial" make migrate -
Start the application:
make run
The API will be available at:
- REST API: http://localhost:8000
- GraphQL Playground: http://localhost:8000/graphql
- API Documentation: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Revo-Backend/
βββ app/ # Main application package
β βββ __init__.py
β βββ main.py # FastAPI application setup
β βββ core/ # Core configuration
β β βββ __init__.py
β β βββ config.py # Pydantic settings
β β βββ database.py # SQLAlchemy async setup
β βββ models/ # SQLAlchemy models (modular by domain)
β β βββ __init__.py # Centralized model imports
β β βββ base.py # Base model class
β β βββ users/ # User domain models
β β β βββ __init__.py
β β β βββ user.py # User authentication
β β βββ farmers/ # Farmer domain models
β β β βββ __init__.py
β β β βββ farmer.py # Farmer profiles
β β β βββ verification.py # Farm verification system
β β βββ products/ # Product domain models
β β β βββ __init__.py
β β β βββ product.py # Agricultural products
β β βββ orders/ # Order domain models
β β β βββ __init__.py
β β β βββ order.py # Orders and order items
β β βββ shared/ # Shared models
β β βββ __init__.py
β β βββ location.py # Geographic locations
β βββ schemas/ # Pydantic schemas
β β βββ __init__.py
β β βββ user.py # User DTOs
β βββ services/ # Business logic
β β βββ __init__.py
β β βββ user_service.py # User operations
β βββ graphql/ # GraphQL schema and resolvers
β β βββ __init__.py
β β βββ schema.py # Main GraphQL schema
β β βββ types/ # GraphQL types
β β β βββ __init__.py
β β β βββ user_type.py # User GraphQL types
β β βββ resolvers/ # GraphQL resolvers
β β βββ __init__.py
β β βββ user_resolver.py # User operations
β βββ api/ # REST API endpoints
β βββ __init__.py
β βββ health.py # Health check endpoints
βββ tests/ # Test suite
β βββ __init__.py
β βββ conftest.py # Test configuration
βββ alembic/ # Database migrations
β βββ env.py # Alembic environment
β βββ script.py.mako # Migration template
β βββ versions/ # Migration files
βββ scripts/ # Utility scripts
β βββ setup.sh # Setup script
β βββ start.sh # Start script
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ docker-compose.yml # Docker services
βββ Dockerfile # Application container
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Python project configuration
βββ alembic.ini # Alembic configuration
βββ Makefile # Development commands
βββ CONTRIBUTING.md # Contribution guidelines
βββ PROJECT_OVERVIEW.md # Project documentation
Use the Makefile for common development tasks:
make help # Show all available commands
make setup # Initial project setup
make run # Start the application
make test # Run tests with coverage
make lint # Run code linting
make format # Format code with black and isort
make docker-up # Start services with Docker
make docker-down # Stop Docker services
make migration # Create database migration
make migrate # Apply database migrationsquery {
users {
id
email
username
isActive
createdAt
}
}mutation {
createUser(userInput: {
email: "[email protected]"
username: "newuser"
password: "securepassword"
}) {
id
email
username
}
}- Copy
.env.exampleto.envand fill in your local credentials. - Never commit real secrets or credentials to version control.
Create a .env file from the example:
cp .env.example .envKey environment variables:
ENVIRONMENT- Application environment (development/production)DATABASE_URL- PostgreSQL connection stringSECRET_KEY- JWT secret key for authenticationALLOWED_ORIGINS- CORS allowed origins
Run the test suite:
# Run all tests with coverage
make test
# Run specific test file
pytest tests/test_main.py -v
# Run tests with coverage report
pytest --cov=app --cov-report=html tests/-
Setup virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt pip install -e ".[dev]" -
Setup database and run migrations:
# Start PostgreSQL (adjust for your setup) # Then run migrations alembic upgrade head
-
Start the application:
uvicorn app.main:app --reload
The project includes several tools for maintaining code quality:
- Black - Code formatting
- isort - Import sorting
- flake8 - Linting
- mypy - Type checking
- pytest - Testing framework
Run all quality checks:
make lint
make format
make test- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License.