# younsseamazzal/social-network architecture

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

- Interactive diagram: https://gitdiagram.com/younsseamazzal/social-network
- Repository: https://github.com/younsseamazzal/social-network

## Overview

This is a small social-network application with a Next.js frontend and Go HTTP backend. The demonstrated workflow is account registration or login, followed by a session-protected feed where users can read and create posts. The backend initializes SQLite and validates session cookies on protected routes. Chat, groups, and profile pages are present in the tree, but their sampled files provide no evidence of implemented behavior or backend connections; their relationships are therefore not inferred.

Main entry points: [`backend/server.go`](https://github.com/younsseamazzal/social-network/blob/main/backend/server.go) (HTTP router), [`backend/pkg/db/sqlite/sqlite.go`](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/sqlite/sqlite.go) (SQLite initialization), [`backend/pkg/handlers/register.go`](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/register.go) (Registration handler), [`frontend/app/login/page.js`](https://github.com/younsseamazzal/social-network/blob/main/frontend/app/login/page.js) (Login and registration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_frontend_auth["Login and registration<br/>[page.js]"]
  node_register_page["Registration form<br/>[page.js]"]
  node_route_guard["Page session guard<br/>[middleware.js]"]
  node_feed_page["Post feed<br/>[page.js]"]
  node_chat_page["Chat page<br/>[page.js]"]
  node_groups_page["Groups page<br/>[page.js]"]
  node_profile_page["Profile page<br/>[page.js]"]
end

subgraph group_api["HTTP backend"]
  node_api_server["HTTP router<br/>[server.go]"]
  node_login_handler["Login handler<br/>[login.go]"]
  node_register_handler["Registration handler<br/>[register.go]"]
  node_posts_handler["Posts handler<br/>[posts.go]"]
  node_users_handler["Users handler<br/>[users.go]"]
  node_auth_middleware["API session guard<br/>[session.go]"]
  node_response_errors["Error responses<br/>[error.go]"]
end

subgraph group_persistence["Persistence and sessions"]
  node_sqlite_init["SQLite initialization<br/>[sqlite.go]"]
  node_login_queries["Login queries<br/>[login.go]"]
  node_register_queries["User queries<br/>[register.go]"]
  node_session_queries["Session queries<br/>[session.go]"]
  node_social_db[("Social database<br/>[social_network.db]")]
end

node_visitor(("Visitor"))

node_visitor -->|"uses"| node_frontend_auth
node_visitor -->|"registers"| node_register_page
node_frontend_auth -->|"posts login"| node_api_server
node_register_page -->|"posts registration"| node_api_server
node_visitor -->|"views feed"| node_feed_page
node_feed_page -->|"fetches and creates posts"| node_api_server
node_api_server -->|"initializes"| node_sqlite_init
node_api_server -->|"routes login"| node_login_handler
node_api_server -->|"routes registration"| node_register_handler
node_api_server -->|"protects routes"| node_auth_middleware
node_api_server -->|"routes protected posts"| node_posts_handler
node_api_server -->|"routes protected users"| node_users_handler
node_auth_middleware -->|"validates session"| node_session_queries
node_register_handler -->|"creates user"| node_register_queries
node_register_handler -->|"checks email"| node_sqlite_init
node_session_queries -->|"reads and writes session"| node_sqlite_init
node_sqlite_init -->|"opens database"| node_social_db

click node_frontend_auth "https://github.com/younsseamazzal/social-network/blob/main/frontend/app/login/page.js"
click node_register_page "https://github.com/younsseamazzal/social-network/blob/main/frontend/app/register/page.js"
click node_route_guard "https://github.com/younsseamazzal/social-network/blob/main/frontend/middleware.js"
click node_feed_page "https://github.com/younsseamazzal/social-network/blob/main/frontend/app/page.js"
click node_chat_page "https://github.com/younsseamazzal/social-network/blob/main/frontend/app/chat/page.js"
click node_groups_page "https://github.com/younsseamazzal/social-network/blob/main/frontend/app/groups/page.js"
click node_profile_page "https://github.com/younsseamazzal/social-network/blob/main/frontend/app/profile/page.js"
click node_api_server "https://github.com/younsseamazzal/social-network/blob/main/backend/server.go"
click node_login_handler "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/login.go"
click node_register_handler "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/register.go"
click node_posts_handler "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/posts.go"
click node_users_handler "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/users.go"
click node_auth_middleware "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/middleware/session.go"
click node_response_errors "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/response/error.go"
click node_sqlite_init "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/sqlite/sqlite.go"
click node_login_queries "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/queries/login.go"
click node_register_queries "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/queries/register.go"
click node_session_queries "https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/queries/session.go"
click node_social_db "https://github.com/younsseamazzal/social-network/blob/main/backend/social_network.db"

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_frontend_auth,node_register_page,node_route_guard,node_feed_page,node_chat_page,node_groups_page,node_profile_page toneBlue
class node_api_server,node_login_handler,node_register_handler,node_posts_handler,node_users_handler,node_auth_middleware,node_response_errors toneAmber
class node_sqlite_init,node_login_queries,node_register_queries,node_session_queries,node_social_db toneMint
class node_visitor toneIndigo
```

## Components

### Web application

- [Login and registration](https://github.com/younsseamazzal/social-network/blob/main/frontend/app/login/page.js): `frontend/app/login/page.js`
- [Registration form](https://github.com/younsseamazzal/social-network/blob/main/frontend/app/register/page.js): `frontend/app/register/page.js`
- [Page session guard](https://github.com/younsseamazzal/social-network/blob/main/frontend/middleware.js): `frontend/middleware.js`
- [Post feed](https://github.com/younsseamazzal/social-network/blob/main/frontend/app/page.js): `frontend/app/page.js`
- [Chat page](https://github.com/younsseamazzal/social-network/blob/main/frontend/app/chat/page.js): `frontend/app/chat/page.js`
- [Groups page](https://github.com/younsseamazzal/social-network/blob/main/frontend/app/groups/page.js): `frontend/app/groups/page.js`
- [Profile page](https://github.com/younsseamazzal/social-network/blob/main/frontend/app/profile/page.js): `frontend/app/profile/page.js`

### HTTP backend

- [HTTP router](https://github.com/younsseamazzal/social-network/blob/main/backend/server.go): `backend/server.go`
- [Login handler](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/login.go): `backend/pkg/handlers/login.go`
- [Registration handler](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/register.go): `backend/pkg/handlers/register.go`
- [Posts handler](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/posts.go): `backend/pkg/handlers/posts.go`
- [Users handler](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/handlers/users.go): `backend/pkg/handlers/users.go`
- [API session guard](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/middleware/session.go): `backend/pkg/middleware/session.go`
- [Error responses](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/response/error.go): `backend/pkg/response/error.go`

### Persistence and sessions

- [SQLite initialization](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/sqlite/sqlite.go): `backend/pkg/db/sqlite/sqlite.go`
- [Login queries](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/queries/login.go): `backend/pkg/db/queries/login.go`
- [User queries](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/queries/register.go): `backend/pkg/db/queries/register.go`
- [Session queries](https://github.com/younsseamazzal/social-network/blob/main/backend/pkg/db/queries/session.go): `backend/pkg/db/queries/session.go`
- [Social database](https://github.com/younsseamazzal/social-network/blob/main/backend/social_network.db): `backend/social_network.db`

### Other components

- **Visitor**

## Connections

- Visitor → Login and registration: uses (evidence: `frontend/app/login/page.js`)
- Visitor → Registration form: registers (evidence: `frontend/app/register/page.js`)
- Login and registration → HTTP router: posts login (evidence: `frontend/app/login/page.js`)
- Registration form → HTTP router: posts registration (evidence: `frontend/app/register/page.js`)
- Visitor → Post feed: views feed (evidence: `frontend/app/page.js`)
- Post feed → HTTP router: fetches and creates posts (evidence: `frontend/app/page.js`)
- HTTP router → SQLite initialization: initializes (evidence: `backend/server.go`)
- HTTP router → Login handler: routes login (evidence: `backend/server.go`)
- HTTP router → Registration handler: routes registration (evidence: `backend/server.go`)
- HTTP router → API session guard: protects routes (evidence: `backend/server.go`)
- HTTP router → Posts handler: routes protected posts (evidence: `backend/server.go`)
- HTTP router → Users handler: routes protected users (evidence: `backend/server.go`)
- API session guard → Session queries: validates session (evidence: `backend/pkg/middleware/session.go`)
- Registration handler → User queries: creates user (evidence: `backend/pkg/handlers/register.go`)
- Registration handler → SQLite initialization: checks email (evidence: `backend/pkg/handlers/register.go`)
- Session queries → SQLite initialization: reads and writes session (evidence: `backend/pkg/db/queries/session.go`)
- SQLite initialization → Social database: opens database (evidence: `backend/pkg/db/sqlite/sqlite.go`)
