# michaelmulley/openparliament architecture

> Architecture diagram of the GitHub repository michaelmulley/openparliament, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/michaelmulley/openparliament
- Repository: https://github.com/michaelmulley/openparliament

## Overview

This project is a Django-based web application designed to scrape and republish information about Canada’s House of Commons. Given both the comprehensive file tree and the README, we can deduce that it is a full-stack website featuring several interconnected Django apps (such as accounts, bills, committees, and search) and integrations (e.g., with a PostgreSQL database, Docker for deployment, and Solr for search indexing).

##### Main Components
- Web Client: Represents the end users accessing the site via browsers. Their interaction is primarily with the front-end assets (HTML, CSS, JavaScript) served from the templates and static directories.
- Django Application Server: The core of the project (initiated by manage.py and the wsgi.py file) hosting the multiple Django apps (accounts, bills, committees, elections, hansards, etc.). Each app encapsulates a distinct aspect of the site’s functionality.
- API Endpoints: Separate modules (e.g., the 'api' directory) offer programmatic access for browsing or consuming parliamentary data.
- Search Engine: The existence of Solr configuration examples in the config-examples/solr directory and dedicated Django search modules indicate an integration with a Solr search service.
- Background Jobs & Importers: The “imports” and “jobs” modules represent processes that scrape, process, and import data into the system. Include a component for “Data Import & Processing” that feeds into the main database and search index.
- Docker & Deployment: Given the Dockerfile and provided docker-compose.yml example, include a containerization component that packages the Django application, database, and potentially the search engine within Docker containers.

##### Relationships and Interactions
- The Web Client sends HTTP requests to the Gunicorn server, which runs the Django application.
- The Django server routes incoming requests based on URL configurations to various Django apps (accounts, bills, committees, etc.).
- The Django apps interact with the PostgreSQL database for CRUD operations on parliamentary data.
- The search functionality involves communication between the Django search module and the external Solr search service.
- Background processes (importers/scrapers) periodically update the database and search index.
- There might be API endpoints that allow external systems to query or retrieve data, interacting with the same backend.
- Docker orchestrates the environment by bundling the Django app, PostgreSQL instance, and Solr (if containerized) into a single ecosystem.

##### Architectural Patterns and Design Principles
- Modular Design: Each domain (e.g., accounts, bills, committees, etc.) has its own Django app, promoting separation of concerns and easier maintenance.
- MVC/MVT Pattern: Django’s Model-View-Template architecture is evident. Models, views, and templates are organized to maintain clear separation between the data layer, the business logic, and the user interface.
- API Layer: For integration and data exposure, the API endpoints are separate from the main web views, showcasing a RESTful interaction pattern.
- Containerization & Deployment: Leveraging Docker supports consistency across development and deployment environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Web Client (Browser)"]:::frontend
    B["Gunicorn WSGI Server"]:::deployment
    C["Django Application Server"]:::backend
    D["API Endpoints"]:::backend
    E(["PostgreSQL Database"]):::database
    F(["Solr Search Server"]):::external
    G["Data Import & Processing"]:::backend
    H["Docker & Deployment"]:::deployment

    A -->|"HTTP"| B
    B -->|"WSGICall"| C
    C -->|"ProvidesAPI"| D
    C -->|"ORMQueries"| E
    C -->|"SearchIndexing"| F
    G -->|"ImportsData"| E
    G -->|"UpdatesIndex"| F
    H -->|"Containerizes"| B
    H -->|"Containerizes"| C
    H -->|"Containerizes"| E
    H -->|"Containerizes"| F

    click A "https://github.com/michaelmulley/openparliament/tree/master/parliament/templates"
    click A "https://github.com/michaelmulley/openparliament/tree/master/parliament/static"
    click C "https://github.com/michaelmulley/openparliament/blob/master/manage.py"
    click C "https://github.com/michaelmulley/openparliament/blob/master/parliament/wsgi.py"
    click D "https://github.com/michaelmulley/openparliament/blob/master/parliament/api/urls.py"
    click D "https://github.com/michaelmulley/openparliament/blob/master/parliament/api/views.py"
    click F "https://github.com/michaelmulley/openparliament/tree/master/config-examples/solr"
    click F "https://github.com/michaelmulley/openparliament/blob/master/parliament/search/solr.py"
    click G "https://github.com/michaelmulley/openparliament/tree/master/parliament/imports"
    click G "https://github.com/michaelmulley/openparliament/blob/master/parliament/jobs.py"
    click H "https://github.com/michaelmulley/openparliament/tree/master/Dockerfile"
    click H "https://github.com/michaelmulley/openparliament/blob/master/config-examples/docker-compose.yml-example"
    click B "https://github.com/michaelmulley/openparliament/blob/master/gunicorn.conf.py"
    click B "https://github.com/michaelmulley/openparliament/blob/master/start-gunicorn.sh"

    classDef frontend fill:#AEDFF7,stroke:#1A7BB9,stroke-width:2px
    classDef backend fill:#C9F7C9,stroke:#379237,stroke-width:2px
    classDef database fill:#F7D6AD,stroke:#D2691E,stroke-width:2px
    classDef external fill:#FFD3B6,stroke:#FF8C42,stroke-width:2px
    classDef deployment fill:#D3B6FF,stroke:#8C42FF,stroke-width:2px
```
