# Ideamarket Account System : Technical Overview An in-depth technical overview of the backend infrasture of the Ideamask Account System and the communicational relationship between it's various functional components. # Key Features - Allows users to login using an SSO like google's, or directly signing up with a gmail and password - Allows for seamless syncing of preferences such as dark/light mode, watchlist and additional features like profile pictures - Scalable and cost effective infrastructure, without compromising on security. # Login Flow for a New User ![](https://i.imgur.com/xN8Eqee.jpg) - User submitted login form data/callback data from an SSO is collected by the Idea Market Front-End (website). - OAuth flow is commenced by the Front-End, sending OAuth Register credentials via an Http POST request. - An AWS Lambda function responds with an object contaning 3 parameters - - Access Token - Refresh Token - Access token expiry timeframe - Ideamarket Front-End submits user data to an API endpoint in the AWS API Gateway, with a Bearer authorisation header who's value is the access token prepended by "Bearer" - A Lambda function authenticates user data, sends objects such as images to AWS S3, and the rest to the FaunaDB databbase. # Login Flow for an Existing User ![](https://i.imgur.com/omheWl6.jpg) - User submitted login form data is collected by the Idea Market Front-End (website). - OAuth flow is commenced by the Front-End, sending OAuth Register credentials via an Http POST request. - An AWS Lambda function responds with an object contaning 3 parameters - - Access Token - Refresh Token - Access token expiry timeframe - deamarket Front-End submits user data to an API endpoint in the AWS API Gateway, with a Bearer authorisation header who’s value is the access token prepended by “Bearer” - A Lambda function responds with an object and status code in the following conditions - - Correct Credentials: Status Code: 200 | {"status":"Credentials Authorized"} - Invalid Credentials: Status Code: 404 | {"status":"Invalid Credentials"} - Idemarket Front-End renders the user's info # Services and Libraries - Authentication in front end using `next-auth` - Since the Idea Market front-end is built using next.js, `next-auth` is a great library that handles OAuth for you. - Documentation: https://next-auth.js.org/getting-started/introduction - `AWS API Gateway` to handle incomming Http requests, which then trigger an `AWS Lambda Function` - The `AWS API Gateway` can be used to recieve and authenticate incomming Http requests. This service makes handling API calls faster, cheaper and simpler in a serverless interface. - AWS Lambda is a serverless compute service that eliminates need for self hosted servers. AWS Lambda functions can be set to trigger on certain Http requests recieved by the API Gateway, thereby making the backend infrastructure serverless, improving efficiency and reducing costs. AWS Lambda is an industry leader in Functions as a Service (FaaS). - Note: Lambda Functions to be writted ONLY in Typescript/Javascript. An exceptions can be made ONLY if significant improvments can be achieved with another language. - Documentation: Getting Started with API Gateway and Lambda Functions: https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html - In-depth docs for AWS Lambda: https://docs.aws.amazon.com/lambda/latest/dg/welcome.html - Database: `FaunaDB` - FaunaDB has a significant edge over competetors like google's Firebase Realtime Database and AWS's DynamoDB. FaunaDB offers very reasonable pricing and has Graphql and Fauna Query Language (FQL) built in, allowing for efficient and fast querying of data, which google's firebase dosen't natively support. Fauna requires zero maintainance and scales to support any amounts of data. It's hasslefree and flexible to use, unlike AWS's DynamoDB. - Documentation: https://docs.fauna.com/fauna/current/drivers/javascript - Object Storage (Images - Profile Pictures): AWS S3 - While images can be saved to a database it is not ideal to do so. it's generally a good idea to use an object storage system like S3. Storing large objects like images on a database like FaunaDB is expensive, S3 allows for cost-effective unstructured data storage. Amazon clamis S3 has an uptime of 99.9%, which is nice to have. - Get started with S3: https://docs.aws.amazon.com/AmazonS3/latest/userguide/GetStartedWithS3.html - Email delivery service: Sendgrid - An email delivery service helps send bulk emails to all subscribed users (Eg- Newsletters, Trasaction Notifications, etc) and email verification. Sendgrid is an industry leader in providing this service outperforming it's competetors by a substantial margin, with a free plan which includes 100 emails/day - Sendgrid API referrence: https://sendgrid.com/docs/for-developers/sending-email/api-getting-started/ ## Estimated Cost `Estimated costs are approximated assuming the following metrics:` - 50k total users - 10k active users/month - 5 Logins per user/month - `Next Auth:` Free - `AWS API Gateway:` 1M free calls for the first year, $0.125/month ($1/1M requests) - `AWS Lambda:` Free for the first year, $1.5/month thereafter. - `FaunaDB:` $25/month - `AWS S3:` $15/month - `SendGrid:` 100 emails/day free #### `Total operational cost: $41.625/month, $500/year`