/newbie

Primary LanguageTypeScriptMIT LicenseMIT

πŸš€πŸ‘ΆπŸ» Newbie (Restful APIs Generator)

Project Description: Newbie generates an advanced production level Express backend using TypeScript based on an input YAML file that contains only the models. It automates the process of setting up the server, routing, and database integration, saving developers valuable time and effort.πŸ‘¨β€πŸ’»πŸ’»

Table of Contents πŸ“‘

Installation πŸ› οΈ

To use Newbie, follow these steps:

  1. Ensure that MongoDB is installed and running locally on your machine. πŸ“¦

  2. Clone the repository: πŸ‘―β€β™‚οΈ

  • git clone https://github.com/OmarElsahragty/newbie.git πŸ‘―β€β™€οΈ
  1. Install the dependencies:
  • cd newbie πŸ’Ώ
  • npm install or yarn

Models 🧠

To define the models for your backend, create a YAML file (newbie.example.yaml) in the root directory of the project. This file should contain the data models required for your application. The YAML file should be well-structured and case-sensitive for the field names but feel free with your own values that will be later on the attribute names for each model. Below is an example YAML file:

- users:
    auth:
      identifier: email
      password: password

    attributes:
      - name: first_name
        type: string
        required: true

      - name: last_name
        type: string
        required: true

      - name: email
        type: string
        unique: true
        required: true

      - name: password
        type: string
        required: true

      - name: bio
        type: string

- posts:
    attributes:
      - name: title
        type: string
        required: true

      - name: content
        type: string
        required: true

      - name: author_id
        type: user
        required: true

      - name: comments
        type: decimal
        array: true

        attributes:
          - name: writer_id
            type: user
            required: true

          - name: content
            type: string
            required: true

      - name: tags
        type: object
        array: true

        attributes:
          - name: name
            type: string
            required: true

      - name: likes
        type: user
        array: true

      - name: visibility
        type: string
        default: private
        enum: [public, private]

- messages:
    attributes:
      - name: sender_id
        type: user
        required: true

      - name: recipient_id
        type: user
        required: true

      - name: subject
        type: string
        required: true

      - name: body
        type: string
        required: true

      - name: read_at
        type: date

- notifications:
    attributes:
      - name: type
        type: string
        required: true

      - name: data
        type: string

      - name: read_at
        type: date

- friendships:
    attributes:
      - name: user_id
        type: user
        required: true

      - name: friend_id
        type: user
        required: true

      - name: status
        type: string
        default: pending
        enum: [pending, accepted, rejected]

      - name: initiated_by
        type: string
        default: user
        enum: [user, friend]

      - name: initiated_at
        type: date

      - name: accepted_at
        type: date

      - name: rejected_at
        type: date
  • Good Hint : Use auth field on any model like users in the previous example if auth field is existing don't forget defining the accessType: "ADMIN" in the register endpoint for the first super user to get the bearer token for accessing the rest of the backend.

Supported Types

  • string: Represents a string value. πŸ’¬
  • number: Represents a numeric value. πŸ”’
  • bigint: Represents a BigInt value. πŸ”’
  • boolean: Represents a boolean value (true or false). βœ…βŒ
  • date: Represents a date value. πŸ“…
  • undefined: Represents an undefined value. ❓
  • null: Represents a null value. 🚫
  • array: Represents an array of values. πŸ“š
  • object: Represents an object with specified properties. πŸ“
  • record: Represents an object with string keys and values of a specific type. πŸ“š
  • function: Represents a function. βš™οΈ
  • literal: Represents a literal value. πŸ“
  • enum: Represents a value from a predefined set of options. 🏷️
  • nativeEnum: Represents a value from a predefined set of options using TypeScript's enum type. 🏷️
  • promise: Represents a promise value. ⏳
  • lazy: Represents a lazily evaluated value. πŸ›‹οΈ
  • tuple: Represents a tuple with a fixed number of elements of different types. πŸ“¦
  • intersection: Represents the intersection of multiple types. βš“
  • union: Represents a value that can be one of several types. πŸ”€
  • optional: Represents an optional value. πŸ”„
  • nullable: Represents a value that can be either of a specified type or null. ⚠️
  • transformer: Represents a value transformed by a given transformation function. πŸ”„
  • instanceof: Represents a value that is an instance of a specific class. πŸ“¦
  • refinement: Represents a value that meets a specific refinement condition. βœ”οΈ
  • check: Represents a value that passes a custom validation check. βœ”οΈ

Usage

To generate the backend, run the following command:

  1. Define the destination path in the index file
  2. npm run generate πŸƒπŸ»

Database Integration

The backend integrates with MongoDB as the database. Make sure that MongoDB is running and accessible before starting the backend more databases will be supported in the future. πŸ“Š

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository. 🀝

License

This project is licensed under the MIT License. Feel free to modify and use it according to your needs. πŸ“ƒ

By following the instructions provided in this README, you will be able to generate an advanced production level Express backend using TypeScript in just seconds. If you have any questions or encounter any difficulties, please don't hesitate to reach out for support. Happy Automation! πŸ”₯πŸ”₯πŸ€–