Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .codeboarding/Application Core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
```mermaid
graph LR
Application_Bootstrap["Application Bootstrap"]
Configuration_Manager["Configuration Manager"]
Logging_System["Logging System"]
Persistence_Layer_SQLAlchemy_["Persistence Layer (SQLAlchemy)"]
ASGI_Server["ASGI Server"]
Domain_Models["Domain Models"]
GraphQL_API["GraphQL API"]
Interactors_Business_Logic["Interactors/Business Logic"]
Middleware["Middleware"]
Application_Bootstrap -- "reads configuration from" --> Configuration_Manager
Application_Bootstrap -- "initializes" --> Logging_System
Application_Bootstrap -- "configures session maker for" --> Persistence_Layer_SQLAlchemy_
Application_Bootstrap -- "creates and starts" --> ASGI_Server
Persistence_Layer_SQLAlchemy_ -- "persists and retrieves" --> Domain_Models
ASGI_Server -- "hosts" --> GraphQL_API
ASGI_Server -- "integrates" --> Middleware
GraphQL_API -- "invokes" --> Interactors_Business_Logic
GraphQL_API -- "exposes" --> Domain_Models
Interactors_Business_Logic -- "operates on" --> Domain_Models
Interactors_Business_Logic -- "accesses data via" --> Persistence_Layer_SQLAlchemy_
Middleware -- "intercepts requests for" --> GraphQL_API
Middleware -- "injects dependencies into" --> Interactors_Business_Logic
```
[![CodeBoarding](https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square)](https://github.com/CodeBoarding/GeneratedOnBoardings)[![Demo](https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square)](https://www.codeboarding.org/demo)[![Contact](https://img.shields.io/badge/Contact%20us%20-%[email protected]?style=flat-square)](mailto:[email protected])

## Component Details

The graph describes the architecture of the MedConB application, detailing its core components and their interactions. The main flow starts with the Application Bootstrap component, which initializes the application by setting up logging, configuring the database persistence layer, and creating the ASGI Server. The ASGI Server then hosts the GraphQL API, which serves as the primary interface for client interactions. Requests to the GraphQL API are processed by Middleware components and then routed to Interactors/Business Logic for executing specific application use cases. These interactors operate on Domain Models and interact with the Persistence Layer (SQLAlchemy) to store and retrieve data. The Configuration Manager provides essential settings across the application. The purpose of this architecture is to provide a structured, maintainable, and scalable backend for the MedConB application, separating concerns into distinct components for clarity and efficient development.

### Application Bootstrap
This component is responsible for the initial setup and orchestration of the MedConB application. It initializes logging, configures the database session maker, creates the caching client, and ultimately creates the ASGI application server. It acts as the entry point for the application.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/app.py#L20-L23" target="_blank" rel="noopener noreferrer">`medconb.app:create_app` (20:23)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/app.py#L26-L39" target="_blank" rel="noopener noreferrer">`medconb.app:_create_sessionmaker` (26:39)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/app.py#L42-L59" target="_blank" rel="noopener noreferrer">`medconb.app:_create_sqlalchemy_sessionmaker` (42:59)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/app.py#L62-L65" target="_blank" rel="noopener noreferrer">`medconb.app:_create_cache_client` (62:65)</a>


### Configuration Manager
This component handles the loading and access of application-wide configuration settings, such as database URLs and caching parameters.


**Related Classes/Methods**:

- `medconb.config.config` (full file reference)


### Logging System
This component provides logging capabilities for the application, allowing different parts of the system to record events and debug information.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/log.py#L23-L42" target="_blank" rel="noopener noreferrer">`medconb.log:setup_logging` (23:42)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/log.py#L48-L86" target="_blank" rel="noopener noreferrer">`medconb.log:time_me` (48:86)</a>


### Persistence Layer (SQLAlchemy)
This component is responsible for managing the interaction with the relational database using SQLAlchemy, including session management, repositories, ORM mappings, and caching mechanisms. It also integrates with Redis for caching.


**Related Classes/Methods**:

- `medconb.persistence.sqlalchemy.create_sessionmaker` (full file reference)
- `medconb.persistence.sqlalchemy.session` (full file reference)
- `medconb.persistence.sqlalchemy.repositories` (full file reference)
- `medconb.persistence.sqlalchemy.orm` (full file reference)
- `medconb.persistence.sqlalchemy.cache` (full file reference)
- `redis.StrictRedis` (full file reference)


### ASGI Server
This component is responsible for creating and running the ASGI (Asynchronous Server Gateway Interface) application, which serves as the entry point for web requests.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/server.py#L119-L162" target="_blank" rel="noopener noreferrer">`medconb.server.create_app` (119:162)</a>


### Domain Models
This component encapsulates the core business logic and data structures of the MedConB application. It defines entities like Codelist, Collection, Container, Ontology, Phenotype, and User.


**Related Classes/Methods**:

- `medconb.domain` (full file reference)
- `medconb.domain.base` (full file reference)
- `medconb.domain.codelist` (full file reference)
- `medconb.domain.collection` (full file reference)
- `medconb.domain.container` (full file reference)
- `medconb.domain.ontology` (full file reference)
- `medconb.domain.phenotype` (full file reference)
- `medconb.domain.user` (full file reference)
- `medconb.domain.importer` (full file reference)


### GraphQL API
This component provides the GraphQL interface for the application, defining queries, mutations, and object types to expose the domain models and interactors to clients.


**Related Classes/Methods**:

- `medconb.graphql.helper` (full file reference)
- `medconb.graphql.main` (full file reference)
- `medconb.graphql.mutation` (full file reference)
- `medconb.graphql.objects` (full file reference)
- `medconb.graphql.query` (full file reference)
- `medconb.graphql.types` (full file reference)


### Interactors/Business Logic
This component contains the application's use cases and business rules. It orchestrates interactions between the domain models and the persistence layer to fulfill specific application functionalities.


**Related Classes/Methods**:

- `medconb.interactors` (full file reference)
- `medconb.interactors.base` (full file reference)
- `medconb.interactors.codelist` (full file reference)
- `medconb.interactors.phenotype` (full file reference)
- `medconb.interactors.property` (full file reference)
- `medconb.interactors.query` (full file reference)
- `medconb.interactors.user` (full file reference)
- `medconb.interactors.workspace` (full file reference)


### Middleware
This component provides middleware functionalities for the ASGI application, potentially handling authentication, authorization, or request/response processing before reaching the core application logic.


**Related Classes/Methods**:

- `medconb.middleware` (full file reference)




### [FAQ](https://github.com/CodeBoarding/GeneratedOnBoardings/tree/main?tab=readme-ov-file#faq)
102 changes: 102 additions & 0 deletions .codeboarding/Authentication & Middleware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
```mermaid
graph LR
Authentication_Backend["Authentication Backend"]
Azure_AD_Authenticator["Azure AD Authenticator"]
Development_Authenticator["Development Authenticator"]
User_Workspace_Domain["User & Workspace Domain"]
Collection_Management_Interactors["Collection Management Interactors"]
Codelist_Management_Interactors["Codelist Management Interactors"]
GraphQL_Request_DTOs["GraphQL Request DTOs"]
Authentication_Backend -- "configures and delegates authentication to" --> Azure_AD_Authenticator
Authentication_Backend -- "configures and delegates authentication to" --> Development_Authenticator
Azure_AD_Authenticator -- "creates and loads user/workspace data" --> User_Workspace_Domain
Azure_AD_Authenticator -- "invokes to create default collections" --> Collection_Management_Interactors
Azure_AD_Authenticator -- "invokes to import default codelists" --> Codelist_Management_Interactors
Azure_AD_Authenticator -- "constructs requests using" --> GraphQL_Request_DTOs
Development_Authenticator -- "retrieves user information from" --> User_Workspace_Domain
Server -- "integrates as an authentication middleware" --> Authentication_Backend
```
[![CodeBoarding](https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square)](https://github.com/CodeBoarding/GeneratedOnBoardings)[![Demo](https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square)](https://www.codeboarding.org/demo)[![Contact](https://img.shields.io/badge/Contact%20us%20-%[email protected]?style=flat-square)](mailto:[email protected])

## Component Details

This graph illustrates the `Authentication & Middleware` subsystem, which is responsible for handling user authentication, supporting both Azure AD and development authenticators. It extracts claims, manages user loading and creation, and ensures secure access to the application by integrating various components for user management, collection, and codelist operations.

### Authentication Backend
This component is responsible for managing different authentication methods (Azure AD and Development). It acts as a central point for authenticating incoming requests by iterating through configured authenticators.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L66-L115" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AuthBackend` (66:115)</a>


### Azure AD Authenticator
Handles authentication specifically for Azure Active Directory. It decodes and validates JWT tokens, extracts claims, and loads or creates user profiles based on these claims. It also initializes new users with default collections and codelists.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L175-L187" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AzureADAuthenticator:__init__` (175:187)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L207-L223" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AzureADAuthenticator:_configure_ad` (207:223)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L243-L261" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AzureADAuthenticator:authenticate` (243:261)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L263-L289" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AzureADAuthenticator:_extract_claims` (263:289)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L291-L332" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AzureADAuthenticator:_load_user` (291:332)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L334-L354" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AzureADAuthenticator:_create_new_user` (334:354)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L356-L530" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.AzureADAuthenticator:_init_new_user` (356:530)</a>


### Development Authenticator
Provides a simplified authentication mechanism for development environments. It authenticates users based on a pre-configured token and user ID.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L119-L123" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.DevAuthenticator:__init__` (119:123)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/middleware.py#L125-L132" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.middleware.DevAuthenticator:_configure_develop` (125:132)</a>


### User & Workspace Domain
Defines the core domain models for users and their workspaces, including UserID, User, and Workspace. These models represent the fundamental entities within the system.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/domain/base.py#L11-L11" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.domain.base.UserID` (11:11)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/domain/user.py#L15-L57" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.domain.user.User` (15:57)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/domain/user.py#L69-L107" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.domain.user.Workspace` (69:107)</a>


### Collection Management Interactors
Contains interactors responsible for managing collections, such as creating new collections.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/interactors/workspace.py#L44-L70" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.interactors.workspace.CreateCollection` (44:70)</a>


### Codelist Management Interactors
Contains interactors responsible for managing codelists, such as importing codelists.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/interactors/codelist.py#L214-L359" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.interactors.codelist.ImportCodelists` (214:359)</a>


### GraphQL Request DTOs
Defines data transfer objects (DTOs) used for GraphQL requests related to creating collections and importing codelists.


**Related Classes/Methods**:

- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/graphql/types.py#L148-L153" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.graphql.types.CreateCollectionRequestDto` (148:153)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/graphql/types.py#L277-L280" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.graphql.types.ImportCodelistsRequestDto` (277:280)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/graphql/types.py#L272-L274" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.graphql.types.CodelistInput` (272:274)</a>
- <a href="https://github.com/Bayer-Group/medconb/blob/master/backend/medconb/graphql/types.py#L267-L269" target="_blank" rel="noopener noreferrer">`medconb.backend.medconb.graphql.types.CodesetInput` (267:269)</a>




### [FAQ](https://github.com/CodeBoarding/GeneratedOnBoardings/tree/main?tab=readme-ov-file#faq)
Loading