Skip to content

WorkforceMentor/Main-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WorkforceMentor Backend API

A modern, well-structured FastAPI backend for the WorkforceMentor application with authentication, user management, and comprehensive development tools.

πŸš€ Features

  • 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

πŸ“ Project Structure

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

πŸ› οΈ Installation

Prerequisites

  • Python 3.11+
  • PostgreSQL 12+
  • Redis 6+
  • Docker & Docker Compose (optional)

Local Development Setup

  1. Clone the repository

    git clone <repository-url>
    cd workforcementor/back-end
  2. Create virtual environment

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

    pip install -r requirements/dev.txt
  4. Environment Configuration

    cp .env.example .env
    # Edit .env with your configuration
  5. Database Setup

    # Create PostgreSQL database
    createdb workforcementor
    
    # Run migrations
    alembic upgrade head
  6. Start Redis

    redis-server
  7. Run the application

    python main.py

Docker Setup

  1. Start services

    docker-compose up -d
  2. Run migrations

    docker-compose exec app alembic upgrade head

πŸ§ͺ Testing

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

πŸ”§ Development Tools

Code Formatting & Linting

# 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/

Pre-commit Hooks

# Install pre-commit hooks
pre-commit install

# Run hooks manually
pre-commit run --all-files

πŸ“š API Documentation

Once the application is running, access the interactive API documentation:

πŸ” Authentication

The API uses JWT-based authentication. To authenticate:

  1. Register a new user at POST /api/v1/auth/register
  2. Login at POST /api/v1/auth/login
  3. Use the returned access token in the Authorization header:
    Authorization: Bearer <access_token>
    

Protected Endpoints

  • GET /api/v1/users/me - Get current user profile
  • PUT /api/v1/users/me - Update current user profile
  • GET /api/v1/users/ - Get all users (admin only)
  • DELETE /api/v1/users/{user_id} - Delete user (admin only)

πŸ—„οΈ Database

Models

  • User: User accounts with email, password, role, and profile information
  • Enums: UserRole (ADMIN, EXPERT, EMPLOYEE)

Migrations

# Create a new migration
alembic revision --autogenerate -m "Description of changes"

# Apply migrations
alembic upgrade head

# Rollback migration
alembic downgrade -1

πŸš€ Deployment

Production Dependencies

pip install -r requirements/prod.txt

Environment Variables

Set 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

Docker Production

# Build production image
docker build -t workforcementor-backend .

# Run with production settings
docker run -p 8000:8000 --env-file .env workforcementor-backend

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make your changes
  4. Run tests: pytest
  5. Format code: black . && isort .
  6. Commit changes: git commit -m "Add new feature"
  7. Push to branch: git push origin feature/new-feature
  8. Submit a pull request

πŸ“ License

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

πŸ†˜ Support

For support, please contact the development team or create an issue in the repository.

πŸ”„ API Endpoints

Authentication

  • POST /api/v1/auth/register - Register new user
  • POST /api/v1/auth/login - Login user
  • POST /api/v1/auth/logout - Logout user
  • POST /api/v1/auth/refresh - Refresh access token
  • POST /api/v1/auth/forgot-password - Request password reset
  • POST /api/v1/auth/reset-password - Reset password

Users

  • GET /api/v1/users/me - Get current user profile
  • PUT /api/v1/users/me - Update current user profile
  • GET /api/v1/users/ - Get all users (admin)
  • DELETE /api/v1/users/{user_id} - Delete user (admin)

Health

  • GET /api/v1/health/health - Basic health check
  • GET /api/v1/health/db - Database health check

Root

  • GET / - API information
  • GET /db-test - Database connection test

About

Main Sever for WorkforceMember - FastAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages