# simptom569/vento architecture

> Architecture diagram of the GitHub repository simptom569/vento, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/simptom569/vento
- Repository: https://github.com/simptom569/vento

## Overview

#### Purpose and Entrypoints
Vento is an async FastAPI backend for a secure messenger: authentication, private/group/secret/channel chats, encrypted messaging, channel posts, and calls. The production ASGI entrypoint is `app/main.py`; it builds the FastAPI app and installs Dishka DI. HTTP v1 boundaries are implemented in `app/presentation/api/v1/routers/auth.py`, `app/presentation/api/v1/routers/chats.py`, and `app/presentation/api/v1/routers/messages.py`.

#### Layered Composition
The repository follows Clean Architecture: presentation invokes application handlers; handlers depend on domain entities and abstract ports; infrastructure implements those ports. DI wiring is centralized in `app/container.py`, while framework-independent settings, request dependencies, and security are in `app/core/config.py`, `app/core/dependencies.py`, and `app/core/security.py`. This is the main boundary preventing FastAPI/SQLAlchemy concerns from entering business logic.

#### Domain Model and Policy
Core domain concepts are users/sessions, chats and memberships, messages, feed posts, and calls, represented separately from persistence in `app/domain/entities/user.py`, `app/domain/entities/chat.py`, and `app/domain/entities/message.py`. Repository contracts establish persistence boundaries in `app/domain/ports/repositories/chat_repo.py`, `app/domain/ports/repositories/message_repo.py`, and `app/domain/ports/repositories/credentials_repo.py`. A channel is a chat; a feed post is a message specialization, avoiding separate content pipelines.

#### Command and Query Flows
Mutations are single-purpose command handlers: auth lifecycle in `app/application/commands/auth/login.py` and `app/application/commands/auth/refresh_token.py`; membership/chat changes in `app/application/commands/chats/create_channel.py`; and message lifecycle in `app/application/commands/messages/send_message.py`. Read models are handled separately by query handlers such as `app/application/queries/chats/get_user_chats.py`, `app/application/queries/messages/get_chat_messages.py`, and `app/application/queries/messages/get_channel_feed.py`. Typical flow is request schema → router → injected handler → domain-port calls → response schema.

#### Persistence and Transaction Boundary
PostgreSQL 16 is accessed through async SQLAlchemy. ORM schema and domain mapping live in `app/infrastructure/db/models/user.py`, `app/infrastructure/db/models/chat.py`, and `app/infrastructure/db/models/message.py`; concrete repository adapters are in `app/infrastructure/db/repositories/`. The request-scoped async session is created from `app/infrastructure/db/session.py`, giving application handlers a unit-of-work-like database boundary. Alembic migration integration begins at `alembic/env.py`.

#### Security and Encrypted Content
Authentication uses RS256 JWT access tokens plus rotating, hashed refresh tokens; the implementation boundary is `app/core/security.py` with session/credential persistence through `app/domain/ports/repositories/credentials_repo.py`. Message content is designed as client-side E2E ciphertext: ordinary chats support per-device recipient payloads, while secret chats use a message-level encrypted blob. Server-side message operations and storage metadata are centered in `app/domain/entities/message.py` and `app/infrastructure/db/models/message.py`; plaintext encryption/decryption is not a backend responsibility.

#### External Runtime and Planned Integrations
The current concrete runtime is Python 3.14+, FastAPI/Uvicorn, Dishka, PostgreSQL/asyncpg, and Docker Compose (`Dockerfile`, `docker-compose.yml`). Redis, Kafka, push, object storage, and WebSocket integration directories exist but are placeholders: `app/infrastructure/redis`, `app/infrastructure/kafka`, `app/infrastructure/storage`, and `app/presentation/websocket`. The intended external services are Redis pub/sub/cache, Kafka events, MinIO S3-compatible attachments, FCM push, and LiveKit for calls; call application handlers currently start at `app/application/commands/calls/initiate_call.py`.

Main entry points: [`app/presentation/api/v1/routers/auth.py`](https://github.com/simptom569/vento/blob/main/app/presentation/api/v1/routers/auth.py) (v1 routers), [`app/container.py`](https://github.com/simptom569/vento/blob/main/app/container.py) (DI container), [`app/domain/ports/repositories/message_repo.py`](https://github.com/simptom569/vento/blob/main/app/domain/ports/repositories/message_repo.py) (Repository ports), [`app/application/commands/auth/login.py`](https://github.com/simptom569/vento/blob/main/app/application/commands/auth/login.py) (Auth commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_main{{"ASGI app<br/>FastAPI entrypoint<br/>[main.py]"}}
  node_routers["v1 routers<br/>HTTP boundary<br/>[auth.py]"]
end

subgraph group_application["Application"]
  node_container["DI container<br/>Dishka wiring<br/>[container.py]"]
  node_security["JWT security<br/>auth service<br/>[security.py]"]
  node_auth_commands["Auth commands<br/>command handlers<br/>[login.py]"]
  node_chat_commands["Chat commands<br/>command handlers<br/>[create_channel.py]"]
  node_message_commands["Message commands<br/>command handlers<br/>[send_message.py]"]
  node_chat_queries["Chat queries<br/>query handlers<br/>[get_user_chats.py]"]
  node_message_queries["Message/feed queries<br/>query handlers"]
  node_call_commands["Call commands<br/>command handlers<br/>[initiate_call.py]"]
end

subgraph group_domain["Domain"]
  node_entities["Messaging domain<br/>entities<br/>[message.py]"]
  node_repo_ports["Repository ports<br/>persistence contracts<br/>[message_repo.py]"]
  node_credentials_port["Credentials port<br/>auth persistence contract"]
end

subgraph group_infrastructure["Infrastructure"]
  node_session["Async DB session<br/>request-scoped unit of work<br/>[session.py]"]
  node_repositories["Repository adapters<br/>SQLAlchemy adapters<br/>[message_repo.py]"]
  node_orm_models["ORM and mapping<br/>persistence models<br/>[message.py]"]
  node_postgres[("PostgreSQL 16<br/>database")]
  node_migrations["Alembic migrations<br/>schema migration<br/>[env.py]"]
  node_planned_realtime["Planned integrations<br/>placeholder adapters"]
end

node_main -->|"mounts"| node_routers
node_main -->|"installs"| node_container
node_container -->|"injects"| node_auth_commands
node_container -->|"injects"| node_chat_commands
node_container -->|"injects"| node_message_commands
node_container -->|"injects"| node_chat_queries
node_container -->|"injects"| node_message_queries
node_routers -->|"commands"| node_auth_commands
node_routers -->|"commands"| node_chat_commands
node_routers -->|"commands"| node_message_commands
node_routers -->|"reads"| node_chat_queries
node_routers -->|"reads"| node_message_queries
node_auth_commands -->|"issues tokens"| node_security
node_security -->|"uses"| node_credentials_port
node_auth_commands -->|"persists sessions"| node_credentials_port
node_chat_commands -->|"applies policy"| node_entities
node_message_commands -->|"stores ciphertext metadata"| node_entities
node_message_queries -->|"queries"| node_repo_ports
node_chat_queries -->|"queries"| node_repo_ports
node_chat_commands -->|"persists"| node_repo_ports
node_message_commands -->|"persists"| node_repo_ports
node_repo_ports -->|"implemented by"| node_repositories
node_credentials_port -->|"implemented by"| node_repositories
node_repositories -->|"uses"| node_session
node_session -->|"loads/maps"| node_orm_models
node_orm_models -->|"persists"| node_postgres
node_migrations -->|"evolves schema"| node_postgres
node_call_commands -.->|"intended integration"| node_planned_realtime

click node_main "https://github.com/simptom569/vento/blob/main/app/main.py"
click node_routers "https://github.com/simptom569/vento/blob/main/app/presentation/api/v1/routers/auth.py"
click node_container "https://github.com/simptom569/vento/blob/main/app/container.py"
click node_security "https://github.com/simptom569/vento/blob/main/app/core/security.py"
click node_auth_commands "https://github.com/simptom569/vento/blob/main/app/application/commands/auth/login.py"
click node_chat_commands "https://github.com/simptom569/vento/blob/main/app/application/commands/chats/create_channel.py"
click node_message_commands "https://github.com/simptom569/vento/blob/main/app/application/commands/messages/send_message.py"
click node_chat_queries "https://github.com/simptom569/vento/blob/main/app/application/queries/chats/get_user_chats.py"
click node_message_queries "https://github.com/simptom569/vento/blob/main/app/application/queries/messages/get_chat_messages.py"
click node_call_commands "https://github.com/simptom569/vento/blob/main/app/application/commands/calls/initiate_call.py"
click node_entities "https://github.com/simptom569/vento/blob/main/app/domain/entities/message.py"
click node_repo_ports "https://github.com/simptom569/vento/blob/main/app/domain/ports/repositories/message_repo.py"
click node_credentials_port "https://github.com/simptom569/vento/blob/main/app/domain/ports/repositories/credentials_repo.py"
click node_session "https://github.com/simptom569/vento/blob/main/app/infrastructure/db/session.py"
click node_repositories "https://github.com/simptom569/vento/blob/main/app/infrastructure/db/repositories/message_repo.py"
click node_orm_models "https://github.com/simptom569/vento/blob/main/app/infrastructure/db/models/message.py"
click node_migrations "https://github.com/simptom569/vento/blob/main/alembic/env.py"
click node_planned_realtime "https://github.com/simptom569/vento/tree/main/app/infrastructure/redis"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_routers toneBlue
class node_container,node_security,node_auth_commands,node_chat_commands,node_message_commands,node_chat_queries,node_message_queries,node_call_commands toneAmber
class node_entities,node_repo_ports,node_credentials_port toneMint
class node_session,node_repositories,node_orm_models,node_postgres,node_migrations,node_planned_realtime toneRose
```

## Components

### HTTP API

- [ASGI app](https://github.com/simptom569/vento/blob/main/app/main.py): FastAPI entrypoint · `app/main.py`
- [v1 routers](https://github.com/simptom569/vento/blob/main/app/presentation/api/v1/routers/auth.py): HTTP boundary · Auth, chat, and message endpoints. · `app/presentation/api/v1/routers/auth.py`

### Application

- [DI container](https://github.com/simptom569/vento/blob/main/app/container.py): Dishka wiring · `app/container.py`
- [JWT security](https://github.com/simptom569/vento/blob/main/app/core/security.py): auth service · RS256 access tokens and rotating hashed refresh tokens. · `app/core/security.py`
- [Auth commands](https://github.com/simptom569/vento/blob/main/app/application/commands/auth/login.py): command handlers · `app/application/commands/auth/login.py`
- [Chat commands](https://github.com/simptom569/vento/blob/main/app/application/commands/chats/create_channel.py): command handlers · `app/application/commands/chats/create_channel.py`
- [Message commands](https://github.com/simptom569/vento/blob/main/app/application/commands/messages/send_message.py): command handlers · `app/application/commands/messages/send_message.py`
- [Chat queries](https://github.com/simptom569/vento/blob/main/app/application/queries/chats/get_user_chats.py): query handlers · `app/application/queries/chats/get_user_chats.py`
- [Message/feed queries](https://github.com/simptom569/vento/blob/main/app/application/queries/messages/get_chat_messages.py): query handlers · Includes chat history and channel feed reads. · `app/application/queries/messages/get_chat_messages.py`
- [Call commands](https://github.com/simptom569/vento/blob/main/app/application/commands/calls/initiate_call.py): command handlers · Call initiation integration is planned. · `app/application/commands/calls/initiate_call.py`

### Domain

- [Messaging domain](https://github.com/simptom569/vento/blob/main/app/domain/entities/message.py): entities · Users, chats/memberships, messages, and feed posts. · `app/domain/entities/message.py`
- [Repository ports](https://github.com/simptom569/vento/blob/main/app/domain/ports/repositories/message_repo.py): persistence contracts · Chat, message, and credential boundaries. · `app/domain/ports/repositories/message_repo.py`
- [Credentials port](https://github.com/simptom569/vento/blob/main/app/domain/ports/repositories/credentials_repo.py): auth persistence contract · `app/domain/ports/repositories/credentials_repo.py`

### Infrastructure

- [Async DB session](https://github.com/simptom569/vento/blob/main/app/infrastructure/db/session.py): request-scoped unit of work · `app/infrastructure/db/session.py`
- [Repository adapters](https://github.com/simptom569/vento/blob/main/app/infrastructure/db/repositories/message_repo.py): SQLAlchemy adapters · `app/infrastructure/db/repositories/message_repo.py`
- [ORM and mapping](https://github.com/simptom569/vento/blob/main/app/infrastructure/db/models/message.py): persistence models · Maps domain messaging data to relational schema. · `app/infrastructure/db/models/message.py`
- **PostgreSQL 16**: database
- [Alembic migrations](https://github.com/simptom569/vento/blob/main/alembic/env.py): schema migration · `alembic/env.py`
- [Planned integrations](https://github.com/simptom569/vento/tree/main/app/infrastructure/redis): placeholder adapters · Redis, Kafka, storage, WebSocket, push, and LiveKit are not yet concrete. · `app/infrastructure/redis`

## Connections

- ASGI app → v1 routers: mounts
- ASGI app → DI container: installs
- DI container → Auth commands: injects
- DI container → Chat commands: injects
- DI container → Message commands: injects
- DI container → Chat queries: injects
- DI container → Message/feed queries: injects
- v1 routers → Auth commands: commands
- v1 routers → Chat commands: commands
- v1 routers → Message commands: commands
- v1 routers → Chat queries: reads
- v1 routers → Message/feed queries: reads
- Auth commands → JWT security: issues tokens
- JWT security → Credentials port: uses
- Auth commands → Credentials port: persists sessions
- Chat commands → Messaging domain: applies policy
- Message commands → Messaging domain: stores ciphertext metadata
- Message/feed queries → Repository ports: queries
- Chat queries → Repository ports: queries
- Chat commands → Repository ports: persists
- Message commands → Repository ports: persists
- Repository ports → Repository adapters: implemented by
- Credentials port → Repository adapters: implemented by
- Repository adapters → Async DB session: uses
- Async DB session → ORM and mapping: loads/maps
- ORM and mapping → PostgreSQL 16: persists
- Alembic migrations → PostgreSQL 16: evolves schema
- Call commands → Planned integrations: intended integration
