# satvikg7/scalable-notification-system architecture

> Architecture diagram of the GitHub repository satvikg7/scalable-notification-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/satvikg7/scalable-notification-system
- Repository: https://github.com/satvikg7/scalable-notification-system

## Overview

1. This repository is a Go-based notification service with two main runtime paths: an HTTP API for managing users/notifications, and a RabbitMQ-backed async processing path for delivering notifications.

2. `main.go` is the composition root. It likely loads configuration, initializes the database connection, starts the HTTP server, and wires up RabbitMQ producers/consumers and any scheduler logic. `config/env.go` centralizes environment-variable loading from `.env`.

3. The HTTP boundary lives under `internal/server` and `internal/handlers`. The README indicates the server is built with Fiber, so external clients talk to a Fiber HTTP API. The handlers are split by responsibility:
   - `internal/handlers/users/*` for CRUD-style user endpoints
   - `internal/handlers/notification.go` for notification-related API actions

4. The user subsystem is isolated as a small application slice. `createUser.go`, `getUser.go`, `getUsers.go`, and `deleteUser.go` suggest separate endpoint handlers rather than a single large controller. `internal/utils/getUser.go` likely provides shared lookup/validation logic used by multiple handlers.

5. The domain layer is modeled explicitly in `internal/models`:
   - `user.go`
   - `preference.go`
   - `message.go`
   - `notification.go`
   These structs are the shared data contracts between HTTP handlers, persistence, and queue payloads.

6. Persistence is separated into `internal/db/db.go` plus `schema.sql`. This strongly suggests a relational database, and the README mentions PostgreSQL for logging failed notifications. The schema file is the authoritative source for tables and relationships, while the db package owns connection setup and query access.

7. RabbitMQ is the asynchronous backbone. `internal/rabbitmq/producer.go` publishes notification work, `consumer.go` processes jobs from queues, `config.go` holds broker configuration, and `scheduler.go` coordinates queue/worker behavior. This is the main decoupling point between request intake and notification delivery.

8. The notification workflow is therefore split into ingestion and execution:
   - API receives a request and validates it
   - a notification/message model is created
   - the producer routes it to RabbitMQ, likely by channel and priority
   - consumers pull work and perform delivery
   - failures are retried or persisted for later inspection

9. The README describes queue prioritization, rate limiting, and dynamic worker reallocation. Architecturally, that means the RabbitMQ layer is not just a simple queue consumer; it also includes scheduling/coordination logic to protect external delivery services and keep high-priority messages moving.

10. Failed delivery handling is a separate concern from the request path. The service logs unsuccessful notifications to PostgreSQL, which makes the database both a source of user/preference data and an audit trail for delivery failures.

11. `schema.sql` and the `models` package together define the data contracts for both synchronous API operations and asynchronous message processing. That makes the models a shared boundary between HTTP, queue workers, and persistence.

12. In diagram terms, the cleanest boundaries are:
   - Client/API layer: Fiber server + handlers
   - Core domain/data: models + utils
   - Persistence: db package + PostgreSQL schema
   - Async messaging: RabbitMQ producer/consumer/scheduler
   - Bootstrap/config: main.go + env config

13. The main external dependencies that materially shape the architecture are Go, Fiber, RabbitMQ, and PostgreSQL. The repo is organized as a classic layered service with an async broker in the middle to scale notification throughput and isolate delivery work from request handling.

