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.π¨βπ»π»
- Installation π οΈ
- Usage βοΈ
- Models π§
- Supported Types π’π€
- Database Integration π
- Contributing π€
- License π
To use Newbie, follow these steps:
-
Ensure that MongoDB is installed and running locally on your machine. π¦
-
Clone the repository: π―ββοΈ
git clone https://github.com/OmarElsahragty/newbie.git π―ββοΈ
- Install the dependencies:
- cd newbie πΏ
- npm install or yarn
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.
- 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. βοΈ
To generate the backend, run the following command:
- Define the destination path in the index file
npm run generate ππ»
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. π
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. π€
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! π₯π₯π€