A service that enables a user to register with a name and email address then confirm their email address.
This is a simple web application that makes the sending of account confirmation email easier. A user registers with their name and email address. They then have to click on the link sent to their email address to activate their account.
To use it, you need an email provider such as Google or Amazon SES. Then:
- Register for an account using the auth/register route (provide a username and email address)
- Send a confirmation email using the send email route (provide your user id and email)
- Confirm your email address (paste the activation token through the confirm route or click on the link in your email).
- Your account is then activated.
This application has several features including:
- Deployed to an AWS EBS.
- Versioned using git and Hosted on GitHub.
- Auto-deployed to AWS EBS using Github actions.
- Uses gunicorn as the application servers.
- Uses an Application Load Balancer to redirect traffic to the frontend
- Uses AWS SES to send confirmation emails.
Here is how to set up the application locally:
-
Clone the application repo:
git clone https://github.com/twyle/email-service.git
-
Navigate into the cloned repo:
cd email-service
-
Create a Virtual environment:
python3 -m venv venv
-
Activate the virtual environmnet:
source venv/bin/activate
-
Install the project dependancies:
pip install --upgrade pip # update the package manager pip install -r requirements.txt
-
Create the environment variables for each service:
touch .env
Then paste the following into the file:
FLASK_APP=manage.py FLASK_DEBUG=True FLASK_ENV=development POSTGRES_HOST=db POSTGRES_DB=email-service POSTGRES_PORT=5432 POSTGRES_USER=postgres POSTGRES_PASSWORD=lyle MAIL_USERNAME=<mail-username> MAIL_PASSWORD=<mail-password> MAIL_SERVER=<mail-server> MAIL_PORT=465 MAIL_USE_SSL=True CELERY_RESULT_BACKEND=redis://redis:6379/0 CELERY_BROKER_URL=redis://redis:6379/0 SERVER_NAME=localhost:5000 PREFERRED_URL_SCHEME=http
Then create the database secrets:
cd database touch .env
Then paste the following into the file:
POSTGRES_HOST=localhost POSTGRES_USER=lyle POSTGRES_PASSWORD=lyle POSTGRES_DB=email-service
-
Start the services:
docker-compose -f docker-compose-dev.yml up --build
-
Create the database:
docker-compose -f docker-compose-dev.yml exec email-service python manage.py create_db
-
View the running application
Head over to http://0.0.0.0:5000/apidocs
-
Services
The application consists of one service that send account activation emails to users:
- Email Service
This service is resposible for sending account activation emails. The routes include:
Route Method Description 'api/v1/email/send' POST Send confirmation email. 'api/v1/auth/confirm' GET Activate account. 'api/v1/auth/register' POST Register for a ccount. - Register as a new user with a unique email address and password as well as name.(Generates a uniques token)
- Proceed to your email address and click on the link given within 24 hours to activate your account. (marks account as activated)
- Log into your account using your email and password. (You get a unique token for authorization)
This service uses the Postgres Database to store the user info. It uses AWS SES to send emails using celery.
-
Coding standards
The application had to adhere to the following coding standards:
- Variable names
- Function names
- Test driven development
- Individual modules need 60% coverage and an overall coverage of 60%.
- CI/CD pipeline has to pass before deployments.
- Commit messages format has to be adhered to.
- Only push code to github using development branches.
- Releases have to be tagged.
- Use pre-commit to run code quality checks
- Use comitizen to format commit messages
-
Application development process management
The project uses GitHub Projects for management.
The application uses atleast 5 branches:
- Features branch used to develop new features.
- Development branch used to hold the most upto date features that are yet to be deployed.
- Staging branch holds the code that is currently being tested for production.
- The release branch holds all the assets used when creating a release.
- The production branch holds the code for the currently deployed application.
The development workflow follows the following steps:
- A feature branch is created for the development of a new feature.
- The code is then pushed to GitHub, triggering the feature-development-workflow.yml workflow. If all the tests pass, the feature is reviewde and merged into the development branch.
- The code in the development branch is then deployed to the development environment. If the deployment is succesful, the development branch is merged into the staging branch.
- This triggers the staging workflow. If all the tests are succesful, this branch is reviewed and deployed to a staging environment.
- For creatinga release, the staging branch is merged into the release branch. This happens when a tag is pushed to GitHub.
- Once a release is created, the release branch is merged into the production branch, which is deployed into production.
The workflows require a couple of secrets to work:
```sh
FLASK_APP=manage.py
FLASK_DEBUG=True
FLASK_ENV=development
POSTGRES_HOST=db
POSTGRES_DB=email-service
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=lyle
MAIL_USERNAME=<mail-username>
MAIL_PASSWORD=<mail-password>
MAIL_SERVER=<mail-server>
MAIL_PORT=465
MAIL_USE_SSL=True
CELERY_RESULT_BACKEND=redis://redis:6379/0
CELERY_BROKER_URL=redis://redis:6379/0
SERVER_NAME=localhost:5000
PREFERRED_URL_SCHEME=http
```
The workflows also require the followingenvironments to work:
- Test
- Staging
- Development
- Production
And within each environment, create a secret that indicates the environment type i.e
- Test ->
FLASK_ENV=test
- Staging ->
FLASK_ENV=stage
- Development ->
FLASK_ENV=development
- Production ->
FLASK_ENV=production
- Fork it https://github.com/twyle/email-service/fork
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
Lyle Okoth – @lylethedesigner on twitter
lyle okoth on medium
My email is [email protected]
Here is my GitHub Profile
You can also find me on LinkedIN
Distributed under the MIT license. See LICENSE
for more information.