IMPORTANT: THE FRONT END IS NOT MINE!1!! (IMPORTANT)
Everything that is in folder "frontend" is made from Valentin Asenov, a fellow candidate for the it organizator position. - https://github.com/alt-plus-f4/imgur
ONLY the script "server_request.js" and the templates in folder "src" are made from me to connect backend and frontend
This project is developed as part of the interview process for the Organizators' Team in HACKTUES 2023.
- The favicon logo is generated by DALL-E
- Node.js with TypeScript for building the CRUD REST API
- Prisma as the ORM (Object-Relational Mapping) tool
- PostgreSQL as the database
+-----------------+
| Account |
+-----------------+
+----- id |
| 1 | email |
| | userName |
| | displayName |
| | createdAt |
| | refreshToken |
| | permissionLevel |
| +-----------------+
| |
| |
| |
| +--------------+
| | Post |
| +--------------+
| | id ---------+ 1
| | title | |
| | imageUrl | |
| | state | |
| | createdAt | |
| N | tags | |
+----- senderId | |
| +--------------+ |
| | |
| | |
| | |
| +--------------+ |
| | Comment | |
| +--------------+ |
| | id ------+ |
| N | body | 1| |
+----- senderId | | |
| createdAt | ) |
| postId ---------+ N
+--------------+ (
| |
| |
| |
+--------------+ |
|CommentHistory| |
+--------------+ |
+-----id | |
| 1 | body | |
| | modifiedAt | N|
| | commentId ------+
| +--------------+
| |
| |
| |
| +--------------+
| | IpSeen |
| +--------------+
| | id |
| | ip |
| N | modifiedAt |
+---- commentId |
+--------------+
The project consists of the following main entities:
id
: Unique identifier for the accountemail
: Email associated with the account (unique)userName
: Username of the account (unique)displayName
: Display name of the accountpassword
: Password of the accountcreatedAt
: Timestamp of when the account was createdrefreshToken
: Refresh token associated with the account (optional and unique)ipsSeen
: List of IP addresses seen for the accountpermissionLevel
: Permission level of the accountposts
: Posts created by the accountcomments
: Comments made by the account
id
: Unique identifier for the posttitle
: Title of the postimageUrl
: URL of the image associated with the poststate
: State of the post (e.g., DELETED, PRIVATE, UNLISTED, PUBLIC)createdAt
: Timestamp of when the post was createdsender
: Account that created the posttags
: Tags associated with the postcomments
: Comments made on the post
id
: Unique identifier for the commentbody
: Body text of the commentcreatedAt
: Timestamp of when the comment was createdsender
: Account that made the commentonPost
: Post on which the comment was madecommentHistory
: History of modifications made to the comment
id
: Unique identifier for the comment history entrybody
: Body text of the comment at a specific point in timemodifiedAt
: Timestamp of when the comment was modifiedcomments
: Comment to which the history entry belongs
id
: Unique identifier for the IP seen entryip
: IP address that was seenaccount
: Account associated with the IP address
Before running the project, make sure you have the following:
- Node.js installed
- PostgreSQL database setup and accessible
- Clone the repository:
git clone <repository-url>
- Install dependencies:
cd <project-folder>
npm install
- Set up the .env and database:
- Create a
.env
file with your credentials.
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_SCHEMA=imgur
POSTGRES_USER=dummy_user
POSTGRES_PASSWORD=dummy_password
POSTGRES_DB=dummy_db
# JWT Configuration
JWT_EXPIRES_IN=20m
JWT_SECRET=<random_data>
RESET_TOKEN_SECRET=<random_data>
# Database URL
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${POSTGRES_DB}?schema=${DB_SCHEMA}&sslmode=prefer
# Email Configuration
EMAIL_FROM_USERNAME="no-reply@example.com"
EMAIL_FROM_PASSWORD="password123"
EMAIL_SMTP="smtp.example.com"
EMAIL_PORT=587
# Cookie Configuration
COOKIE_JWT_KEY="YourCookieKey"
The <random_data> should be a random string of at least 256 bytes (could use a crypto lirary for crypto.randomBits(512).toSting() or just some random text)
- Create a PostgreSQL database (could be a docker).
docker-compose --env-file .env up -d
- Run database migrations:
npx prisma migrate dev
- Start the application:
- Its on 2 different apis'
- For authentication
- For posts/coments
npm run devStart
npm run devStartAuth
- The two apis' should now be running at
http://localhost:3000
andhttp://localhost:4000
.