# willbarbosa/clone-tabnews architecture

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

- Interactive diagram: https://gitdiagram.com/willbarbosa/clone-tabnews
- Repository: https://github.com/willbarbosa/clone-tabnews

## Overview

clone-tabnews is a course.dev implementation of TabNews. Its visible runtime centers on HTTP APIs for user accounts and sessions, backed by PostgreSQL, with a status endpoint and a small web UI. The login flow authenticates credentials, creates a session, and sets a cookie; logout validates and expires that session. User creation, profile operations, and migrations are distinct API areas in the tree, but their handler implementations were not sampled. Edges for those areas are omitted; optional or unverified relationships are dashed with no evidence path.

Main entry points: [`pages/api/v1/sessions/index.js`](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/sessions/index.js) (Sessions API), [`models/session.js`](https://github.com/willbarbosa/clone-tabnews/blob/main/models/session.js) (Session model), [`infra/database.js`](https://github.com/willbarbosa/clone-tabnews/blob/main/infra/database.js) (Database access), [`models/authentication.js`](https://github.com/willbarbosa/clone-tabnews/blob/main/models/authentication.js) (Credential authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_home["Construction page<br/>[index.js]"]
  node_status_page["Status page<br/>[index.js]"]
end

subgraph group_api["HTTP API"]
  node_sessions_api["Sessions API<br/>[index.js]"]
  node_status_api["Status API<br/>[index.js]"]
  node_user_api["Current user API<br/>[index.js]"]
  node_users_api["Users API<br/>[index.js]"]
  node_profile_api["User profile API<br/>[index.js]"]
  node_migrations_api["Migrations API<br/>[index.js]"]
end

subgraph group_identity["Identity and accounts"]
  node_authentication["Credential authentication<br/>[authentication.js]"]
  node_user_model["User model<br/>[user.js]"]
  node_password["Password handling<br/>[password.js]"]
  node_session_model["Session model<br/>[session.js]"]
end

subgraph group_persistence["Persistence"]
  node_migrator["Migration runner<br/>[migrator.js]"]
  node_postgres[("PostgreSQL")]
  node_database["Database access<br/>[database.js]"]
  node_schema_migrations["Database migrations"]
end

subgraph group_platform["Shared services"]
  node_controller["HTTP controller<br/>[controller.js]"]
  node_errors["API errors<br/>[errors.js]"]
  node_email["Email service<br/>[email.js]"]
end

node_visitor(("Visitor"))

node_visitor -->|"opens"| node_home
node_visitor -->|"opens"| node_status_page
node_visitor -.->|"submits credentials"| node_sessions_api
node_sessions_api -->|"authenticates"| node_authentication
node_sessions_api -->|"creates session"| node_session_model
node_sessions_api -->|"expires session"| node_session_model
node_sessions_api -->|"sets cookie"| node_controller
node_authentication -->|"looks up user"| node_user_model
node_authentication -->|"checks password"| node_password
node_session_model -->|"queries"| node_database
node_user_model -->|"queries"| node_database
node_user_model -->|"hashes password"| node_password
node_database -->|"queries"| node_postgres
node_controller -->|"reads expiry"| node_session_model
node_controller -->|"formats errors"| node_errors
node_status_page -->|"polls status"| node_status_api
node_status_api -->|"reads status"| node_database
node_visitor -.->|"requests account"| node_user_api
node_visitor -.->|"manages users"| node_users_api
node_visitor -.->|"requests profile"| node_profile_api
node_visitor -.->|"requests migrations"| node_migrations_api
node_migrations_api -.->|"dispatches"| node_migrator
node_migrator -.->|"applies"| node_schema_migrations
node_email -.->|"sends email"| node_visitor

click node_home "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/index.js"
click node_status_page "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/status/index.js"
click node_sessions_api "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/sessions/index.js"
click node_status_api "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/status/index.js"
click node_user_api "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/user/index.js"
click node_users_api "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/users/index.js"
click node_profile_api "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/users/%5Busername%5D/index.js"
click node_migrations_api "https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/migrations/index.js"
click node_authentication "https://github.com/willbarbosa/clone-tabnews/blob/main/models/authentication.js"
click node_user_model "https://github.com/willbarbosa/clone-tabnews/blob/main/models/user.js"
click node_password "https://github.com/willbarbosa/clone-tabnews/blob/main/models/password.js"
click node_session_model "https://github.com/willbarbosa/clone-tabnews/blob/main/models/session.js"
click node_migrator "https://github.com/willbarbosa/clone-tabnews/blob/main/models/migrator.js"
click node_database "https://github.com/willbarbosa/clone-tabnews/blob/main/infra/database.js"
click node_schema_migrations "https://github.com/willbarbosa/clone-tabnews/tree/main/infra/migrations"
click node_controller "https://github.com/willbarbosa/clone-tabnews/blob/main/infra/controller.js"
click node_errors "https://github.com/willbarbosa/clone-tabnews/blob/main/infra/errors.js"
click node_email "https://github.com/willbarbosa/clone-tabnews/blob/main/infra/email.js"

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_home,node_status_page toneBlue
class node_sessions_api,node_status_api,node_user_api,node_users_api,node_profile_api,node_migrations_api toneAmber
class node_authentication,node_user_model,node_password,node_session_model toneMint
class node_migrator,node_postgres,node_database,node_schema_migrations toneRose
class node_controller,node_errors,node_email,node_visitor toneIndigo
```

## Components

### Web interface

- [Construction page](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/index.js): `pages/index.js`
- [Status page](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/status/index.js): `pages/status/index.js`

### HTTP API

- [Sessions API](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/sessions/index.js): `pages/api/v1/sessions/index.js`
- [Status API](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/status/index.js): `pages/api/v1/status/index.js`
- [Current user API](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/user/index.js): `pages/api/v1/user/index.js`
- [Users API](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/users/index.js): `pages/api/v1/users/index.js`
- [User profile API](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/users/%5Busername%5D/index.js): `pages/api/v1/users/[username]/index.js`
- [Migrations API](https://github.com/willbarbosa/clone-tabnews/blob/main/pages/api/v1/migrations/index.js): `pages/api/v1/migrations/index.js`

### Identity and accounts

- [Credential authentication](https://github.com/willbarbosa/clone-tabnews/blob/main/models/authentication.js): `models/authentication.js`
- [User model](https://github.com/willbarbosa/clone-tabnews/blob/main/models/user.js): `models/user.js`
- [Password handling](https://github.com/willbarbosa/clone-tabnews/blob/main/models/password.js): `models/password.js`
- [Session model](https://github.com/willbarbosa/clone-tabnews/blob/main/models/session.js): `models/session.js`

### Persistence

- [Migration runner](https://github.com/willbarbosa/clone-tabnews/blob/main/models/migrator.js): `models/migrator.js`
- **PostgreSQL**
- [Database access](https://github.com/willbarbosa/clone-tabnews/blob/main/infra/database.js): `infra/database.js`
- [Database migrations](https://github.com/willbarbosa/clone-tabnews/tree/main/infra/migrations): `infra/migrations`

### Shared services

- [HTTP controller](https://github.com/willbarbosa/clone-tabnews/blob/main/infra/controller.js): `infra/controller.js`
- [API errors](https://github.com/willbarbosa/clone-tabnews/blob/main/infra/errors.js): `infra/errors.js`
- [Email service](https://github.com/willbarbosa/clone-tabnews/blob/main/infra/email.js): `infra/email.js`

### Other components

- **Visitor**

## Connections

- Visitor → Construction page: opens
- Visitor → Status page: opens
- Visitor → Sessions API: submits credentials
- Sessions API → Credential authentication: authenticates (evidence: `pages/api/v1/sessions/index.js`)
- Sessions API → Session model: creates session (evidence: `pages/api/v1/sessions/index.js`)
- Sessions API → Session model: expires session (evidence: `pages/api/v1/sessions/index.js`)
- Sessions API → HTTP controller: sets cookie (evidence: `pages/api/v1/sessions/index.js`)
- Credential authentication → User model: looks up user (evidence: `models/authentication.js`)
- Credential authentication → Password handling: checks password (evidence: `models/authentication.js`)
- Session model → Database access: queries (evidence: `models/session.js`)
- User model → Database access: queries (evidence: `models/user.js`)
- User model → Password handling: hashes password (evidence: `models/user.js`)
- Database access → PostgreSQL: queries (evidence: `infra/database.js`)
- HTTP controller → Session model: reads expiry (evidence: `infra/controller.js`)
- HTTP controller → API errors: formats errors (evidence: `infra/controller.js`)
- Status page → Status API: polls status (evidence: `pages/status/index.js`)
- Status API → Database access: reads status (evidence: `pages/api/v1/status/index.js`)
- Visitor → Current user API: requests account
- Visitor → Users API: manages users
- Visitor → User profile API: requests profile
- Visitor → Migrations API: requests migrations
- Migrations API → Migration runner: dispatches
- Migration runner → Database migrations: applies
- Email service → Visitor: sends email
