A modern, well-structured FastAPI backend for the WorkforceMentor application with authentication, user management, and comprehensive development tools.
- FastAPI Framework - Modern, fast web framework for building APIs
- Async SQLAlchemy - Async database operations with PostgreSQL
- JWT Authentication - Secure token-based authentication
- Redis Caching - High-performance caching layer
- Email Service - SMTP email functionality
- Comprehensive Testing - Unit and integration tests with pytest
- Code Quality Tools - Black, isort, flake8, mypy, pre-commit hooks
- Docker Support - Containerized application with docker-compose
- Database Migrations - Alembic for database schema management
- API Documentation - Auto-generated OpenAPI/Swagger docs
workforcementor/back-end/
βββ app/ # Application code
β βββ api/ # API layer
β β βββ deps.py # Dependencies
β β βββ middleware.py # Custom middleware
β β βββ v1/ # API version 1
β β βββ endpoints/ # API endpoints
β β βββ router.py # Main router
β βββ core/ # Core functionality
β β βββ config.py # Configuration
β β βββ security.py # Security utilities
β βββ crud/ # Database operations
β βββ db/ # Database layer
β βββ models/ # SQLAlchemy models
β βββ schemas/ # Pydantic schemas
β βββ services/ # Business logic
β βββ utils/ # Utility functions
β βββ cache/ # Caching layer
βββ tests/ # Test suite
βββ migrations/ # Database migrations
βββ requirements/ # Dependencies
βββ docker-compose.yml # Docker services
βββ Dockerfile # Application container
βββ README.md # This file
- Python 3.11+
- PostgreSQL 12+
- Redis 6+
- Docker & Docker Compose (optional)
-
Clone the repository
git clone <repository-url> cd workforcementor/back-end
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements/dev.txt
-
Environment Configuration
cp .env.example .env # Edit .env with your configuration -
Database Setup
# Create PostgreSQL database createdb workforcementor # Run migrations alembic upgrade head
-
Start Redis
redis-server
-
Run the application
python main.py
-
Start services
docker-compose up -d
-
Run migrations
docker-compose exec app alembic upgrade head
Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=app
# Run specific test file
pytest tests/test_auth.py
# Run with verbose output
pytest -v# Format code with Black
black app/ tests/
# Sort imports with isort
isort app/ tests/
# Lint with flake8
flake8 app/ tests/
# Type checking with mypy
mypy app/# Install pre-commit hooks
pre-commit install
# Run hooks manually
pre-commit run --all-filesOnce the application is running, access the interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
The API uses JWT-based authentication. To authenticate:
- Register a new user at
POST /api/v1/auth/register - Login at
POST /api/v1/auth/login - Use the returned access token in the Authorization header:
Authorization: Bearer <access_token>
GET /api/v1/users/me- Get current user profilePUT /api/v1/users/me- Update current user profileGET /api/v1/users/- Get all users (admin only)DELETE /api/v1/users/{user_id}- Delete user (admin only)
- User: User accounts with email, password, role, and profile information
- Enums: UserRole (ADMIN, EXPERT, EMPLOYEE)
# Create a new migration
alembic revision --autogenerate -m "Description of changes"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1pip install -r requirements/prod.txtSet the following environment variables for production:
APP_NAME=WorkforceMentor Backend
DATABASE_URL=postgresql+asyncpg://user:password@host:port/dbname
REDIS_HOST=redis-host
REDIS_PORT=6379
SECRET_KEY=your-secret-key
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-password
FROM_EMAIL=your-email@gmail.com
FROM_NAME=WorkforceMentor# Build production image
docker build -t workforcementor-backend .
# Run with production settings
docker run -p 8000:8000 --env-file .env workforcementor-backend- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Make your changes
- Run tests:
pytest - Format code:
black . && isort . - Commit changes:
git commit -m "Add new feature" - Push to branch:
git push origin feature/new-feature - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please contact the development team or create an issue in the repository.
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- Login userPOST /api/v1/auth/logout- Logout userPOST /api/v1/auth/refresh- Refresh access tokenPOST /api/v1/auth/forgot-password- Request password resetPOST /api/v1/auth/reset-password- Reset password
GET /api/v1/users/me- Get current user profilePUT /api/v1/users/me- Update current user profileGET /api/v1/users/- Get all users (admin)DELETE /api/v1/users/{user_id}- Delete user (admin)
GET /api/v1/health/health- Basic health checkGET /api/v1/health/db- Database health check
GET /- API informationGET /db-test- Database connection test