This chapter describes Katari general architecture.
Katari applications are designed with modularity in mind, so the main concept in Katari is a module. Each module is a reusable independent 'vertical cut' in the functionality, spanning from the UI down to persistence.
Modules are contained in a Katari application, that serves as a module container. The module container provides common services to all modules, like request dispatching, menu registration, security infrastructure, and more.
The full stack of each module (view, application and domain) can be independently packed in a jar and reused in many applications.
The following figure gives a global overview of how a Katari application is structured.

Modules are plugged with the help of spring. There are three 'points of contact' between modules: the view, the domain and the database.
At the view layer, the application consists of a servlet that dispatches the request to the corresponding module. This servlet listens to all requests that go to context/module. From there, the servlet dispatches the request to the corresponding module. The modules are mapped with the following url: context/module/module-name.
For example, if the application is deployed at localhost:8098, the main module servlet gets all requests that go to:
http://localhost:8098/acme-coyote/module.
The user module gets mapped to the following url:
http://localhost:8098/acme-coyote/module/user.
The following figure describes how a request is dispatched to the destination servlet in a module, considering a request to <http://localhost:8098/acme-coyote/module/user/editUser.do>.

As you can see, the main entry point for a servlet request is the SpringBootstrapServlet. This is a servlet that simply passes the request to another servlet. The target server is configured in the spring application context, under a bean named, by default, 'katari.moduleContainer'. This bean is an instance of ModuleContainerServlet whose responsibility is to know all the modules registered in an application and dispatch the request to the corresponding module.
Each module defines it's own domain model. We recommend following Evans recomendations layed out in Domain Driven Design. You will find entities, value objects, repositories, factories and services in modules implemented by us.
All modules share the same classloader, so a module can use any public class from another module. With the help of spring, a module can export a service that can be used by any other module.
There is one database for all the modules. The database configuration is injected in every module through spring.
When you write a module, you need to provide a spring bean that implements the Module interface. You usually use an instance of ConfigurableModule so you don't need to implement it yourself. The module interface defines:
void init(final com.globant.katari.core.web.ModuleContext context);
void destroy();
When the spring application context starts up, a special Katari provided bean factory post-processor (ModuleBeanPostProcessor) takes care of initializing all the modules declared in the application context. This post-processor creates an instance of ModuleContext for each module and calls init. The ModuleContext is the point of contact between the module and its container. It allows the module to declare:

As mentioned earlier, Katari uses spring as its DI framework. Katari makes heavy use of spring to split the application into modules. A normal Katari application has a main bean definition file usually called applicationContext.xml, located in the WEB-INF directory of the webapp. This file imports the module spring files, called module.xml (for example /com/globant/katari/editablepages/module.xml) with the katari:import element, and overrides some other beans to configure the modules (for example, the data source connection information.)
A typical applicationContext.xml file looks like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:katari="http://www.globant.com/schema/katari"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.globant.com/schema/katari
http://www.globant.com/schema/katari/katari.xsd">
<!-- The katari global beans. -->
<import resource="classpath:/com/globant/katari/core/applicationContext.xml"/>
<!-- The home module. -->
<katari:import module="com.globant.katari.sample.home"/>
<!-- The classic menu module. -->
<katari:import module="com.globant.katari.menu.classic"/>
.... more modules ....
<!-- The hibernate properties, They are referenced from the hibernate bean. -->
<bean id="katari.hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5InnoDBDialect
</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
... more datasource properties ....
</bean>
<!-- The katari data source as an alias to dataSource. -->
<alias name="dataSource" alias="katari.dataSource"/>
... more configuration beans ...
</beans>A sample module.xml file is:
<beans ... >
<bean id="editable-pages.module"
class="com.globant.katari.core.web.ConfigurableModule">
<property name='entryPoints'>
<!-- The servlet mappings. It maps the spring DispatcherServlet to *.do.
-->
<bean
...
</property>
</bean
<bean class='com.globant.katari.core.web.ListFactoryAppender'>
<constructor-arg value='katari.persistentClasses'/>
<constructor-arg>
<list>
<value>com.globant.katari.editablepages.domain.Page</value>
</list>
</constructor-arg>
</bean>
... other beans ...
</beans>Given that beans defined in module.xml files share the same spring bean factory, every bean must comply to a strict naming convention:
This convention guarantees that beans do not accidentally override each other.
Katari includes the following modules:
There are also a couple of sample modules that are included in the main web application:
Katari modules use a traditional layered model, consisting of the following four layers:
The view layer is permitted to call just one method per request en the application layer, plus additional idempotent methods when rendering the view.

The view and the application layer depends on the domain layer: classes from the domain layer can be imported in the view and/or application layers.
Katari modules do not need to follow this layering schema, but it is our recomended approach.
Katari integrates the following libraries and tools:
http://www.acegisecurity.org
http://www.springframework.org
http://www.springframework.org
http://www.hibernate.org
http://freemarker.org
http://opensymphony.com/sitemesh
http://www.ja-sig.org/products/cas
http://logging.apache.org/log4j
http://commons.apache.org
http://www.easymock.org
http://www.junit.org