A secure diary application with AI-powered recommendations.
- Encrypted diary entries
- User authentication with Azure AD
- AI-powered recommendations based on diary entries
- Daily email digests with personalized insights
- Responsive design for desktop and mobile devices
- Light and dark theme support
Second Diary is a modern web application that allows users to:
- Securely log in using Microsoft Identity
- Create diary entries with thoughts and optional context
- View and manage personal diary entries
- Receive AI-generated insights based on journal content
- Experience a responsive UI that adapts to both desktop and mobile devices
- Automatically adjust to system light/dark theme preferences
- ASP.NET Core 9.0 API
- React with TypeScript
- Azure AD authentication
- Azure Cosmos DB
- Azure OpenAI Service
- Azure Communication Services
Create an appsettings.Development.json file based on the template with the following settings:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "your-domain.onmicrosoft.com",
"TenantId": "your-tenant-id",
"ClientId": "your-client-id",
"CallbackPath": "/signin-oidc",
"SignedOutCallbackPath": "/signout-callback-oidc"
},
"CosmosDb": {
"EndpointUrl": "your-cosmos-db-url",
"PrimaryKey": "your-primary-key",
"DatabaseName": "SecondDiary",
"ContainerName": "DiaryEntries"
},
"AzureOpenAI": {
"Endpoint": "https://your-resource-name.openai.azure.com/",
"ApiKey": "your-api-key",
"DeploymentName": "your-deployment-name",
"ModelName": "gpt-4",
"ApiVersion": "2023-12-01-preview"
},
"CommunicationService": {
"ConnectionString": "your-communication-service-connection-string",
"SenderEmail": "[email protected]",
"SenderName": "Second Diary Insights"
},
"FeatureFlags": {
"DiaryAnalysis": true,
"EmailNotifications": false
},
"AllowedHosts": "*",
"CORS": {
"AllowedOrigins": ["https://localhost:3000", "https://yourdomain.com"]
}
}GET /authentication/login- Initiate login processGET /authentication/logout- Logout current user
GET /api/diaries- Get all diary entries for the authenticated userGET /api/diaries/{id}- Get a specific diary entryPOST /api/diaries- Create a new diary entryPUT /api/diaries/{id}- Update an existing diary entryDELETE /api/diaries/{id}- Delete a diary entry
GET /api/insights- Get AI-generated insights based on recent entriesGET /api/insights/preferences- Get insight preferencesPUT /api/insights/preferences- Update insight preferences
GET /api/profile- Get current user's profilePUT /api/profile- Update profile settings
- .NET 9.0 SDK
- Node.js (v18 or higher)
- npm (v9 or higher)
- Visual Studio Code or Visual Studio 2022
-
Clone the repository
git clone https://github.com/yourusername/seconddiary.git cd seconddiary -
Configure appsettings.Development.json as shown in the Configuration section
-
Install frontend dependencies:
cd SecondDiary.API/ClientApp npm install -
Run the application:
cd SecondDiary.API dotnet run -
The application will be available at
https://localhost:7126
-
Create an App Registration in Azure:
- Navigate to the Azure Portal
- Go to "Azure Active Directory" > "App registrations" > "New registration"
- Enter a name for your application (e.g., "SecondDiary-Dev")
- For "Supported account types", select "Accounts in this organizational directory only"
- Set the Redirect URI: Select "Single-page application (SPA)"
- Enter
https://localhost:7126/authentication/login-callbackas the redirect URI - Click "Register"
-
Configure Authentication Settings:
- In your app registration, go to "Authentication"
- Add additional redirect URIs:
https://localhost:7126/https://localhost:7126/silent-refresh.html
- Ensure "Access tokens" and "ID tokens" are selected
- Save your changes
-
Copy the "Application (client) ID" and "Directory (tenant) ID" to your appsettings.Development.json
-
Create an Azure OpenAI resource:
- Navigate to the Azure portal and search for "Azure OpenAI"
- Click "Create" and complete the required fields
- Select an appropriate region and pricing tier
-
Create a model deployment:
- Navigate to Azure AI Studio (https://oai.azure.com/)
- Select your OpenAI resource
- Go to "Deployments" and click "Create new deployment"
- Choose a model (e.g., GPT-4, GPT-3.5-Turbo)
- Give your deployment a name (e.g., "diary-insights")
- Configure your model version and other parameters
-
Get your configuration details from the "Keys and Endpoint" section in your Azure OpenAI resource:
- Endpoint
- API Key
- Deployment Name
-
Create a Cosmos DB account:
- In the Azure Portal, search for "Cosmos DB"
- Click "Create" and select "Core (SQL)" API
- Configure account with appropriate settings
- Create a database named "SecondDiary"
- Create a container named "DiaryEntries" with partition key "/userId"
-
Get your connection string and primary key from the "Keys" section
-
Create a Communication Service resource:
- In the Azure portal, search for "Communication Services"
- Click "Create" and configure as needed
-
Set up email services:
- Configure a verified domain or use Azure managed domains
- Set up your sender email address
-
Get your connection string from the "Keys" section for use in your application
- Azure subscription
- Azure CLI installed
-
Create Azure resources:
az login az group create --name SecondDiaryResourceGroup --location eastus az appservice plan create --name SecondDiaryPlan --resource-group SecondDiaryResourceGroup --sku F1 az webapp create --name SecondDiary --resource-group SecondDiaryResourceGroup --plan SecondDiaryPlan --runtime "DOTNET|9.0" -
Configure app settings (replace with your actual values):
az webapp config appsettings set --name SecondDiary --resource-group SecondDiaryResourceGroup --settings "AzureAd:TenantId=your-tenant-id" "AzureAd:ClientId=your-client-id" "CosmosDb:EndpointUrl=your-cosmos-db-url" "CosmosDb:PrimaryKey=your-primary-key" -
Publish the application:
dotnet publish SecondDiary.Service/SecondDiary.Service.csproj -c Release -o ./publish az webapp deployment source config-zip --name SecondDiary --resource-group SecondDiaryResourceGroup --src ./publish.zip
- Authentication Issues: Verify your Azure AD configuration and redirect URLs
- Database Connection: Check your Cosmos DB connection string and permissions
- AI Integration: Ensure your Azure OpenAI API keys and deployment names are correct
- Email Notifications: Verify your Communication Services connection string and sender email