Skip to content

A FastAPI-based backend for calculating the properties of composite materials.

License

Notifications You must be signed in to change notification settings

wenbinyugroup/swiftcomp-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftComp-API

Version Build Status Last Commit

SwiftComp-API is a FastAPI-based backend designed to perform calculations related to composite laminate materials. It exposes various endpoints for computing engineering constants, plate properties, 3D laminate properties, and more. This API is suitable for researchers, engineers, and developers working in composite materials and structural analysis.

Table of Contents


Features

  • Versioned API: Support for multiple versions of the API, with versioning (v1, v2) for backward compatibility.
  • Material Property Calculations: Endpoints to calculate various laminate engineering constants and composite properties.
  • Lightweight & Fast: Built using FastAPI, ensuring high performance and minimal latency.
  • Modular Architecture: Separation of concerns using routers, services, and utility functions for better maintainability.
  • Extensible: Easy to add new endpoints and services for additional material computations.

Technologies

  • FastAPI: A modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python-type hints.
  • Python 3.7: Programming language used to implement the logic.
  • Pytest: A robust testing framework for Python.
  • Uvicorn: ASGI server used for serving FastAPI applications.
  • Virtual Environment (venv): For dependency isolation.

Public Use

The SwiftComp API is deployed online: https://swiftcomp-api-7327e882adaf.herokuapp.com

You can access API documentation at:


Installation Using Docker (recommend)

Prerequisites

  • Docker

Step-by-Step Guide

  1. Clone the repository:
git clone https://github.com/wenbinyugroup/swiftcomp-api.git
cd swiftcomp-api
  1. Building the Docker Image: You can build a Docker image for the FastAPI app using the following command:
docker build -t swiftcomp-api .
  1. Running the Docker Container: Once the image is built, you can run the application in a Docker container:
docker run -d -p 8000:8000 swiftcomp-api

This will run the SwiftComp API app in a container and map port 8000 from the container to your local machine. You can access the application at http://localhost:8000.

  1. Running Tests Inside the Docker Container: To run the tests inside the running Docker container:
docker exec $(docker ps -q -f ancestor=swiftcomp-api) bash -c "PYTHONPATH=./ pytest"

This command sets the PYTHONPATH and runs pytest inside the running Docker container.

  1. Monitoring Logs: To monitor the logs from the running Docker container in real time:
docker logs -f <container_id_or_name>

You can get the container ID or name by running:

docker ps

Installation Locally

To set up the project locally, follow these steps:

Prerequisites

  • Python 3.7 or higher.
  • Git installed on your system.

Step-by-Step Guide

  1. Clone the repository:
git clone https://github.com/wenbinyugroup/swiftcomp-api.git
cd swiftcomp-api
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install the dependencies:
pip install -r requirements.txt
  1. Run the FastAPI application locally:
uvicorn app.main:app --reload

This will start the SwiftComp API server at http://127.0.0.1:8000.

  1. Testing:

The repository includes unit tests using pytest. To run the tests:

  • Ensure you are in the virtual environment.
  • Run the following command:
PYTHONPATH=./ pytest

API Documentation

FastAPI automatically generates interactive API documentation using Swagger and Redoc. Once the server is running, you can access the documentation at:

Sample Endpoints

  • GET /: Root endpoint, returns a welcome message.
  • POST /api/v1/lamina_engineering_constants: Calculates the lamina engineering constants based on the provided material properties.
  • POST /api/v1/laminate_plate_properties: Calculates the laminate plate properties.
  • POST /api/v1/laminate_3d_properties: Computes the 3D properties of laminate.
  • POST /api/v1/udfrc_properties: Calculates UDFRC properties.

Contributing

We welcome contributions to SwiftComp-API! Here's how you can help:

  1. Fork the repository.
  2. Create a new feature branch:
git checkout -b feature/your-feature-name
  1. Commit your changes:
git commit -m "Add your message"
  1. Push to the branch:
git push origin feature/your-feature-name
  1. Create a pull request: Describe the changes you’ve made.

License

This project is licensed under the MIT License. See the LICENSE file for more details.