# adityasharma-tech/synapse architecture

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

- Interactive diagram: https://gitdiagram.com/adityasharma-tech/synapse
- Repository: https://github.com/adityasharma-tech/synapse

## Overview

##### Project Type and Purpose
- This is a Lerna-managed monorepo containing a full-stack streaming platform.
- Frontends:
- apps/auth – an Angular-Vite SPA handling user login/registration flows.
- apps/web  – a React/TSX/Vite site for browsing, streaming, chat, and payments.
- Backends & Services:
- apps/server      – a Node/Express REST + WebSocket API server.
- apps/queue-worker– a background worker (mail, SMS, transient tasks) using RabbitMQ.
- apps/permit-service – a microservice for permission checks or feature gating.
- Shared packages:
- drizzle-client   – DB schema and migrations (Postgres via Drizzle ORM).
- rmq-client       – RabbitMQ abstraction.
- zod-client       – Zod validators for request/response schemas.
- lib              – common error handlers, logging, async wrappers.

##### Key Architectural Patterns
- Micro-frontend pattern: separate Angular auth app and React main web app.
- Micro-services: distinct Node services (main API, queue worker, permit service).
- Event-driven async processing via RabbitMQ.
- Shared monorepo libraries to enforce type-safe contracts (Zod, Drizzle, shared lib).
- REST + WebSocket hybrid for real-time chat/stream controls.
- Docker + docker-compose + Nginx for local/on-premise deployment.

##### Main Components
a. Frontend Layer
- Angular Auth App (apps/auth)
- React Web App (apps/web)
b. API Layer (apps/server)
- REST Controllers (auth, user, admin, webhook, stream)
- WebSocket Gateway (chat, live events)
- Middleware (Auth, Rate Limit, Validation)
c. Background Processing
- RabbitMQ Broker
- Queue Worker (mail.service.ts, worker.ts)
d. Microservice: Permit Service
e. Data Layer
- Postgres DB (Drizzle migrations + client)
- Redis Cache / session store
f. External Integrations
- Cloudinary (media uploads)
- Cashfree Payments (webhook callbacks)
- SMTP / SMS gateways

##### Relationships & Data Flows
1. User → Angular Auth App or React Web App
2. Frontends ↔ apps/server over HTTPS for REST and wss:// for WebSocket
3. apps/server → Postgres via drizzle-client
4. apps/server ↔ Redis for caching, rate limiting, sessions
5. apps/server → RabbitMQ (publish events)
6. Queue Worker ← RabbitMQ (consume jobs: send mail/SMS, other tasks)
7. apps/server → Permit Service (HTTP/RPC) for feature checks
8. apps/server → External APIs: Cloudinary, Cashfree
9. Cashfree → apps/server/webhook endpoint → triggers DB updates / RabbitMQ

##### Elements
- Clear labels on each container/component (e.g., “apps/server (Express + WebSocket)”).
- Annotations for major shared libraries in the monorepo (drizzle-client, zod-client, rmq-client).
- A load-balancer or ingress (Nginx) in front of the API if depicting production infra.

