A concept-driven backend API server built with Deno and Hono, implementing a modular architecture for a flashcard and note-taking application for different Torah topics.
TorahCards is a backend system designed around the concept design methodology from MIT 6.104. The application provides a RESTful API for managing flashcards, notes, user authentication, following relationships, through independently implemented "concepts."
- FlashCards: Create and manage flashcard sets with questions and answers
- Notes: Create, organize, and search personal notes
- UserAuth: User authentication and session management
- Following: Social following relationships between users
- Labeling: Tag and categorize content (backend ready)
- π Full-text search for flashcards and notes
- π₯ User authentication with session management
- π Content following system
- ποΈ MongoDB integration for data persistence
- π€ AI-powered features via Google Gemini API
- π Auto-discovered concept routing
- Runtime: Deno 2.x
- Web Framework: Hono
- Database: MongoDB Atlas
- AI Integration: Google Gemini API
- Testing: Deno's built-in test framework
- Design Tool: Context tool (custom Markdown-based LLM collaboration)
- Deno installed (v2.0 or higher)
- MongoDB Atlas account (free tier available)
- Google Gemini API key (optional, for AI features)
git clone https://github.com/bzgrey/TorahCards.git
cd TorahCards-backendCreate a .env file in the root directory:
# Gemini API Configuration (optional)
GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-2.5-flash
# MongoDB Configuration
MONGODB_URL=mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority
DB_NAME=torahcards- Create a MongoDB Atlas account
- Create a free M0 cluster
- Configure network access to allow all IPs (0.0.0.0/0)
- Create a database user with read/write permissions
- Get your connection string and add it to
.env
For design documentation and LLM collaboration:
deno compile -A --output ctx .ctx/context.tsdeno task conceptsThe server will start on http://localhost:8000 by default.
The API follows a consistent pattern: POST /api/{ConceptName}/{actionName}
POST /api/FlashCards/addFlashcards- Create a new flashcard setPOST /api/FlashCards/addCard- Add a card to an existing setPOST /api/FlashCards/getUserCards- Get all flashcard sets for a userPOST /api/FlashCards/searchFlashcards- Search flashcards by name
POST /api/Notes/addNote- Create a new notePOST /api/Notes/editNote- Edit an existing notePOST /api/Notes/deleteNote- Delete a notePOST /api/Notes/searchNotes- Search notes by content
POST /api/UserAuth/register- Register a new userPOST /api/UserAuth/login- Authenticate a userPOST /api/UserAuth/logout- End a user session
POST /api/Following/follow- Follow another userPOST /api/Following/unfollow- Unfollow a userPOST /api/Following/getFollowers- Get list of followersPOST /api/Following/getFollowing- Get list of users being followed
All endpoints accept and return JSON. Request bodies vary by endpoint but typically include relevant concept parameters.
Example Request:
POST /api/FlashCards/addFlashcards
{
"user": "user123",
"name": "Hebrew Vocabulary",
"cards": [
{ "question": "Χ©ΧΧΧ", "answer": "Peace/Hello" },
{ "question": "ΧͺΧΧΧ", "answer": "Thank you" }
]
}Run all tests:
deno test -ARun a specific test file:
deno test -A src/concepts/FlashCards/FlashCardsConcept.test.tsTests use Deno's built-in testing framework and automatically set up/tear down test databases.
TorahCards-backend/
βββ src/
β βββ concept_server.ts # Main server with auto-discovery
β βββ concepts/ # Concept implementations
β β βββ FlashCards/
β β β βββ FlashCardsConcept.ts
β β β βββ FlashCardsConcept.test.ts
β β βββ Notes/
β β βββ UserAuth/
β β βββ Following/
β β βββ Labeling/
β βββ utils/
β βββ database.ts # MongoDB connection
β βββ gemini-llm.ts # AI integration
β βββ types.ts # Shared type definitions
βββ design/ # Concept specifications
β βββ background/ # Design methodology docs
β βββ concepts/ # Individual concept specs
β βββ learning/ # Design decisions log
βββ context/ # Design history (immutable)
βββ deno.json # Deno configuration
βββ geminiConfig.json # AI model configuration
βββ .env # Environment variables
This project uses the Context framework for concept-driven design:
- Each concept is independently specified, implemented, and tested
- Design documentation lives alongside code in the
design/directory - The
context/directory maintains an immutable history of design decisions - LLM collaboration is integrated through the Context CLI tool
- Create a specification in
design/concepts/{ConceptName}/ - Implement in
src/concepts/{ConceptName}/{ConceptName}Concept.ts - Export the class as default
- Add tests in
{ConceptName}Concept.test.ts - The server will auto-discover and route your concept!
Example Concept Class:
export default class MyConceptConcept {
constructor(private db: Db) {}
async myAction(params: { /* ... */ }) {
// Implementation
return { success: true };
}
}Customize server behavior via command-line flags:
deno run --allow-net --allow-read --allow-sys --allow-env src/concept_server.ts \
--port 3000 \
--baseUrl /api/v1Edit geminiConfig.json to adjust AI behavior:
{
"temperature": 0.7,
"topK": 40,
"topP": 0.95,
"maxOutputTokens": 8192
}This is an educational project for MIT 6.104. For course-related contributions:
- Fork the repository
- Create a feature branch
- Make your changes following the concept design methodology
- Add tests for new functionality
- Submit a pull request
- MIT 6.104 course staff for the concept design framework
- Context tool for design-driven development
- Deno team for an excellent runtime
- MongoDB for reliable data persistence
Repository: github.com/bzgrey/TorahCards-backend