Skip to content

Crypto-Jaguars/Revo-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

266 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Revo Backend

A modern FastAPI backend application with GraphQL support, SQLAlchemy, and PostgreSQL.

Tech Stack

  • 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

Features

  • πŸš€ 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

Getting Started

Prerequisites

  • Python 3.11+
  • Docker and Docker Compose
  • Git

Quick Setup

  1. Clone the repository:

    git clone <repository-url>
    cd Revo-Backend
  2. Run the setup script:

    make setup
  3. Start the database:

    make docker-up
  4. Create and run migrations:

    make migration name="initial"
    make migrate
  5. Start the application:

    make run

The API will be available at:

Project Structure

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

Available Commands

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 migrations

GraphQL Examples

Query Users

query {
  users {
    id
    email
    username
    isActive
    createdAt
  }
}

Create User

mutation {
  createUser(userInput: {
    email: "[email protected]"
    username: "newuser"
    password: "securepassword"
  }) {
    id
    email
    username
  }
}

Environment Setup

  1. Copy .env.example to .env and fill in your local credentials.
  2. Never commit real secrets or credentials to version control.

Environment Variables

Create a .env file from the example:

cp .env.example .env

Key environment variables:

  • ENVIRONMENT - Application environment (development/production)
  • DATABASE_URL - PostgreSQL connection string
  • SECRET_KEY - JWT secret key for authentication
  • ALLOWED_ORIGINS - CORS allowed origins

Testing

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/

Development

Local Development (without Docker)

  1. Setup virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  2. Install dependencies:

    pip install -r requirements.txt
    pip install -e ".[dev]"
  3. Setup database and run migrations:

    # Start PostgreSQL (adjust for your setup)
    # Then run migrations
    alembic upgrade head
  4. Start the application:

    uvicorn app.main:app --reload

Code Quality

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

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors