# lukaszfabia/chatterbox architecture

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

- Interactive diagram: https://gitdiagram.com/lukaszfabia/chatterbox
- Repository: https://github.com/lukaszfabia/chatterbox

## Overview

##### Project type and purpose
- This is a microservices‐based full-stack chat application (“Chatterbox”) that implements a simplified CQRS pattern and event-driven architecture.
- It consists of five back-end services (Auth, Profile, Notification, Chat, Status), a Next.js front-end, an Nginx reverse proxy, and uses Docker/Docker-Compose for local orchestration and Terraform/AWS for deployment.

##### File structure
- Top-level directories:
- auth_service (Python + FastAPI + PostgreSQL + Alembic)
- profile_service (Go + PostgreSQL)
- notification_service (Go + PostgreSQL + SMTP)
- chat_service (Node.js/TypeScript + Express + MongoDB + WebSocket)
- status_service (Node.js/TypeScript + Express + Redis + WebSocket)
- frontend (Next.js + React + REST + WebSocket)
- nginx (reverse proxy)
- aws (Terraform modules)
- docker-compose.yml (local orchestration)
- Each service follows a clear layering: domain, application (commands/events/queries), infrastructure (DB, messaging, REST, WS), and a top-level entrypoint (`main.go` or `app.ts` / `main.py`).

##### README for additional insights
- Services communicate via RabbitMQ as the event bus.
- Real-time interactions use WebSockets.
- Databases: PostgreSQL for Auth/Profile/Notification, MongoDB for Chat, Redis for Status.
- External integrations: SMTP (email), Google SSO, Google Cloud (optional), AWS ECR/Terraform for container registry & infra.

##### Be detailed but focused
- Microservice, its datastore, and its interactions on the bus.
- Nginx as the single entry point for HTTP traffic.
- This level of granularity ensures stakeholders see both high-level flow and critical architectural elements.

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px
    classDef service fill:#9f9,stroke:#333,stroke-width:1px
    classDef db fill:#ff9,stroke:#333,stroke-width:1px
    classDef broker fill:#9ff,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px
    classDef infra fill:#fcf,stroke:#333,stroke-width:1px

    User["User"]:::external
    Frontend["Next.js Frontend"]:::frontend
    Nginx["Nginx Reverse Proxy"]:::infra
    RabbitMQ["RabbitMQ Broker"]:::broker

    subgraph "Auth Service" 
        AuthService["Auth Service"]:::service
    end
    subgraph "Profile Service"
        ProfileService["Profile Service"]:::service
    end
    subgraph "Chat Service"
        ChatService["Chat Service"]:::service
    end
    subgraph "Status Service"
        StatusService["Status Service"]:::service
    end
    subgraph "Notification Service"
        NotificationService["Notification Service"]:::service
    end

    Postgres["PostgreSQL"]:::db
    MongoDB["MongoDB"]:::db
    Redis["Redis"]:::db
    SMTP["SMTP Server"]:::external
    GoogleOAuth["Google OAuth"]:::external
    AWS_ECR["AWS ECR"]:::infra
    Terraform["Terraform (AWS Infra)"]:::infra

    User -->|"HTTPS / WebSocket"| Frontend
    Frontend -->|"REST"| Nginx

    Nginx -->|"REST"| AuthService
    Nginx -->|"REST"| ProfileService
    Nginx -->|"REST"| ChatService
    Nginx -->|"REST"| StatusService
    Nginx -->|"REST"| NotificationService

    AuthService -->|"SQL"| Postgres
    ProfileService -->|"SQL"| Postgres
    NotificationService -->|"SQL"| Postgres
    ChatService -->|"NoSQL"| MongoDB
    StatusService -->|"KV Store"| Redis

    AuthService -.->|"publishes"| RabbitMQ
    ProfileService -.->|"publishes"| RabbitMQ
    ChatService -.->|"publishes"| RabbitMQ
    StatusService -.->|"publishes"| RabbitMQ
    NotificationService -.->|"publishes"| RabbitMQ

    RabbitMQ -.->|"subscribes"| AuthService
    RabbitMQ -.->|"subscribes"| ProfileService
    RabbitMQ -.->|"subscribes"| ChatService
    RabbitMQ -.->|"subscribes"| StatusService
    RabbitMQ -.->|"subscribes"| NotificationService

    ChatService -->|"WebSocket Push"| Frontend
    StatusService -->|"WebSocket Push"| Frontend

    NotificationService -->|"SMTP Send"| SMTP
    Frontend -->|"OAuth2"| GoogleOAuth

    Terraform -->|"deploys images"| AWS_ECR
    AWS_ECR -->|"hosts containers"| AuthService
    AWS_ECR -->|"hosts containers"| ProfileService
    AWS_ECR -->|"hosts containers"| ChatService
    AWS_ECR -->|"hosts containers"| StatusService
    AWS_ECR -->|"hosts containers"| NotificationService
    AWS_ECR -->|"hosts containers"| Frontend

    class User,SMTP,GoogleOAuth external
    class Frontend frontend
    class AuthService,ProfileService,ChatService,StatusService,NotificationService service
    class Postgres,MongoDB,Redis db
    class RabbitMQ broker
    class Nginx,Terraform,AWS_ECR infra

    click AuthService "https://github.com/lukaszfabia/chatterbox/tree/main/auth_service/"
    click ProfileService "https://github.com/lukaszfabia/chatterbox/tree/main/profile_service/"
    click NotificationService "https://github.com/lukaszfabia/chatterbox/tree/main/notification_service/"
    click ChatService "https://github.com/lukaszfabia/chatterbox/tree/main/chat_service/"
    click StatusService "https://github.com/lukaszfabia/chatterbox/tree/main/status_service/"
    click Frontend "https://github.com/lukaszfabia/chatterbox/tree/main/frontend/"
    click Nginx "https://github.com/lukaszfabia/chatterbox/blob/main/nginx/nginx.conf"
    click Terraform "https://github.com/lukaszfabia/chatterbox/blob/main/aws/main.tf"
```
