"Brick That" is a Lego mosaic generator developed using Node.js and Express, with Handlebars as the templating engine. The application allows users to create accounts and generate mosaic artwork from images they upload, which is then stored on a server-side library managed by Sequelize ORM with a MySQL database. Users can log in and access their previously generated mosaics, making it a personalized experience for storing and retrieving their artwork.
A critical aspect of the application is the integration of ImageKit.io, an image processing and management service. This integration required setting up the public and private API keys for secure image uploads. The router responsible for handling uploads uses environment variables to securely access the private key and upload images. We implemented checks to ensure the privateKey is correctly initialized by referencing environment variables stored in a .env file. Once images are uploaded, the returned URL is saved in the Lego model to associate the image with a specific user. Troubleshooting this integration included resolving key-related issues and addressing Sequelize validation errors when saving data in the lego_url column, which stores the URL of the uploaded image.
The Lego model below represents the mosaics generated by users and uses Sequelize to define the schema and handle database interactions. This model contains the lego_url, which stores the URL of the uploaded mosaic image, and the user_id, which references the User model to link the artwork to a specific user. On the backend, routes are defined to handle image uploads and retrieval of saved mosaics. The POST route uploads the user's image using ImageKit and saves the URL in the database, while the GET route retrieves and returns the saved mosaics for the logged-in user.
The User model manages user accounts, including authentication through password hashing using bcrypt. The application ensures secure user data management by encrypting passwords before they are saved in the database. The model includes methods for password comparison during login, making the authentication process smooth and secure. Each user is associated with multiple mosaics, enabling them to store, retrieve, and manage their artwork over time.
Future Development
Future enhancements to "Brick That" could include expanding the mosaic customization options, such as adding control over the size and complexity of the generated mosaics. Additionally, features like user-generated content sharing or adding social interaction within the platform would increase engagement. The application could also benefit from improving performance monitoring and adding logging systems to track errors and user activity, ensuring smooth future scaling of the service.