72 Miles

Recent News

Archives

72 Miles on Flickr

Enjoy our content? Please subscribe to read new content weekly.
April 2, 2008 @ 10:01 pm

Architecture Rules 101

How about a short, sweet introduction to Architecture Rules.

The Basics

  • Java.
  • Open Source.
  • Asserts architectural rules via unit tests.
  • Write your rules in XML.
  • Run your tests with junit, ant, or a continuous integration server.

Your Rules

You define your rules. For example, if you are developing n-tiered software, you probably have three layers. A DAO/integration layer, a service/business layer, and a presentation layer. Generally, the presentation layer does not interact directly with the integration layer. You could describe this rule as: com.company.project.presentation can not depend on the com.company.project.integration package. Its that easy.

The XML

The XML is in architecture-rules.xml and contains two section: <configuration> and <rules>. Configuration describes where your files are, and the rules simply describe a package, and one or more packages that it can not depend on.


<architecture>

<configuration>
<sources>
<source>\target\classes</source>
</sources>
</configuration>

<rules>

<rule id="dao">
<packages>
<package>
com.company.project.presentation
</package>
</packages>
<violations>
<violation>
com.company.project.integration
</violation>
</violations>
</rule>

</rules>

</architecture>

Thats it. You have a simple architecture-rules.xml.

The Unit Test

Just extend and run your tests.


public class SimpleArchitectureTest
extends AbstractArchitectureRulesConfigurationTest {

public String getConfigurationFileName() {
return "architecture-rules.xml";
}

public void testArchitecture() {
assertTrue(doTests());
}
}

More Features

In Architecture Rules 201, we’ll show you how to check for cycles (cyclic dependencies), write more action-packed rules, and describe how to handle source paths that can’t be found. We can also take a gander at the various Exceptions that can be thrown when rules are broken.

Go Get It

The next thing to do, is to go get it and try it out. Download, svn checkout, or put it in your pom.xml. Just add this repository:


<repository>
<id>architect-rules-repo</id>
<name>
architecture-rules hosted by code.google.com
</name>
<layout>default</layout>
<url>
http://architecturerules.googlecode.com/svn/maven2/
</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>

And this dependency:


<dependency>
<groupId>com.seventytwomiles</groupId>
<artifactId>architecture-rules</artifactId>
<version>2.0.3</version>
</dependency>

architecture rules xml architecture rules java

Now that you've read what we think, what did you like about the post? Where do you think we went wrong? Join or star the discussion.

Filed under Architecture-Rules, Open Source

About the Author

Mike Nereson has been a professional software developer since 2000. He thinks open source is rad, and is an active volunteer Fire Fighter.

1 Comment »

  1. Posted by Openversion blog » Blog Archive » Project highlight: Architecture Rules

    July 3, 2008 @ 7:46 am

    [...] Short Introduction [...]

RSS feed for comments on this post · TrackBack URI

Leave a Comment

About

72 Miles Software - open source software, search engine optimization analytics, and software startup information. Software by design. Read More

Categories

Links