# angelac123/twitter-api-2020 architecture

> Architecture diagram of the GitHub repository angelac123/twitter-api-2020, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/angelac123/twitter-api-2020
- Repository: https://github.com/angelac123/twitter-api-2020

## Overview

##### Project type and purpose
- This is a Node.js/Express “backend-only” Web API implementing a mini-Twitter clone.
- It exposes REST endpoints for tweets, replies, likes, followships, user-profile management, and an admin interface.
- It uses Sequelize + MySQL for persistence, Passport for authentication (JWT + Local), Multer for file-upload, Imgur for media storage, and includes migrations, seeders, and automated tests.

##### File structure
- Top-level:
- app.js – entry point, sets up Express, middleware, routes
- config/ – database credentials (config.json), Passport strategies
- controllers/ – MVC “C”—admin-controller.js, tweet-controller.js, user-controller.js
- routes/ – Express routers organized by module
- models/ – Sequelize models + index.js wiring models to DB
- migrations/ & seeders/ – Sequelize CLI DB schema + initial data
- middleware/ – auth (Passport JWT), multer (file upload), error handler
- helpers/ – file-helpers, general utility functions
- test/ – Mocha/Chai unit & request specs
- Patterns: classic MVC + layered service → controller → model. DB migrations/seeders separate.

##### README for insights
- Features outline domain entities (User, Tweet, Reply, Like, Followship) and interactions.
- Tech stack: Node.js, Express, MySQL2, Sequelize, Passport, JWT, Multer, Imgur, Mocha/Chai.

