# gabrieldornelas/clone-tabnews architecture

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

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

## Overview

##### Project type and purpose
- Full-stack web application built with Next.js (pages/, pages/api/v1/…)
- Provides user management, sessions, migrations, and status endpoints
- Intended as a “clone” of TabNews, likely for posting and reading content

##### File structure
- Top-level infra/: Docker Compose (compose.yaml), DB bootstrap scripts, controller.js, database.js
- pages/: Next.js pages (SSR UI) and API routes under pages/api/v1
- models/: ORM-style modules (user, session, password, authentication, migrator)
- infra/migrations: schema migration scripts
- tests/: integration tests driving the HTTP API
- Config and workflows (.env.development, GitHub Actions, ESLint, Jest)

##### Extract key README insights
- Very minimal; confirms it’s a “clone-tabnews” course project

##### Main components & their interactions
a. Browser (end user)
– Hits UI routes (pages/index.js, pages/status)
– Hits API routes (pages/api/v1/…)
b. Next.js Server
– Serves UI pages
– Exposes RESTful JSON API under /api/v1
– Uses infra/controller.js for request handling
c. Controller Layer (infra/controller.js)
– Parses HTTP requests, invokes business logic in models
– Handles errors via infra/errors.js
d. Data Access Layer (models/*.js)
– Models for User, Session, Password, Authentication, Migrator
– Calls database.js for low-level queries
e. PostgreSQL Database
– Stateful store for users, sessions
– Initialized/migrated via infra/migrations and wait-for-postgres.js
f. Docker Compose (infra/compose.yaml)
– Defines Node service and Postgres service
– Orchestrates local dev environment
g. External Dependencies
– Node.js, Next.js, PostgreSQL, GitHub Actions (CI), Husky/commitlint

##### Architectural patterns & design principles
- MVC-like layering: Controllers → Models → Database
- API versioning (v1 namespace) to allow future upgrades
- Migration-driven schema evolution
- Separation of concerns: UI pages vs. API routes
- DevOps: containerized infra and CI pipelines

– UI Subbox (pages/index.js, pages/status)
– API Subbox (pages/api/v1/…)
– Controller (infra/controller.js, errors.js)
– Models (user, session, password, auth, migrator)
7. A footer or side note for Docker Compose, CI, and tests as supporting infrastructure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Browser["Browser"]:::presentation
        UI_Index["pages/index.js"]:::frontend
        UI_Status["pages/status/index.js"]:::frontend
    end

    %% Application Layer (Node Container)
    subgraph "Node Container" 
        direction TB
        subgraph "Next.js Server" 
            direction TB
            UI_Index --> NextServer["Next.js Server (Node.js + pages/)"]:::application
            UI_Status --> NextServer
            API_Users["/api/v1/users"]:::api
            API_UserDetail["/api/v1/users/[username]"]:::api
            API_Sessions["/api/v1/sessions"]:::api
            API_Status["/api/v1/status"]:::api
            API_Migrations["/api/v1/migrations"]:::api
        end

        subgraph "Controller Layer" 
            direction TB
            Controller["infra/controller.js"]:::infra
            Errors["infra/errors.js"]:::infra
        end

        subgraph "Model Layer" 
            direction TB
            Model_User["models/user.js"]:::model
            Model_Session["models/session.js"]:::model
            Model_Password["models/password.js"]:::model
            Model_Auth["models/authentication.js"]:::model
            Model_Migrator["models/migrator.js"]:::model
        end

        %% Connections inside Node Container
        API_Users -->|"handles request"| Controller
        API_UserDetail -->|"handles request"| Controller
        API_Sessions -->|"handles request"| Controller
        API_Status -->|"handles request"| Controller
        API_Migrations -->|"handles request"| Controller
        Controller -->|"invokes models"| Model_User
        Controller --> Model_Session
        Controller --> Model_Password
        Controller --> Model_Auth
        Controller --> Model_Migrator
        Model_User -->|"queries via"| DBClient
        Model_Session --> DBClient
        Model_Password --> DBClient
        Model_Auth --> DBClient
        Model_Migrator --> DBClient
    end

    %% Database Client
    DBClient["infra/database.js"]:::infra

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Postgres["PostgreSQL"]:::data
        Migrate1["1740019112233_create-users.js"]:::data
        Migrate2["1749156310798_create-sessions.js"]:::data
        Migrate1 --> Postgres
        Migrate2 --> Postgres
        DBClient -->|"SQL queries"| Postgres
    end

    %% Infrastructure
    infraCompose["infra/compose.yaml"]:::infra
    WaitForPostgres["infra/scripts/wait-for-postgres.js"]:::infra
    infraCompose -->|"orchestrates"| NextServer
    infraCompose --> Postgres
    WaitForPostgres --> Postgres

    %% Browser interactions
    Browser -->|"SSR page requests"| UI_Index
    Browser -->|"SSR page requests"| UI_Status
    Browser -->|"AJAX/REST calls"| API_Users
    Browser --> API_UserDetail
    Browser --> API_Sessions
    Browser --> API_Status
    Browser --> API_Migrations

    %% Click Events
    click UI_Index "https://github.com/gabrieldornelas/clone-tabnews/blob/main/pages/index.js"
    click UI_Status "https://github.com/gabrieldornelas/clone-tabnews/blob/main/pages/status/index.js"
    click API_Users "https://github.com/gabrieldornelas/clone-tabnews/blob/main/pages/api/v1/users/index.js"
    click API_UserDetail "https://github.com/gabrieldornelas/clone-tabnews/blob/main/pages/api/v1/users/[username]/index.js"
    click API_Sessions "https://github.com/gabrieldornelas/clone-tabnews/blob/main/pages/api/v1/sessions/index.js"
    click API_Status "https://github.com/gabrieldornelas/clone-tabnews/blob/main/pages/api/v1/status/index.js"
    click API_Migrations "https://github.com/gabrieldornelas/clone-tabnews/blob/main/pages/api/v1/migrations/index.js"
    click Controller "https://github.com/gabrieldornelas/clone-tabnews/blob/main/infra/controller.js"
    click Errors "https://github.com/gabrieldornelas/clone-tabnews/blob/main/infra/errors.js"
    click DBClient "https://github.com/gabrieldornelas/clone-tabnews/blob/main/infra/database.js"
    click Model_User "https://github.com/gabrieldornelas/clone-tabnews/blob/main/models/user.js"
    click Model_Session "https://github.com/gabrieldornelas/clone-tabnews/blob/main/models/session.js"
    click Model_Password "https://github.com/gabrieldornelas/clone-tabnews/blob/main/models/password.js"
    click Model_Auth "https://github.com/gabrieldornelas/clone-tabnews/blob/main/models/authentication.js"
    click Model_Migrator "https://github.com/gabrieldornelas/clone-tabnews/blob/main/models/migrator.js"
    click Migrate1 "https://github.com/gabrieldornelas/clone-tabnews/blob/main/infra/migrations/1740019112233_create-users.js"
    click Migrate2 "https://github.com/gabrieldornelas/clone-tabnews/blob/main/infra/migrations/1749156310798_create-sessions.js"
    click infraCompose "https://github.com/gabrieldornelas/clone-tabnews/blob/main/infra/compose.yaml"
    click WaitForPostgres "https://github.com/gabrieldornelas/clone-tabnews/blob/main/infra/scripts/wait-for-postgres.js"

    %% Styles
    classDef presentation fill:#AEDFF7,stroke:#333,stroke-width:1px
    classDef frontend fill:#B3E5FC,stroke:#333,stroke-width:1px
    classDef api fill:#81D4FA,stroke:#333,stroke-width:1px
    classDef application fill:#C6F5C6,stroke:#333,stroke-width:1px
    classDef infra fill:#E1E1E1,stroke:#333,stroke-width:1px
    classDef model fill:#A5D6A7,stroke:#333,stroke-width:1px
    classDef data fill:#F5D6A6,stroke:#333,stroke-width:1px
```
