A Next.js application for managing constituent contact information for elected officials.
- Prerequisites
- Setup Instructions
- Getting Started
- Database Details
- Learn More
- Decisions I Made
- What’s Next
Before setting up and running the project, ensure you have the following installed:
-
Docker
- Install Docker: Get Started with Docker
- Confirm installation by running:
docker --version
-
Node.js
-
MySQL Client (Optional)
- Install a MySQL client for database interaction:
- GUI tools like MySQL Workbench.
- Or use the command-line MySQL client.
- Install a MySQL client for database interaction:
git clone https://github.com/your-username/constituent-manager.git
cd constituent-managerdocker run --name constituent-manager \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_DATABASE=constituents_db \
-p 3306:3306 \
-d mysql:latestAdd the following environment variables in a .env.local file at the root of the project:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=password
DB_NAME=constituents_dbConnect to the MySQL Docker container and create the table.
docker exec -it constituent-manager mysql -u root -pUSE constituents_db;CREATE TABLE constituents (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
street_address VARCHAR(255),
city VARCHAR(100),
state VARCHAR(100),
zip_code VARCHAR(10),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Install dependencies and run the development server:
npm i
npm run devThen open http://localhost:3000 in your browser to view the app.
You can start editing the app by modifying files in the app/ directory. The page auto-updates as you edit.
Here’s an example query to populate the database with sample data:
INSERT INTO constituents (first_name, last_name, email, street_address, city, state, zip_code, created_at)
VALUES
('John', 'Doe', '[email protected]', '123 Main St', 'Springfield', 'IL', '62704', '2022-03-15 10:30:00'),
('Jane', 'Smith', '[email protected]', '456 Elm St', 'Madison', 'WI', '53703', '2023-05-20 15:45:00');GET /api/constituents: Gets a list of constituent data sorted by most recently added.POST /api/constituents/add: Adds or updates constituent data.GET /api/constituents/export?startDate=YYYY-MM-DD&endDate=YYYY-MM-DD: Exports constituent data as a CSV file, filtered by date.
To learn more about Next.js, check out the following resources:
- Next.js Documentation – Explore features and APIs.
- Learn Next.js – Interactive Next.js tutorial.
Here are some of the key decisions I made while developing this project:
-
Next.js as the Framework:
- I chose Next.js because it comes out of the box with server-side rendering (SSR) and API routes, and because I'm familiar with it.
-
Database Choice: MySQL:
- MySQL was selected for its familiarity, performance, and compatibility with Docker.
-
Dockerized Database:
- Running the database in a Docker container ensures consistency across development environments.
-
Tailwind:
- I chose this for it's quick and easy styling.
If I had more time, I would focus on the following improvements:
-
Testing:
- Add unit and integration tests to ensure stability and prevent regressions.
-
Styling and Responsiveness:
- Clean up the styles and make the application fully responsive.
- Fix issues with the export modal and datepickers. I attempted to use a Tailwind plugin called Flowbite but struggled with some of its implementation. Further time spent on this would improve the UI.
-
Pagination:
- Implement pagination for the constituent list to handle larger datasets more efficiently.
-
CSV Date Formatting:
- Enhance the exported CSV by formatting dates for better readability.
-
Split Frontend and Backend:
- While I used Next.js API routes for simplicity, splitting the frontend and backend could help with scaling. For the backend, I would consider using NestJS, which pairs well with a Next.js frontend.
-
Improved Success/Error Handling:
- Enhance the user interface to provide better feedback for success and error states.
-
Validation:
- Add thorough frontend and backend validation for all input fields to ensure data integrity and improve user experience.
-
Extra credit
- I'd add more of the extra credit capabilities - search, sort, filter, upload CSV, auth, etc.