This is a simple web application allows registered children to send messages to Santa. I made this to match the specifications, and make it simple no overengineering.
- Project Overview
- Prerequisites & Dependencies
- Installation & Usage
- Architecture
- BackEnd
- API Endpoints
- FrontEnd
- Configuration
- Testing
- Deployment
- Future Improvements
This Santa Letter Application is a web-based system that allows registered children to send messages to Santa Claus. It includes features for submitting request, validate child, and sending emails with simple queue.
- Child request submission
- Age and registration validation
- Periodic email sending for pending message requests
- RESTful API for request management
- Node.js (v16 or later)
- npm (v8 or later)
- Modern browser (Chrome, chromium, firefox)
- Ethereal email https://ethereal.email/, username password given in the
.env.example
dotenv
: For loading environment variablesexpress
: Web application frameworkmorgan
: HTTP request logger middlewarehttp
: Node.js HTTP modulepath
: Node.js path moduleuuid
: to Generate unique identifiersconcurrently
: Runs multiple commands concurrently.jest
: JavaScript testing framework.nodemon
: Monitors for changes and automatically restarts the server.
@hookform/resolvers
: Provides validation resolvers for react-hook-form.@reduxjs/toolkit
: A set of tools to simplify Redux development.react
andreact-dom
: Core React libraries.react-hook-form
: Library for managing form state in React.react-redux
: Official React bindings for Redux.yup
: JavaScript schema builder for value parsing and validation.@testing-library/jest-dom
and@testing-library/react
: Testing utilities for React.@types/*
packages: TypeScript type definitions for various libraries.@vitejs/plugin-react
: Vite plugin for React projects.jest
: JavaScript testing framework.jsdom
: JavaScript implementation of web standards for use with Node.js.typescript
: Adds static typing to JavaScript.vite
: Build tool and development server.vitest
: Vite-native unit test framework.
- nodemailer: to send the email
- jest: testing module
- uuid: generate uid for the message sent to santa
and updates all the package version
-
Login to glitch: make sure you are logged in to glitch.com
-
Clone: Go to this URL: https://glitch.com/~js-santa-app and click the
Remix your own
button to clone the code. This will copy all the code to a new, randomly generated URL (e.g. https://glitch.com/edit/#!/capable-toothpaste). -
Code: You can edit the code directly in the Glitch editor or use your editor of choice (VSCode, Sublime, etc) and copy paste the files into Glitch. Git import and export is also available in the Tools menu on the bottom left. How you edit the code is entirely up to you, so long as your finished work is viewable at the URL created in the previous step.
NOTE: Click
Show
in the header to see your app live. Updates to your code will instantly deploy and update live.
- Clone the repository:
git clone git@github.com:icanq/santa-apps.git
- Install dependencies
npm install
- create
.env
you can paste from the.env.example
Start both client and server
npm run start
Server only
npm run start:server
Client only
npm run start:client
Build the client:
npm run build
Since server written using JS we don't need to build it.
Run tests with
server test
npm run test:server
client test
npm run
Generate coverage
npm run test:coverage
To simply access the coverage we can see in
https://candied-gray-marble.glitch.me/coverage/
This app follows a client and server architecture:
- BackEnd: Node.js with Express.js; written in JS
- FrontEnd: React with Typescript; Build with Vite
- Database: In memory storage (only for demo)
- Test: Backend (Jest); Frontend (Jest + Vitest)
The main server file set up the Express application, configure middlewares, and define API routes. And handle email sending in pending requests, and using proxy for development.
This service manages the core business logic to:
- Validating the incoming requests
- Add new requests
- Retrieve the pending requests
This controller manage HTTP Requests and responses for the related santa operations:
- Submit request
- Get Pending request
This manage sending email functionality using nodemailer
:
- Send periodic email from the pending requests
- Configurable SMTP settings
GET /api/health
: To check if the server health (run check)GET /api/santa/pending
: Retrieve all pending requests to santaPOST /api/santa/request
: Send Message to santa
This implements basic react setup with ReduxToolkit for state management and displaying responses or errors in the app
A form component for submitting requests to Santa, including input validation and character count using rtk and react-hooks-form
- store configuration:
client/src/config/redux/store/index.ts
- root reducer:
client/src/config/redux/store/rootReducer.ts
- santa slice:
client/src/config/redux/slices/santaSlice.ts
As the application grows we can modify the santa slice, or creating new slice for new features.
Defines API endpoints using RTK-Query for interacting with backend (client/src/services/santaApi.ts
); as the app grows we can create new api service in this folder
- Environment variables are defined in
.env.example
- Vite configuration:
vite.config.ts
- TypeScript configuration:
tsconfig.json
andtsconfig.node.json
- Test configuration:
jest.config.js
andvitest.config.ts
Controller tests: server/__tests__/santa.controller.test.js
Service tests: server/__tests__/santa.service.test.js
Route tests: server/__tests__/santa.routes.test.js
App component test: client/__tests__/App.test.tsx
SantaForm component test: client/src/components/SantaForm/SantaForm.test.tsx
Footer component test: client/src/components/Footer/Footer.test.tsx
In this project it only setup for coverage in server
, to run the coverage we can use
npm run test:coverage
This app is already compatible withglitch.com
. to deploy just follow simple steps:
-
Login to glitch: make sure you are logged in to glitch.com
-
Clone: Go to this URL: https://glitch.com/~sphenoid-coral-coelurus and click the
Remix your own
button to clone the code. This will copy all the code to a new, randomly generated URL (e.g. https://glitch.com/edit/#!/capable-toothpaste).
- Implement persistent storage (e.g., database) for requests
- Add user authentication for enhanced security
- Improve frontend UI/UX with more interactive features
- Implement rate limiting to prevent abuse
- Add more comprehensive error handling and logging
- Enhance email templates for better readability
- Implement continuous integration and deployment (CI/CD) pipeline (idk how to do this in glitch)
The client and server are running parallel using concurrently
. somehow, everytime glitch run it will choose the first port that run. And this will make the hot reload in vite not working correctly, but it's working fine in local environment, idk how to fix this since the time is very limited.
i notice that user bugs.bunny
birthdate format is different, i turn it into YYYY/mm/dd format.