README.md

# Archeometer

Proof of concept work for analyzing Elixir code bases. Things like:
+ Code properties: code lines, public functions, cyclomatic complexity
+ Dependency graphs: DSM, cyclic dependencies
+ Test coverage
  
The goal is to give you an insight into how a project is organized and how it could be improved.  
  
**Work In Progress**

## Installation

For the time being, this package is not in Hex. To use it you can specify the Git repository directly. If you already use Credo, be sure to use at least the `1.6.6` version.
```elixir
def deps do
  [
    {:archeometer, git: "https://gitlab.bunsan.io/RD/archeometer", only: [:dev, :test], runtime: false},

    # and if you already use Credo, be sure to use at least the 1.6.6 version and add something like this
    {:credo, "~> 1.6.6", only: [:dev, :test], runtime: false}
  ]
end
```

Or alternatively, you can clone this repository and add the dependency as a  `path: "path/to/the/repo"` instead.

### Setup for development
To use the correct Erlang and Elixir version we use [asdf-vm](https://asdf-vm.com/). You need to run
```sh
asdf install
```
on the root of the repository.

To add the git hooks you must change the default hooks path to `githooks` using the following command
```sh
git config core.hooksPath .githooks
```
with this, before each commit the hook will find issues related with compilation errors and warnings, failures in tests, issues or warnings in Credo and a correct code formatting.

### Third party dependencies

Some non Elixir dependencies are necessary:
+ [SQLite](https://www.sqlite.org/index.html) : is used to store all the project information
+ [Graphviz](https://graphviz.org/) : to create `png` dependency graphs

## Usage

### Collecting Data
Data collection is divided in several phases, depending on the requirements of each phase. To collect all the data simply run
```sh
mix arch.explore
```
And a SQLite database will be created with all the collected data.

You can also run each phase individually. They are
+ `mix arch.explore.static`: to run the static analysis section and create the database; it needs Credo
+ `mix arch.explore.xrefs`: collect cross reference data; it needs to force compile the project
+ `mix arch.explore.apps`: collect OTP application data; it needs the project to be previously compiled
+ `mix arch.explore.coverage`: collects test coverage information; it requires testing

### Explore your project
There are some predefined tasks to give you a brief overview of the project.
+ `mix arch.dsm`: will create a [Design Structure Matrix](https://dsmweb.org/introduction-to-dsm/), and will use it to find the cyclic dependencies in the project.
+ `mix arch.xref --format png --out out.png Mod1 Mod2... ModN` : will create the dependency graph and save it into a `out.png` file.
+ `mix arch.report.html` : Creates a comprehensive report on the project under review.
 
### Directly poke at the database
For everything else, you can always run queries directly into the generated database. For example, to get the top 10 modules with more lines you could run

```sql
select m.name, m.num_lines
from modules m
order by num_lines desc
limit 10;
```

There are plenty of more examples in the [Wiki](https://gitlab.bunsan.io/RD/archeometer/-/wikis/home)!