Fix WSGI custom addons path
[odoo/odoo.git] / doc / 02_architecture.rst
1 ========================================
2 Architecture
3 ========================================
4
5 OpenERP as a multitenant three-tiers architecture
6 =================================================
7
8 This section presents the OpenERP architecture along with technology details
9 of the application. The tiers composing OpenERP are presented. Communication
10 means and protocols between the application components are also presented.
11 Some details about used development languages and technology stack are then summarized.
12
13 OpenERP is a `multitenant <http://en.wikipedia.org/wiki/Multitenancy>`_, `three-tiers architecture 
14 <http://en.wikipedia.org/wiki/Multitier_architecture#Three-tier_architecture>`_:
15 database tier for data storage, application tier for processing and functionalities
16 and presentation tier providing user interface. Those are separate layers
17 inside OpenERP. The application tier itself is written as a core; multiple
18 additional modules can be installed in order to create a particular instance
19 of OpenERP adapted to specific needs and requirements. Moreover, OpenERP
20 follows the Model-View-Controller (MVC) architectural pattern.
21
22 A typical deployment of OpenERP is shown on `Figure 1`_. This deployment is
23 called Web embedded deployment. As shown, an OpenERP system consists of
24 three main components:
25
26 - a PostgreSQL database server which contains all OpenERP databases. 
27   Databases contain all application data, and also most of the OpenERP
28   system configuration elements. Note that this server can possibly be
29   deployed using clustered databases.
30 - the OpenERP Server, which contains all the enterprise logic and ensures
31   that OpenERP runs optimally. One layer of the server is dedicated to
32   communicate and interface with the PostgreSQL database, the ORM engine.
33   Another layer allows communications between the server and a web browser,
34   the Web layer. Having more than one server is possible, for example in
35   conjunction with a load balancing mechanism.
36 - the client running in the a web browser as javascript application.
37
38 The database server and the OpenERP server can be installed on the same
39 computer, or distributed onto separate computer servers, for example for
40 performance considerations.
41
42 .. _`Figure 1`:
43 .. figure:: _static/02_openerp_architecture.png
44    :width: 50%
45    :alt: OpenERP 6.1 architecture for embedded web deployment
46    :align: center
47    
48    OpenERP 6.1 architecture for embedded web deployment
49
50 The next subsections give details about the different tiers of the OpenERP
51 architecture.
52
53 PostgreSQL database
54 +++++++++++++++++++
55
56 The data tier of OpenERP is provided by a PostgreSQL relational database.
57 While direct SQL queries can be executed from OpenERP modules, most accesses
58 to the relational database are done through the server Object Relational
59 Mapping layer.
60
61 Databases contain all application data, and also most of the OpenERP system
62 configuration elements. Note that this server can possibly be deployed using
63 clustered databases.
64
65 OpenERP server
66 ++++++++++++++
67
68 OpenERP provides an application server on which specific business applications
69 can be built. It is also a complete development framework, offering a range
70 of features to write those applications. Among those features, the OpenERP
71 ORM provides functionalities and an interface on top of the PostgreSQL server.
72 The OpenERP server also features a specific layer designed to communicate
73 with the web browser-based client. This layer connects users using standard
74 browsers to the server.
75
76 From a developer perspective, the server acts both as a library which brings
77 the above benefits while hiding the low-level details, and as a simple way
78 to install, configure and run the written applications. The server also contains
79 other services, such as extensible data models and view, workflow engine or
80 reports engine. However, those are OpenERP services not specifically related
81 to security, and are therefore not discussed in details in this document.
82
83 **Server - ORM**
84
85 The Object Relational Mapping ORM layer is one of the salient features of
86 the OpenERP Server. It provides additional and essential functionalities
87 on top of PostgreSQL server. Data models are described in Python and OpenERP
88 creates the underlying database tables using this ORM. All the benefits of
89 RDBMS such as unique constraints, relational integrity or efficient querying
90 are used and completed by Python flexibility. For instance, arbitrary constraints
91 written in Python can be added to any model. Different modular extensibility
92 mechanisms are also afforded by OpenERP.
93
94 It is important to understand the ORM responsibility before attempting to
95 by-pass it and to access directly the underlying database via raw SQL queries.
96 When using the ORM, OpenERP can make sure the data remains free of any corruption.
97 For instance, a module can react to data creation in a particular table.
98 This behavior can occur only if queries go through the ORM.
99
100 The services granted by the ORM are among other :
101
102  - consistency validation by powerful validity checks,
103  - providing an interface on objects (methods, references, ...) allowing
104    to design and implement efficient modules,
105  - row-level security per user and group; more details about users and user
106    groups are given in the section Users and User Roles,
107  - complex actions on a group of resources,
108  - inheritance service allowing fine modeling of new resources
109
110 **Server - Web**
111
112 The web layer offers an interface to communicate with standard browsers.
113 In the 6.1 version of OpenERP, the web-client has been rewritten and integrated
114 into the OpenERP server tier. This web layer is a WSGI-compatible application
115 based on werkzeug. It handles regular http queries to server static file or
116 dynamic content and JSON-RPC queries for the RPC made from the browser.
117
118 **Modules**
119
120 By itself, the OpenERP server is a core. For any enterprise, the value of
121 OpenERP lies in its different modules. The role of the modules is to implement
122 any business requirement. The server is the only necessary component to
123 add modules. Any official OpenERP release includes a lot of modules, and
124 hundreds of modules are available thanks to the community. Examples of
125 such modules are Account, CRM, HR, Marketing, MRP, Sale, etc.
126
127 Clients
128 +++++++
129
130 As the application logic is mainly contained server-side, the client is
131 conceptually simple. It issues a request to the server, gets data back
132 and display the result (e.g. a list of customers) in different ways
133 (as forms, lists, calendars, ...). Upon user actions, it sends queries
134 to modify data to the server.
135
136 The default client of OpenERP is an JavaScript application running in the
137 browser that communicates with the server using JSON-RPC.
138
139 MVC architecture in OpenERP
140 ===========================
141
142 According to `Wikipedia <http://en.wikipedia.org/wiki/Model-view-controller>`_,
143 "a Model-view-controller (MVC) is an architectural pattern used in software
144 engineering". In complex computer applications presenting lots of data to
145 the user, one often wishes to separate data (model) and user interface (view)
146 concerns. Changes to the user interface does therefore not impact data
147 management, and data can be reorganized without changing the user interface.
148 The model-view-controller solves this problem by decoupling data access
149 and business logic from data presentation and user interaction, by
150 introducing an intermediate component: the controller.
151
152 .. _`Figure 3`:
153 .. figure:: _static/02_mvc_diagram.png
154    :width: 35%
155    :alt: Model-View-Controller diagram
156    :align: center
157    
158    Model-View-Controller diagram
159
160 For example in the diagram above, the solid lines for the arrows starting
161 from the controller and going to both the view and the model mean that the
162 controller has a complete access to both the view and the model. The dashed
163 line for the arrow going from the view to the controller means that the view
164 has a limited access to the controller. The reasons of this design are :
165
166  - From **View** to **Model** : the model sends notification to the view
167    when its data has been modified in order the view to redraw its content.
168    The model doesn't need to know the inner workings of the view to perform
169    this operation. However, the view needs to access the internal parts of the model.
170  - From **View** to **Controller** : the reason why the view has limited
171    access to the controller is because the dependencies from the view to
172    the controller need to be minimal: the controller can be replaced at
173    any moment. 
174
175 OpenERP follows the MVC semantic with
176
177  - model : The PostgreSQL tables.
178  - view : views are defined in XML files in OpenERP.
179  - controller : The objects of OpenERP. 
180
181 Network communications and WSGI
182 ===============================
183 OpenERP is an HTTP web server and may also be deployed as an WSGI-compliant
184 application.
185
186 Clients may communicate with OpenERP using sessionless XML-RPC, the recommended
187 way to interoperate with OpenERP. Web-based clients communicates using the
188 session aware JSON-RPC.
189
190 Everything in OpenERP, and objects methods in particular, are exposed via
191 the network and a security layer. Access to the data model is in fact a ‘service’
192 and it is possible to expose new services. For instance, a WebDAV service and
193 a FTP service are available.
194
195 Services can make use of the `WSGI
196 <http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface>`_ stack. WSGI is a
197 standard solution in the Python ecosystem to write HTTP servers, applications,
198 and middleware which can be used in a mix-and-match fashion. By using WSGI, it
199 is possible to run OpenERP in any WSGI compliant server. It is also possible to
200 use OpenERP to host a WSGI application.
201
202 A striking example of this possibility is the OpenERP Web layer that is
203 the server-side counter part to the web clients. It provides the requested
204 data to the browser and manages web sessions. It is a WSGI-compliant application.
205 As such, it can be run as a stand-alone HTTP server or embedded inside OpenERP.
206
207 The HTTP namespaces /openerp/ /object/ /common/ are reserved for the XML-RPC
208 layer, every module restrict it's HTTP namespace to /<name_of_the_module>/
209