##### Essential details to capture
- Authentication flows: login via Local → JWT issue → subsequent requests use JWT middleware
- File-upload flow: client sends image → Multer handles local upload → helper uploads to Imgur → store Imgur link in DB
- Database schema relationships:
- User 1–* Tweet
- Tweet 1–* Reply
- User *–* Tweet through Like
- User *–* User through Followship

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Client["Web/Mobile Client"]:::external -->|"HTTPS"| API_Init

    %% API Server Initialization
    subgraph "API Server"
        direction TB
        API_Init["app.js"]:::api
        subgraph "Configuration"
            direction TB
            DB_Config["config/config.json"]:::api
            Passport_Strategies["config/passport.js"]:::api
        end
        subgraph "Middleware Layer"
            direction TB
            Auth_MW["auth.js (JWT Middleware)"]:::api
            Upload_MW["multer.js (Upload Middleware)"]:::api
            Error_MW["error-handler.js"]:::api
        end
        subgraph "Controllers"
            direction TB
            Admin_Ctrl["AdminController"]:::controller
            Tweet_Ctrl["TweetController"]:::controller
            User_Ctrl["UserController"]:::controller
        end
        subgraph "Helpers / Services"
            direction TB
            File_Help["file-helpers.js"]:::helper
            Dummy_User["dummyUser.js"]:::helper
            Gen_Help["_helpers.js"]:::helper
        end
        subgraph "ORM & Models"
            direction TB
            Model_Index["models/index.js"]:::model
            User_Model["user.js"]:::model
            Tweet_Model["tweet.js"]:::model
            Reply_Model["reply.js"]:::model
            Like_Model["like.js"]:::model
            Followship_Model["followship.js"]:::model
        end
        subgraph "Migrations & Seeders"
            direction TB
            M1["migrations/20190115071421-create-user.js"]:::migration
            M2["migrations/20190115071420-create-tweet.js"]:::migration
            M3["migrations/20190115071420-create-reply.js"]:::migration
            M4["migrations/20190115071419-create-like.js"]:::migration
            M5["migrations/20190115071418-create-followship.js"]:::migration
            S1["seeders/20220511085003-users-seed-file.js"]:::migration
            S2["seeders/20220511090116-tweets-seed-file.js"]:::migration
            S3["seeders/20220511090129-replies-seed-file.js"]:::migration
        end
    end

    %% External Services
    Imgur(("Imgur API")):::external

    %% Database
    MySQL[(MySQL DB)]:::database

    %% Flow Connections
    API_Init --> DB_Config
    API_Init --> Passport_Strategies
    API_Init --> Auth_MW
    API_Init --> Upload_MW
    API_Init --> Error_MW
    Auth_MW --> Admin_Ctrl
    Auth_MW --> Tweet_Ctrl
    Auth_MW --> User_Ctrl
    Upload_MW --> File_Help
    Admin_Ctrl --> File_Help
    Tweet_Ctrl --> File_Help
    User_Ctrl --> File_Help
    Admin_Ctrl -->|CRUD| Model_Index
    Tweet_Ctrl -->|CRUD| Model_Index
    User_Ctrl -->|CRUD| Model_Index
    Model_Index --> User_Model
    Model_Index --> Tweet_Model
    Model_Index --> Reply_Model
    Model_Index --> Like_Model
    Model_Index --> Followship_Model
    User_Model --> MySQL
    Tweet_Model --> MySQL
    Reply_Model --> MySQL
    Like_Model --> MySQL
    Followship_Model --> MySQL
    File_Help -->|upload| Imgur
    Imgur -->|response URL| File_Help

    %% Click Events
    click API_Init "https://github.com/angelac123/twitter-api-2020/blob/master/app.js"
    click DB_Config "https://github.com/angelac123/twitter-api-2020/blob/master/config/config.json"
    click Passport_Strategies "https://github.com/angelac123/twitter-api-2020/blob/master/config/passport.js"
    click Auth_MW "https://github.com/angelac123/twitter-api-2020/blob/master/middleware/auth.js"
    click Upload_MW "https://github.com/angelac123/twitter-api-2020/blob/master/middleware/multer.js"
    click Error_MW "https://github.com/angelac123/twitter-api-2020/blob/master/middleware/error-handler.js"
    click Admin_Ctrl "https://github.com/angelac123/twitter-api-2020/blob/master/controllers/admin-controller.js"
    click Tweet_Ctrl "https://github.com/angelac123/twitter-api-2020/blob/master/controllers/tweet-controller.js"
    click User_Ctrl "https://github.com/angelac123/twitter-api-2020/blob/master/controllers/user-controller.js"
    click File_Help "https://github.com/angelac123/twitter-api-2020/blob/master/helpers/file-helpers.js"
    click Dummy_User "https://github.com/angelac123/twitter-api-2020/blob/master/helpers/dummyUser.js"
    click Gen_Help "https://github.com/angelac123/twitter-api-2020/blob/master/helpers/_helpers.js"
    click Model_Index "https://github.com/angelac123/twitter-api-2020/blob/master/models/index.js"
    click User_Model "https://github.com/angelac123/twitter-api-2020/blob/master/models/user.js"
    click Tweet_Model "https://github.com/angelac123/twitter-api-2020/blob/master/models/tweet.js"
    click Reply_Model "https://github.com/angelac123/twitter-api-2020/blob/master/models/reply.js"
    click Like_Model "https://github.com/angelac123/twitter-api-2020/blob/master/models/like.js"
    click Followship_Model "https://github.com/angelac123/twitter-api-2020/blob/master/models/followship.js"
    click M1 "https://github.com/angelac123/twitter-api-2020/blob/master/migrations/20190115071421-create-user.js"
    click M2 "https://github.com/angelac123/twitter-api-2020/blob/master/migrations/20190115071420-create-tweet.js"
    click M3 "https://github.com/angelac123/twitter-api-2020/blob/master/migrations/20190115071420-create-reply.js"
    click M4 "https://github.com/angelac123/twitter-api-2020/blob/master/migrations/20190115071419-create-like.js"
    click M5 "https://github.com/angelac123/twitter-api-2020/blob/master/migrations/20190115071418-create-followship.js"
    click S1 "https://github.com/angelac123/twitter-api-2020/blob/master/seeders/20220511085003-users-seed-file.js"
    click S2 "https://github.com/angelac123/twitter-api-2020/blob/master/seeders/20220511090116-tweets-seed-file.js"
    click S3 "https://github.com/angelac123/twitter-api-2020/blob/master/seeders/20220511090129-replies-seed-file.js"

    %% Styles
    classDef external fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef api fill:#90EE90,stroke:#000,stroke-width:1px
    classDef controller fill:#FFA500,stroke:#000,stroke-width:1px
    classDef helper fill:#FFD700,stroke:#000,stroke-width:1px
    classDef model fill:#FFFF99,stroke:#000,stroke-width:1px
    classDef database fill:#FFE4B5,stroke:#000,stroke-width:1px,shape:cylinder
    classDef migration fill:#D3D3D3,stroke:#000,stroke-width:1px
```
