# impl0x/impstagram architecture

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

- Interactive diagram: https://gitdiagram.com/impl0x/impstagram
- Repository: https://github.com/impl0x/impstagram

## Overview

Impstagram is presented as an Instagram clone, but this tree exposes a Go backend centered on authentication, account validation, and PostgreSQL-backed user/session/profile data—not the broader social-media features. Its visible user workflow is HTTP auth requests through handlers into auth services, which use repositories and in-memory verification sessions to produce login, OTP, password-reset, and token outcomes. The README also names Resend email and Telegram phone registration. Some wiring and integrations are unsampled, so those links are omitted or marked unverified.

Main entry points: [`backend/internal/service/auth/service.go`](https://github.com/impl0x/impstagram/blob/main/backend/internal/service/auth/service.go) (Auth workflows), [`backend/internal/transport/http/handler/auth/handlers.go`](https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/handler/auth/handlers.go) (Auth routes), [`backend/internal/database/sql/postgres`](https://github.com/impl0x/impstagram/tree/main/backend/internal/database/sql/postgres) (Postgres adapters), [`backend/app/repository.go`](https://github.com/impl0x/impstagram/blob/main/backend/app/repository.go) (Repository wiring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_app["App bootstrap<br/>[app.go]"]
  node_auth_handlers["Auth routes<br/>[handlers.go]"]
  node_validation_handlers["Validation routes<br/>[handlers.go]"]
  node_http_errors["HTTP error mapping<br/>[error_handler.go]"]
  node_response["Response schema<br/>[response.go]"]
end

subgraph group_auth["Authentication"]
  node_auth_service["Auth workflows<br/>[service.go]"]
  node_auth_validation["Account validation<br/>[auth.go]"]
  node_auth_config["Auth configuration<br/>[auth.go]"]
end

subgraph group_data["Persistence"]
  node_repositories["Repository contracts"]
  node_postgres_adapters["Postgres adapters"]
  node_postgres_db[("PostgreSQL")]
  node_repo_wiring["Repository wiring<br/>[repository.go]"]
end

subgraph group_support["Runtime support"]
  node_otp_cache["OTP session caches<br/>[service.go]"]
  node_crypto["Crypto utilities"]
  node_jwt["JWT utilities"]
  node_email_provider["Resend email"]
  node_telegram["Telegram phone"]
end

node_user(("API client"))

node_user -->|"sends requests"| node_auth_handlers
node_auth_handlers -->|"calls workflows"| node_auth_service
node_auth_service -->|"uses repositories"| node_repositories
node_app -.->|"initializes app"| node_repo_wiring
node_repo_wiring -->|"binds adapters"| node_postgres_adapters
node_postgres_adapters -.->|"queries"| node_postgres_db
node_auth_service -->|"stores sessions"| node_otp_cache
node_auth_service -->|"uses cryptography"| node_crypto
node_auth_service -.->|"mints tokens"| node_jwt
node_validation_handlers -->|"validates input"| node_auth_validation
node_auth_handlers -->|"formats results"| node_response
node_http_errors -->|"formats errors"| node_response
node_auth_service -.->|"may send email"| node_email_provider
node_auth_service -.->|"may send phone codes"| node_telegram

click node_app "https://github.com/impl0x/impstagram/blob/main/backend/app/app.go"
click node_auth_handlers "https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/handler/auth/handlers.go"
click node_validation_handlers "https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/handler/validation/handlers.go"
click node_http_errors "https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/error_handler.go"
click node_auth_service "https://github.com/impl0x/impstagram/blob/main/backend/internal/service/auth/service.go"
click node_auth_validation "https://github.com/impl0x/impstagram/blob/main/backend/internal/validation/auth.go"
click node_auth_config "https://github.com/impl0x/impstagram/blob/main/backend/internal/config/services/auth.go"
click node_repositories "https://github.com/impl0x/impstagram/tree/main/backend/internal/repository"
click node_postgres_adapters "https://github.com/impl0x/impstagram/tree/main/backend/internal/database/sql/postgres"
click node_repo_wiring "https://github.com/impl0x/impstagram/blob/main/backend/app/repository.go"
click node_otp_cache "https://github.com/impl0x/impstagram/blob/main/backend/internal/service/auth/service.go"
click node_crypto "https://github.com/impl0x/impstagram/tree/main/backend/pkg/cryptoutil"
click node_jwt "https://github.com/impl0x/impstagram/tree/main/backend/pkg/jwt"
click node_email_provider "https://github.com/impl0x/impstagram/tree/main/backend/pkg/email/resend"
click node_response "https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/response/response.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_app,node_auth_handlers,node_validation_handlers,node_http_errors,node_response,node_user toneBlue
class node_auth_service,node_auth_validation,node_auth_config toneAmber
class node_repositories,node_postgres_adapters,node_postgres_db,node_repo_wiring toneMint
class node_otp_cache,node_crypto,node_jwt,node_email_provider,node_telegram toneRose
```

## Components

### HTTP API

- [App bootstrap](https://github.com/impl0x/impstagram/blob/main/backend/app/app.go): `backend/app/app.go`
- [Auth routes](https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/handler/auth/handlers.go): `backend/internal/transport/http/handler/auth/handlers.go`
- [Validation routes](https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/handler/validation/handlers.go): `backend/internal/transport/http/handler/validation/handlers.go`
- [HTTP error mapping](https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/error_handler.go): `backend/internal/transport/http/error_handler.go`
- [Response schema](https://github.com/impl0x/impstagram/blob/main/backend/internal/transport/http/response/response.go): `backend/internal/transport/http/response/response.go`

### Authentication

- [Auth workflows](https://github.com/impl0x/impstagram/blob/main/backend/internal/service/auth/service.go): `backend/internal/service/auth/service.go`
- [Account validation](https://github.com/impl0x/impstagram/blob/main/backend/internal/validation/auth.go): `backend/internal/validation/auth.go`
- [Auth configuration](https://github.com/impl0x/impstagram/blob/main/backend/internal/config/services/auth.go): `backend/internal/config/services/auth.go`

### Persistence

- [Repository contracts](https://github.com/impl0x/impstagram/tree/main/backend/internal/repository): `backend/internal/repository`
- [Postgres adapters](https://github.com/impl0x/impstagram/tree/main/backend/internal/database/sql/postgres): `backend/internal/database/sql/postgres`
- **PostgreSQL**
- [Repository wiring](https://github.com/impl0x/impstagram/blob/main/backend/app/repository.go): `backend/app/repository.go`

### Runtime support

- [OTP session caches](https://github.com/impl0x/impstagram/blob/main/backend/internal/service/auth/service.go): `backend/internal/service/auth/service.go`
- [Crypto utilities](https://github.com/impl0x/impstagram/tree/main/backend/pkg/cryptoutil): `backend/pkg/cryptoutil`
- [JWT utilities](https://github.com/impl0x/impstagram/tree/main/backend/pkg/jwt): `backend/pkg/jwt`
- [Resend email](https://github.com/impl0x/impstagram/tree/main/backend/pkg/email/resend): `backend/pkg/email/resend`
- **Telegram phone**

### Other components

- **API client**

## Connections

- API client → Auth routes: sends requests (evidence: `backend/internal/transport/http/handler/auth/handlers.go`)
- Auth routes → Auth workflows: calls workflows (evidence: `backend/internal/transport/http/handler/auth/handlers.go`)
- Auth workflows → Repository contracts: uses repositories (evidence: `backend/internal/service/auth/service.go`)
- App bootstrap → Repository wiring: initializes app
- Repository wiring → Postgres adapters: binds adapters (evidence: `backend/app/repository.go`)
- Postgres adapters → PostgreSQL: queries
- Auth workflows → OTP session caches: stores sessions (evidence: `backend/internal/service/auth/service.go`)
- Auth workflows → Crypto utilities: uses cryptography (evidence: `backend/internal/service/auth/service.go`)
- Auth workflows → JWT utilities: mints tokens
- Validation routes → Account validation: validates input (evidence: `backend/internal/transport/http/handler/validation/handlers.go`)
- Auth routes → Response schema: formats results (evidence: `backend/internal/transport/http/handler/auth/handlers.go`)
- HTTP error mapping → Response schema: formats errors (evidence: `backend/internal/transport/http/error_handler.go`)
- Auth workflows → Resend email: may send email (evidence: `README.md`)
- Auth workflows → Telegram phone: may send phone codes (evidence: `README.md`)
