Mini Twitter is a API REST for a small social media application built with Node.js, Express, Typescript, Prisma ORM and Jest.
- Features
- Deploy
- Getting Started
- Prerequisites
- Installation
- Configuration
- Usage
- Testing
- Contributing
- License
- User registration and authentication
- Following/unfollowing other users
- Posting tweets
- Posting static files on tweets
- Timeline to view tweets from followed users
- User profile management
The API and database for this project have been successfully deployed and are now live. You can access them using the following link:
https://mini-twitter-api.onrender.com
The integration between the API and the database allows seamless communication and data storage for the application. You can now interact with the API endpoints to perform various operations and utilize the functionality provided by the application.
Feel free to explore and make use of the deployed API and database. If you encounter any issues or have any feedback, please don't hesitate to reach out.
The API documentation can be accessed by visiting the following route:
The documentation provides detailed information about the available endpoints, request and response formats, authentication requirements, and example requests and responses. It serves as a valuable resource for understanding and utilizing the functionalities provided by the API.
A comprehensive database schema has been designed and implemented for this project. It provides a structured representation of the tables and relationships in the database.
To visualize the model of the database tables, refer to the following image:
The database schema illustrates the organization of entities, their attributes, and the associations between them. It serves as a reference for understanding the data structure and relationships within the application.
Please refer to the image above to gain a better understanding of the database structure and how the tables are interconnected.
To get a local copy up and running, follow these steps.
- Node.js (version ^16)
- PostgreSQL database
-
Clone the repository.
-
Install the dependencies by running the following command:
npm install
Configure the application by setting the following environment variables:
POSTGRES_USERNAME
: PostgreSQL database usernamePOSTGRES_PASSWORD
: PostgreSQL database passwordPOSTGRES_HOST
: PostgreSQL hostPOSTGRES_PORT
: PostgreSQL portPOSTGRES_DATABASE
: PostgreSQL database nameJWT_SECRET
: Secret key for JWT authenticationDATABASE_URL
: URL for connecting to the PostgreSQL databaseSTORAGE_TYPE
: Storage type for file uploads (e.g., "local" or "s3")AWS_BUCKET_NAME
: AWS S3 bucket nameAWS_ACCESS_KEY_ID
: AWS access key IDAWS_SECRET_ACCESS_KEY
: AWS secret access keyAWS_DEFAULT_REGION
: AWS region
- Clone this repository
- Install all dependencies
npm i
- Create a PostgreSQL database with whatever name you want
- Configure the
.env.development
file using the.env.example
file (see "Running application locally or inside docker section" for details) - Run all migrations
npm run dev:migration:run
- Seed db
npm run dev:seed
- Run the back-end in a development environment:
npm run dev
- Follow the steps in the last section
- Configure the
.env.test
file using the.env.example
file (see "Running application locally or inside docker" section for details) - Run all migrations
npm run migration:run
- Run test: (locally)
npm run test
npm run build
npm start
Before running migrations make sure you have a postgres db running based on .env.development
or .env.test
file for each environment. You can start a postgres instance by typing npm run dev:postgres
or npm run test:postgres
. The host name is the name of the postgres container inside docker-compose file if you are running the application inside a docker container or localhost if you are running it locally.
You can operate on databases for different environments, but it is necessary to populate correct env variables for each environment first, so in order to perform db operations type the following commands:
-
npm run dev:migration:run
- run migrations for development environment by loading envs from .env.development file. It uses dotenv-cli to load envs from .env.development file. -
npm run test:migration:run
- the same, but for test environment -
npm run dev:migration:generate -- --name ATOMIC_OPERATION_NAME
- generate and run migration and prisma client for development environment by loading envs from .env.development file. ReplaceATOMIC_OPERATION_NAME
by the name of the migration you want to generate.
There are several things you need to do when you add new ENV VARIABLES:
- Add them to
.env.example
file - Add them to your local
.env.development
and.env.test
files - Add them to your docker-compose.yml file (just the name, not the value). Only envs listed in the environment section will be exposed to your docker container.
- Add them (prod version) to your github repo secrets. They will be used to generate the
.env
file on deploy. - Add them (prod version) to test.yml file on .github/workflows/test.yml.
Contributions are welcome! If you have any improvements or bug fixes, feel free to submit a pull request. Additionally, I'm open to suggestions, ideas, or just having a conversation. Feel free to reach out to me through the following channels:
- Email: matheussvini@outlook.com
- LinkedIn: linkedin.com/in/mvsd
This project is licensed under the Mozilla Public License Version 2.0.