- Captures front-to-back separation
- Shows real-time vs. async flows
- Highlights data persistence and caching
- Details external integrations and microservices
- Reflects the Lerna monorepo’s shared-library strategy

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        AuthApp["Angular Auth App"]:::frontend
        WebApp["React Web App"]:::frontend
    end

    %% API & Microservices Layer
    subgraph "API & Microservices"
        direction TB
        NGINX["Nginx Load Balancer"]:::service
        Server["apps/server<br/>(Express + WebSocket)"]:::service
        Permit["Permit Service"]:::service
        Worker["Queue Worker"]:::service
    end

    %% Data & Messaging Layer
    subgraph "Data & Messaging"
        direction TB
        RabbitMQ["RabbitMQ Broker"]:::broker
        Postgres[(Postgres DB)]:::db
        Redis[(Redis Cache/Session)]:::db
    end

    %% External Integrations
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary"]:::external
        Cashfree["Cashfree Payments"]:::external
        SMTP_SMS["SMTP / SMS Gateways"]:::external
    end

    %% Shared Libraries
    subgraph "Shared Packages"
        direction TB
        Drizzle["drizzle-client"]:::shared
        RMQClient["rmq-client"]:::shared
        Zod["zod-client"]:::shared
        Lib["lib"]:::shared
    end

    %% User Interaction
    User["User"]:::external

    %% Connections
    User -->|"HTTP/HTTPS"| AuthApp
    User -->|"HTTP/HTTPS"| WebApp

    AuthApp -->|"HTTP/HTTPS"| NGINX
    WebApp -->|"HTTP/HTTPS / WSS"| NGINX

    NGINX -->|"HTTP/HTTPS / WSS"| Server

    Server -->|"HTTP/JSON"| Postgres
    Server -->|"AMQP Publish"| RabbitMQ
    Server -->|"RPC/HTTP"| Permit
    Server -->|"Cache / Session"| Redis
    Server -->|"HTTP API"| Cloudinary
    Server -->|"HTTP API"| Cashfree
    Server -->|"HTTP API"| SMTP_SMS

    Cashfree -->|"Webhook Callback"| Server

    RabbitMQ -->|"AMQP Consume"| Worker

    %% Shared Packages Usage
    Server ---> Drizzle
    Server ---> RMQClient
    Server ---> Zod
    Server ---> Lib
    Worker ---> RMQClient
    Worker ---> Lib
    Permit ---> Zod
    Permit ---> Lib

    %% Click Events
    click AuthApp "https://github.com/adityasharma-tech/synapse/tree/main/apps/auth"
    click WebApp "https://github.com/adityasharma-tech/synapse/tree/main/apps/web"
    click Server "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/index.ts"
    click Server "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/app.ts"
    click AuthController "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/controller/auth.controller.ts"
    click UserController "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/controller/user.controller.ts"
    click AdminController "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/controller/admin.controller.ts"
    click StreamController "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/controller/stream.controller.ts"
    click WebhookController "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/controller/webhook.controller.ts"
    click DefaultController "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/controller/default.controller.ts"
    click WSService "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/services/ws.service.ts"
    click SocketMiddleware "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/middleware/socket.middleware.ts"
    click AuthMiddleware "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/middleware/auth.middleware.ts"
    click LimiterMiddleware "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/middleware/limiters.middleware.ts"
    click ValidatorMiddleware "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/middleware/validator.middleware.ts"
    click MulterMiddleware "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/middleware/multer.middeware.ts"
    click AuthRoutes "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/routes/auth.routes.ts"
    click UserRoutes "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/routes/user.routes.ts"
    click AdminRoutes "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/routes/admin.routes.ts"
    click StreamRoutes "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/routes/stream.routes.ts"
    click WebhookRoutes "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/routes/webhook.routes.ts"
    click DefaultRoutes "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/routes/default.routes.ts"
    click QueueWorker "https://github.com/adityasharma-tech/synapse/blob/main/apps/queue-worker/src/worker.ts"
    click MailServiceWorker "https://github.com/adityasharma-tech/synapse/blob/main/apps/queue-worker/src/mail.service.ts"
    click Permit "https://github.com/adityasharma-tech/synapse/blob/main/apps/permit-service/index.ts"
    click DrizzleClient "https://github.com/adityasharma-tech/synapse/blob/main/packages/drizzle-client/src/client.ts"
    click DrizzleSchemas "https://github.com/adityasharma-tech/synapse/tree/main/packages/drizzle-client/src/schemas"
    click DrizzleSQL "https://github.com/adityasharma-tech/synapse/blob/main/packages/drizzle-client/drizzle/*.sql"
    click RMQClient "https://github.com/adityasharma-tech/synapse/blob/main/packages/rmq-client/src/client.ts"
    click ZodValidators "https://github.com/adityasharma-tech/synapse/tree/main/packages/zod-client/main/validators"
    click ZodClient "https://github.com/adityasharma-tech/synapse/tree/main/packages/zod-client/client"
    click ErrorHandler "https://github.com/adityasharma-tech/synapse/blob/main/packages/lib/src/errorHandler.ts"
    click Logger "https://github.com/adityasharma-tech/synapse/blob/main/packages/lib/src/logger.ts"
    click AsyncHandler "https://github.com/adityasharma-tech/synapse/blob/main/packages/lib/src/asyncHandler.ts"
    click Utils "https://github.com/adityasharma-tech/synapse/blob/main/packages/lib/src/utils.ts"
    click RedisService "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/services/redis.service.ts"
    click CloudinaryHelper "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/lib/cloudinary.ts"
    click PaymentsService "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/services/payments.service.ts"
    click SMSService "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/services/sms.service.ts"
    click MailServiceAPI "https://github.com/adityasharma-tech/synapse/blob/main/apps/server/src/services/mail.service.ts"
    click Dockerfile "https://github.com/adityasharma-tech/synapse/tree/main/Dockerfile"
    click DockerCompose "https://github.com/adityasharma-tech/synapse/blob/main/docker-compose.yml"
    click NginxConf "https://github.com/adityasharma-tech/synapse/blob/main/nginx.conf"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1;
    classDef service fill:#C8E6C9,stroke:#43A047,color:#1B5E20;
    classDef db fill:#FFE0B2,stroke:#FB8C00,color:#E65100;
    classDef broker fill:#E1BEE7,stroke:#8E24AA,color:#4A148C,shape:hexagon;
    classDef external fill:#E0E0E0,stroke:#757575,color:#212121,stroke-dasharray: 5 5;
    classDef shared fill:#F5F5F5,stroke:#9E9E9E,color:#424242,stroke-dasharray: 2 2;
```
