- Casper Frøding
- Mads Nørklit Jensen
This is the repository supporting our Bachelor thesis on AI for Software Architecture.
This tool analyzes software repositories to detect violations of architectural principles using AI. Currently it uses Antropic API, and can only analyse code in regards to the Onion Architecture. It can be run manually, or integrated with GitHub pipelines to automate architectural checks during development.
When run, the tool outputs a list of architectural violations, in regards to the Onion Architecture, such as this example:
1. ‘UserDTO‘ in Application layer directly references Domain entity (User) in its constructor, violating dependency rule as Application should not depend directly on concrete Domain entities.
2. ‘SpecificationEvaluator‘ in Infrastructure layer uses Domain interfaces (‘IS-pecification‘) and models (‘BaseEntity‘), but is not implementing any Domain interface itself, making it an infrastructure concern that’s too tightly coupled to Domain.
3. ‘UserService‘ in Application layer directly instantiates Domain entities(User), violating the dependency inversion principle. It should use a factory or mapper.-
Clone the Repository (if applicable):
git clone https://github.com/AIForSoftArchi/bachelor cd bachelor -
Create Virtual Environment (if not already created):
python -m venv .venv
-
Activate the Virtual Environment:
-
On Windows:
.venv\Scripts\activate
-
On macOS/Linux:
source .venv/bin/activate
-
-
Install Dependencies:
pip install -r requirements.txt
-
Inputting secrets: To input the key for Anthropic API, you should create a .env file, and in this file input your personal key:
ANTHROPIC_API_KEY= {YOUR ANTHROPIC API KEY HERE!}
After activating the virtual environment and installing dependencies, the project can be manually run with the command:
python main.pyTo integrate into a pipeline, the project can be put in the same github repository as the code that should be analysed. The project automatically detects if it is run by a pipeline, or manually, so everything that is needed is to setup a yaml file, to make the analysis happen when desired. Under here is an example of a yaml file, from a github repository that has saved our project in a folder called .scripts , and the analysis is run on every push and pull request:
name: Architecture checking prototype
on:
push:
pull_request:
jobs:
check:
runs-on: windows-latest
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
PYTHONIOENCODING: utf-8
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -r .scripts/requirements.txt || true
- name: Run architecture check
run: python .scripts/main.pyNotice that you should not upload the Anthropic API key directly to a .env file in the repisitory, but instead go through Github's own secret integration, like in the above example
This project is licensed under the MIT License. See the LICENSE file for details.