Main entry points: [`internal/handlers`](https://github.com/satvikg7/scalable-notification-system/tree/main/internal/handlers) (Handlers), [`internal/models`](https://github.com/satvikg7/scalable-notification-system/tree/main/internal/models) (Models), [`internal/db/db.go`](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/db/db.go) (DB), [`main.go`](https://github.com/satvikg7/scalable-notification-system/blob/main/main.go) (main.go)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bootstrap["Bootstrap"]
  node_main["main.go<br/>composition root<br/>[main.go]"]
  node_env["Env config<br/>config loader<br/>[env.go]"]
end

subgraph group_http["HTTP API"]
  node_server["Server<br/>[server.go]"]
  node_handlers["Handlers"]
  node_user_create["Create user<br/>user handler<br/>[createUser.go]"]
  node_user_get["Get user<br/>user handler<br/>[getUser.go]"]
  node_user_list["List users<br/>user handler<br/>[getUsers.go]"]
  node_user_delete["Delete user<br/>user handler<br/>[deleteUser.go]"]
  node_notif_handler["Notification API<br/>notification handler<br/>[notification.go]"]
end

subgraph group_domain["Domain"]
  node_models["Models"]
  node_utils["Lookup utils<br/>helper<br/>[getUser.go]"]
end

subgraph group_persistence["Persistence"]
  node_db[("DB<br/>postgres access<br/>[db.go]")]
  node_schema["Schema<br/>[schema.sql]"]
end

subgraph group_messaging["Async messaging"]
  node_rabbitcfg["Broker config<br/>rabbitmq config<br/>[config.go]"]
  node_producer["Producer<br/>queue publisher<br/>[producer.go]"]
  node_consumer["Consumer<br/>queue worker<br/>[consumer.go]"]
  node_scheduler["Scheduler<br/>queue coordinator<br/>[scheduler.go]"]
end

node_main -->|"loads"| node_env
node_main -->|"starts"| node_server
node_main -->|"opens"| node_db
node_main -->|"configures"| node_rabbitcfg
node_main -->|"wires"| node_scheduler
node_server -->|"routes to"| node_handlers
node_handlers -->|"includes"| node_user_create
node_handlers -->|"includes"| node_user_get
node_handlers -->|"includes"| node_user_list
node_handlers -->|"includes"| node_user_delete
node_handlers -->|"includes"| node_notif_handler
node_user_create -->|"uses"| node_models
node_user_get -->|"uses"| node_utils
node_user_list -->|"queries"| node_db
node_user_delete -->|"mutates"| node_db
node_notif_handler -->|"creates"| node_models
node_notif_handler -->|"publishes"| node_producer
node_producer -->|"coordinates with"| node_scheduler
node_consumer -->|"logs failures"| node_db
node_consumer -->|"deserializes"| node_models
node_db -->|"implements"| node_schema
node_models -->|"shared by"| node_db
node_models -->|"shared by"| node_producer
node_models -->|"shared by"| node_consumer

click node_main "https://github.com/satvikg7/scalable-notification-system/blob/main/main.go"
click node_env "https://github.com/satvikg7/scalable-notification-system/blob/main/config/env.go"
click node_server "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/server/server.go"
click node_handlers "https://github.com/satvikg7/scalable-notification-system/tree/main/internal/handlers"
click node_user_create "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/createUser.go"
click node_user_get "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/getUser.go"
click node_user_list "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/getUsers.go"
click node_user_delete "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/deleteUser.go"
click node_notif_handler "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/notification.go"
click node_models "https://github.com/satvikg7/scalable-notification-system/tree/main/internal/models"
click node_utils "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/utils/getUser.go"
click node_db "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/db/db.go"
click node_schema "https://github.com/satvikg7/scalable-notification-system/blob/main/schema.sql"
click node_rabbitcfg "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/config.go"
click node_producer "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/producer.go"
click node_consumer "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/consumer.go"
click node_scheduler "https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/scheduler.go"

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_env toneBlue
class node_server,node_handlers,node_user_create,node_user_get,node_user_list,node_user_delete,node_notif_handler toneAmber
class node_models,node_utils toneMint
class node_db,node_schema toneRose
class node_rabbitcfg,node_producer,node_consumer,node_scheduler toneIndigo
```

## Components

### Bootstrap

Process startup and configuration

- [main.go](https://github.com/satvikg7/scalable-notification-system/blob/main/main.go): composition root · Wires configuration, HTTP server, database, and messaging together · `main.go`
- [Env config](https://github.com/satvikg7/scalable-notification-system/blob/main/config/env.go): config loader · Loads environment variables and runtime settings · `config/env.go`

### HTTP API

Fiber server and request handlers

- [Server](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/server/server.go): Fiber server · HTTP server setup and route registration · `internal/server/server.go`
- [Handlers](https://github.com/satvikg7/scalable-notification-system/tree/main/internal/handlers): API handlers · HTTP entrypoints for users and notifications · `internal/handlers`
- [Create user](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/createUser.go): user handler · Creates a new user record via HTTP · `internal/handlers/users/createUser.go`
- [Get user](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/getUser.go): user handler · Fetches a single user via HTTP · `internal/handlers/users/getUser.go`
- [List users](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/getUsers.go): user handler · Returns user collections via HTTP · `internal/handlers/users/getUsers.go`
- [Delete user](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/users/deleteUser.go): user handler · Removes a user via HTTP · `internal/handlers/users/deleteUser.go`
- [Notification API](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/handlers/notification.go): notification handler · HTTP actions related to notification submission or control · `internal/handlers/notification.go`

### Domain

Shared data models and helpers

- [Models](https://github.com/satvikg7/scalable-notification-system/tree/main/internal/models): domain models · Shared structs for users, preferences, messages, and notifications · `internal/models`
- [Lookup utils](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/utils/getUser.go): helper · Shared user lookup and validation logic · `internal/utils/getUser.go`

### Persistence

Database connection and schema

- [DB](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/db/db.go): postgres access · Database connection and query access layer · `internal/db/db.go`
- [Schema](https://github.com/satvikg7/scalable-notification-system/blob/main/schema.sql): sql schema · Authoritative table and relationship definitions · `schema.sql`

### Async messaging

RabbitMQ delivery pipeline

- [Broker config](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/config.go): rabbitmq config · RabbitMQ connection and topology settings · `internal/rabbitmq/config.go`
- [Producer](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/producer.go): queue publisher · Publishes notification work onto RabbitMQ · `internal/rabbitmq/producer.go`
- [Consumer](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/consumer.go): queue worker · Consumes queued notifications and performs delivery work · `internal/rabbitmq/consumer.go`
- [Scheduler](https://github.com/satvikg7/scalable-notification-system/blob/main/internal/rabbitmq/scheduler.go): queue coordinator · Coordinates prioritization, rate limiting, and worker allocation · `internal/rabbitmq/scheduler.go`

## Connections

- main.go → Env config: loads · Reads runtime configuration at startup
- main.go → Server: starts · Bootstraps the HTTP service
- main.go → DB: opens · Initializes database connectivity
- main.go → Broker config: configures · Sets up RabbitMQ connectivity
- main.go → Scheduler: wires · Starts async coordination logic
- Server → Handlers: routes to · Connects HTTP routes to handlers
- Handlers → Create user: includes · User creation endpoint
- Handlers → Get user: includes · Single-user retrieval endpoint
- Handlers → List users: includes · User listing endpoint
- Handlers → Delete user: includes · User deletion endpoint
- Handlers → Notification API: includes · Notification-related HTTP actions
- Create user → Models: uses · Builds and validates user domain objects
- Get user → Lookup utils: uses · Shares lookup logic
- List users → DB: queries · Reads users from persistence
- Delete user → DB: mutates · Deletes users in persistence
- Notification API → Models: creates · Creates notification/message payloads
- Notification API → Producer: publishes · Enqueues notification work
- Producer → Scheduler: coordinates with · Respects prioritization and dispatch rules
- Consumer → DB: logs failures · Persists unsuccessful deliveries
- Consumer → Models: deserializes · Consumes shared message and notification structures
- DB → Schema: implements · Backed by the SQL schema
- Models → DB: shared by · Domain structs are stored and queried in persistence
- Models → Producer: shared by · Payloads are published to the queue
- Models → Consumer: shared by · Payloads are consumed from the queue
