Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence diagram for user creation #32

Merged
merged 4 commits into from
Jul 11, 2024
Merged
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
82 changes: 41 additions & 41 deletions diagrams/sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,69 @@

These diagrams show the flow of the processes into the architecture and how the flows will work.

## Account creation flow

An account will be persisted into the queue when the user call a creation. The RPC driver (management API) will persist a cache to manipulate and make query easly. And the daemon will create the resource in each cluster.
## User creation flow

### RPC Driver

The RPC will call the domain to create the account where the domain will validate the information and integrate with the demeter legacy. When the account is created an event will be sent to the queue to handle the account creation.
The user will first authenticate in Auth0 and get an Access token. Then, the user will request the fabric to create the user or return the existing user.

```mermaid
sequenceDiagram
actor User

User->>+RPC_Driver: Create a new account
RPC_Driver->>+Management_Domain: Call create account

Management_Domain->>+Demeter_Driven: Create an account in the old database(pg)
Note left of Demeter_Driven: This flow replaces the logic <br/> of the old demeter API
Demeter_Driven-->>-Management_Domain: All old business logic and integrations executed

Management_Domain->>Event_Driven: Submit an event to handle account
User->>+Auth0: Login/Signup in oauth
Auth0->>-User: Access Token

Management_Domain-->>-RPC_Driver: Account created
RPC_Driver-->>-User: Account created
```

### Event Driver
User->>+RPC: Send command to create user
RPC->>+Management_Domain: Create user

The event driver will be running togheter to the RPC driver watching the queue where it will handle account created.
Management_Domain->>+OAuth_Driven: Verify access token
alt Invalid token
OAuth_Driven->>Management_Domain: Invalid access token
Management_Domain->>RPC: Invalid access token
RPC->>User: Invalid access token
end
OAuth_Driven->>-Management_Domain: Return user id

```mermaid
sequenceDiagram
actor Queue
Management_Domain->>+Cache_Driven: Get user
alt User already exists
Cache_Driven->>Management_Domain: Return user
Management_Domain->>RPC: User already exists
RPC->>User: Return the user
end
Cache_Driven->>-Management_Domain: User doesn't exist

Queue->>+Event_Driver: Handle a new account
Event_Driver->>+Management_Domain: Handle account function
Management_Domain->>+OAuth_Driven: Get user profile
OAuth_Driven->>-Management_Domain: Return user profile

Management_Domain->>+Cache_Driven: Update cache
Cache_Driven->>-Management_Domain: Cache updated
Management_Domain->>+Event_Driven: Send event user created
Event_Driven->>-Management_Domain: Return confirmation

Management_Domain->>-Event_Driver: Account handled
Event_Driver->>-Queue: Ack event
Management_Domain->>-RPC: User created
RPC->>-User: Return the user
```

### Daemon Driver
### Event Driver

The Daemon Driver will be running in each cluster and watching the queue as well, but it will create the resource into the cluster.
If all is ok, an event of the user created will be sent to a queue to persist that user. The event drive will be listening for events and will persist the user in the cache.

```mermaid
sequenceDiagram
actor Queue
Queue->>+Event_Driver: New event: User Created

Queue->>+Fabric_Driver: Push event
Fabric_Driver->>+Daemon_Domain: Call create namespace function
Event_Driver->>+Management_Domain: Insert new user in the cache

Daemon_Domain->>+Cluster_Driven: Create resource into the cluster
Note over Cluster_Driven: This function will integrate with <br/> the cluster and create the resource there
Cluster_Driven-->>-Daemon_Domain: Confirmation resource created
Management_Domain->>+Cache_Driven: Get user
alt User already exists
Cache_Driven->>Management_Domain: Return User
Management_Domain->>Event_Driver: User already exists
Event_Driver->>Queue: Ack event
end

Daemon_Domain->>+Event_Driven: Dispatch the event to update the state
Note over Event_Driven: Each cluster will dispatch the event and <br/> the state will be updated with each cluster <br/> that created the namespace
Event_Driven-->>-Daemon_Domain: Event sent confirmation
Cache_Driven->>-Management_Domain: User doesn't exist
Management_Domain->>+Cache_Driven: Insert new user
Cache_Driven->>-Management_Domain: Return Ok

Daemon_Domain-->>-Fabric_Driver: Namespace created
Fabric_Driver-->>-Queue: Ack the event
Management_Domain->>-Event_Driver: User inserted
Event_Driver->>-Queue: Ack event
```

Loading